From 888b0ebfec8c2eff9015163549a7e47443cb8665 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Fri, 1 Apr 2016 21:00:20 -0400 Subject: "explode" all modpacks into their individual components (you can't have a modpack buried inside a modpack) --- nature_classic/blossom.lua | 75 ++++++++++++++++++++++++++ nature_classic/config.lua | 6 +++ nature_classic/depends.txt | 2 + nature_classic/global_function.lua | 82 +++++++++++++++++++++++++++++ nature_classic/init.lua | 41 +++++++++++++++ nature_classic/textures/nature_blossom.png | Bin 0 -> 115 bytes 6 files changed, 206 insertions(+) create mode 100644 nature_classic/blossom.lua create mode 100644 nature_classic/config.lua create mode 100644 nature_classic/depends.txt create mode 100644 nature_classic/global_function.lua create mode 100644 nature_classic/init.lua create mode 100644 nature_classic/textures/nature_blossom.png (limited to 'nature_classic') diff --git a/nature_classic/blossom.lua b/nature_classic/blossom.lua new file mode 100644 index 0000000..62947b5 --- /dev/null +++ b/nature_classic/blossom.lua @@ -0,0 +1,75 @@ +-- Blossoms and such + +local function spawn_apple_under(pos) + local below = { + x = pos.x, + y = pos.y - 1, + z = pos.z, + } + if minetest.get_node(below).name == "air" then + minetest.set_node(below, { name = "default:apple" }) + end +end + +minetest.register_node(":"..nature.blossom_node, { + description = "Apple blossoms", + drawtype = "allfaces_optional", + tiles = nature.blossom_textures, + paramtype = "light", + groups = { snappy = 3, leafdecay = 3, flammable = 2, leafdecay = 3 }, + sounds = default.node_sound_leaves_defaults(), + waving = 1 +}) + +minetest.register_craft({ + type = "fuel", + recipe = nature.blossom_node, + burntime = 2, +}) + +-- these ABMs can get heavy, so just enqueue the nodes + +-- Adding Blossoms +-- Limit mass changes after block has not been loaded for some time: +-- Run ABM with higher frequency, but don't enqueue all blocks +minetest.register_abm({ + nodenames = { nature.blossom_leaves }, + interval = nature.blossom_delay / nature.leaves_blossom_chance, + chance = nature.leaves_blossom_chance, + + action = function(pos, node, active_object_count, active_object_count_wider) + if math.random(nature.leaves_blossom_chance) == 1 then + nature.enqueue_node(pos, node, nature.blossom_node) + end + end +}) + +-- Removing blossoms +-- Limit mass changes after block has not been loaded for some time: +-- Run ABM with higher frequency, but don't enqueue all blocks +minetest.register_abm({ + nodenames = { nature.blossom_node }, + interval = nature.blossom_delay / nature.blossom_leaves_chance, + chance = nature.blossom_leaves_chance, + + action = function(pos, node, active_object_count, active_object_count_wider) + if math.random(nature.blossom_leaves_chance) == 1 then + nature.enqueue_node(pos, node, nature.blossom_leaves) + end + end +}) + +-- Spawning apples +-- Limit mass changes after block has not been loaded for some time: +-- spawn apples with 25% chance, but with 4 times higher frequency +minetest.register_abm({ + nodenames = { nature.blossom_node }, + interval = nature.apple_delay / 4, + chance = nature.apple_chance, + + action = function(pos, node, active_object_count, active_object_count_wider) + if math.random(4) == 1 and nature.dtime < 0.2 and not minetest.find_node_near(pos, nature.apple_spread, { "default:apple" }) then + spawn_apple_under(pos) + end + end +}) diff --git a/nature_classic/config.lua b/nature_classic/config.lua new file mode 100644 index 0000000..8f67b1c --- /dev/null +++ b/nature_classic/config.lua @@ -0,0 +1,6 @@ +-- Set on which distance from water can the tree still grow. +-- Grows anywhere if set to -1. +nature.distance_from_water = 20 + +-- Minimum light level needed to grow. Default is 8, which means daylight. +nature.minimum_growth_light = 8 diff --git a/nature_classic/depends.txt b/nature_classic/depends.txt new file mode 100644 index 0000000..1246684 --- /dev/null +++ b/nature_classic/depends.txt @@ -0,0 +1,2 @@ +default +moretrees? diff --git a/nature_classic/global_function.lua b/nature_classic/global_function.lua new file mode 100644 index 0000000..3a5b9e3 --- /dev/null +++ b/nature_classic/global_function.lua @@ -0,0 +1,82 @@ +-- helper functions + +local function process_blossom_queue_item() + local pos = nature.blossomqueue[1][1] + local node = nature.blossomqueue[1][2] + local replace = nature.blossomqueue[1][3] + if (nature.blossomqueue[1][3] == nature.blossom_node and not nature:is_near_water(pos)) then + table.remove(nature.blossomqueue, 1) -- don't grow if it's not near water, pop from queue. + return + end + nature:grow_node(pos, replace) -- now actually grow it. + table.remove(nature.blossomqueue, 1) +end + +minetest.register_globalstep(function(dtime) + nature.dtime = dtime + if #nature.blossomqueue > 0 and dtime < 0.2 then + local i = 1 + if dtime < 0.1 then + i = i + 4 + end + if dtime < 0.05 then + i = i + 10 + end + while #nature.blossomqueue > 0 and i > 0 do + process_blossom_queue_item() + i = i - 1 + end + end +end) + +function nature.enqueue_node(pos, node, replace) + local idx = #nature.blossomqueue + if idx < nature.blossomqueue_max then + local enqueue_prob = 0 + if idx < nature.blossomqueue_max * 0.8 then + enqueue_prob = 1 + else + -- Reduce queue growth as it gets closer to its max. + enqueue_prob = 1 - (idx - nature.blossomqueue_max * 0.8) / (nature.blossomqueue_max * 0.2) + end + if enqueue_prob == 1 or math.random(100) <= 100 * enqueue_prob then + nature.blossomqueue[idx+1] = {} + nature.blossomqueue[idx+1][1] = pos + nature.blossomqueue[idx+1][2] = node + nature.blossomqueue[idx+1][3] = replace + end + end +end + +local function set_young_node(pos) + local meta = minetest.get_meta(pos) + + meta:set_int(nature.meta_blossom_time, minetest.get_gametime()) +end + +local function is_not_young(pos) + local meta = minetest.get_meta(pos) + + local blossom_time = meta:get_int(nature.meta_blossom_time) + return not (blossom_time and minetest.get_gametime() - blossom_time < nature.blossom_duration) +end + +function nature:grow_node(pos, nodename) + if pos ~= nil then + local light_enough = (minetest.get_node_light(pos, nil) or 0) + >= nature.minimum_growth_light + + if is_not_young(pos) and light_enough then + minetest.set_node(pos, { name = nodename }) + set_young_node(pos) + + minetest.log("info", nodename .. " has grown at " .. pos.x .. "," + .. pos.y .. "," .. pos.z) + end + end +end + +function nature:is_near_water(pos) + return nature.distance_from_water == -1 or minetest.find_node_near(pos, nature.distance_from_water, + { "default:water_source" }) ~= nil +end diff --git a/nature_classic/init.lua b/nature_classic/init.lua new file mode 100644 index 0000000..47fd9bf --- /dev/null +++ b/nature_classic/init.lua @@ -0,0 +1,41 @@ +-- Nature Classic mod +-- Originally by neko259 + +-- Nature is slowly capturing the world! + +local current_mod_name = minetest.get_current_modname() + +nature = {} +nature.blossomqueue = {} +nature.blossomqueue_max = 1000 + +nature.blossom_node = "nature:blossom" +nature.blossom_leaves = "default:leaves" +nature.blossom_textures = { "default_leaves.png^nature_blossom.png" } + +if minetest.get_modpath("moretrees") then + nature.blossom_node = "moretrees:apple_blossoms" + nature.blossom_leaves = "moretrees:apple_tree_leaves" + nature.blossom_textures = { "moretrees_apple_tree_leaves.png^nature_blossom.png" } + minetest.register_alias("nature:blossom", "default:leaves") +end + +nature.leaves_blossom_chance = 15 +nature.blossom_leaves_chance = 5 +nature.blossom_delay = 3600 +nature.apple_delay = 3600 +nature.apple_chance = 10 +nature.apple_spread = 2 + +nature.meta_blossom_time = "blossom_time" +nature.blossom_duration = nature.blossom_delay + +function dumppos(pos) + return "("..pos.x..","..pos.y..","..pos.z..")" +end + +dofile(minetest.get_modpath(current_mod_name) .. "/config.lua") +dofile(minetest.get_modpath(current_mod_name) .. "/global_function.lua") +dofile(minetest.get_modpath(current_mod_name) .. "/blossom.lua") + +minetest.log("info", "[Nature Classic] loaded!") diff --git a/nature_classic/textures/nature_blossom.png b/nature_classic/textures/nature_blossom.png new file mode 100644 index 0000000..9d90336 Binary files /dev/null and b/nature_classic/textures/nature_blossom.png differ -- cgit v1.2.3