From 828c2008e7d756d4f9e2800e9e20c929652d3d30 Mon Sep 17 00:00:00 2001 From: Vanessa Ezekowitz Date: Fri, 4 Jul 2014 00:49:32 -0400 Subject: [PATCH] import part of the original nature mod from nature_pack blossoms/apple spawning portion only does not include the iron trees or tree-growing code as those are obsolete --- nature_classic/blossom.lua | 67 +++++++++++++++++++++ nature_classic/config.lua | 6 ++ nature_classic/depends.txt | 1 + nature_classic/global_function.lua | 43 +++++++++++++ nature_classic/init.lua | 12 ++++ nature_classic/textures/nature_blossom.png | Bin 0 -> 173 bytes 6 files changed, 129 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 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 0000000000000000000000000000000000000000..a5bb2d3b7cfe2145f98f6e6a85c7118202d1cccc GIT binary patch literal 173 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`jKx9jP7LeL$-D$|(mh=qLo7}w zCoE9^!OwakNoPsMzpsa6&!wfLq^O*1=oZ&ETJiBt`)1D~HJ+Fq1rPtXa*GE%ktnpB z?3<*{d}ihk2JXmnN7y%57AHKO`NH6U=y?}uhwTh5-_?{?CbrD;i|{aPP`k&%aN}O- V%xA5wpMX{}c)I$ztaD0e0sz8ZKM()_ literal 0 HcmV?d00001