diff --git a/nature_classic/blossom.lua b/nature_classic/blossom.lua new file mode 100644 index 0000000..d492113 --- /dev/null +++ b/nature_classic/blossom.lua @@ -0,0 +1,67 @@ +-- Blossom + +local BLOSSOM_CHANCE = 15 +local APPLE_CHANCE = 10 +local BLOSSOM_DELAY = 3600 + +local BLOSSOM_NODE = "nature:blossom" + +local function spawn_apple_under(pos) + local below = { + x = pos.x, + y = pos.y - 1, + z = pos.z, + } + if minetest.env:get_node(below).name == "air" then + minetest.env:add_node(below, { name = "default:apple" }) + end +end + +minetest.register_node(":"..BLOSSOM_NODE, { + description = "Blossom", + drawtype = "allfaces_optional", + tiles = { "default_leaves.png^nature_blossom.png" }, + paramtype = "light", + groups = { snappy = 3, leafdecay = 3, flammable = 2 }, + sounds = default.node_sound_leaves_defaults(), + drop = BLOSSOM_NODE, +}) + +minetest.register_craft({ + type = "fuel", + recipe = BLOSSOM_NODE, + burntime = 2, +}) + +-- Blossoming +minetest.register_abm({ + nodenames = { "default:leaves" }, + interval = BLOSSOM_DELAY, + chance = BLOSSOM_CHANCE, + + action = function(pos, node, active_object_count, active_object_count_wider) + nature:grow_node(pos, BLOSSOM_NODE) + end +}) + +-- Removing blossom +minetest.register_abm({ + nodenames = { BLOSSOM_NODE }, + interval = BLOSSOM_DELAY, + chance = BLOSSOM_CHANCE, + + action = function(pos, node, active_object_count, active_object_count_wider) + nature:grow_node(pos, "default:leaves") + end +}) + +-- Spawning apples +minetest.register_abm({ + nodenames = { BLOSSOM_NODE }, + interval = BLOSSOM_DELAY, + chance = APPLE_CHANCE, + + action = function(pos, node, active_object_count, active_object_count_wider) + spawn_apple_under(pos) + end +}) diff --git a/nature_classic/config.lua b/nature_classic/config.lua new file mode 100644 index 0000000..49278e0 --- /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. +DISTANCE_FROM_WATER = -1 + +-- Minimum light level needed to grow. Default is 8, which means daylight. +MINIMUM_GROWTH_LIGHT = 8 diff --git a/nature_classic/depends.txt b/nature_classic/depends.txt new file mode 100644 index 0000000..4ad96d5 --- /dev/null +++ b/nature_classic/depends.txt @@ -0,0 +1 @@ +default diff --git a/nature_classic/global_function.lua b/nature_classic/global_function.lua new file mode 100644 index 0000000..e46d1ef --- /dev/null +++ b/nature_classic/global_function.lua @@ -0,0 +1,43 @@ +local NODE_YOUNG = "young" + +nature = {} + +local function set_young_node(pos) + local meta = minetest.env:get_meta(pos) + + meta:set_string(NODE_YOUNG, "true") + minetest.after(5, + function(pos) + local meta = minetest.env:get_meta(pos) + meta:set_string(NODE_YOUNG, "false") + end, + pos) +end + +local function is_not_young(pos) + local meta = minetest.env:get_meta(pos) + + local young = meta:get_string(NODE_YOUNG) + return young ~= "true" +end + +function nature:grow_node(pos, nodename) + if pos ~= nil then + local light_enough = minetest.env:get_node_light(pos, nil) + >= MINIMUM_GROWTH_LIGHT + + if is_not_young(pos) and light_enough then + minetest.env:remove_node(pos) + minetest.env:add_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 minetest.env:find_node_near(pos, DISTANCE_FROM_WATER, + { "default:water_source" }) ~= nil or DISTANCE_FROM_WATER == -1 +end diff --git a/nature_classic/init.lua b/nature_classic/init.lua new file mode 100644 index 0000000..6bb4eb0 --- /dev/null +++ b/nature_classic/init.lua @@ -0,0 +1,12 @@ +-- Nature Classic mod +-- Originally by neko259 + +-- Nature is slowly capturing the world! + +local current_mod_name = minetest.get_current_modname() + +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..a5bb2d3 Binary files /dev/null and b/nature_classic/textures/nature_blossom.png differ