From 84efae02c40eef01877f9c587ceefee3a90919a9 Mon Sep 17 00:00:00 2001 From: FaceDeer Date: Sat, 1 Feb 2020 17:06:16 -0700 Subject: [PATCH] update spindlestem growth code, remove deprecated functions --- df_farming/plants.lua | 2 +- df_farming/plump_helmet.lua | 2 +- df_mapitems/util.lua | 2 +- df_trees/spindlestem.lua | 44 +++++++++++++++++++++++-------------- df_trees/torchspine.lua | 2 +- subterrane | 2 +- 6 files changed, 33 insertions(+), 21 deletions(-) diff --git a/df_farming/plants.lua b/df_farming/plants.lua index 8c874fa..3e7a4a6 100644 --- a/df_farming/plants.lua +++ b/df_farming/plants.lua @@ -136,7 +136,7 @@ local place_seed = function(itemstack, placer, pointed_thing, plantname) -- add the node and remove 1 item from the itemstack minetest.add_node(pt.above, {name = plantname, param2 = 1}) df_farming.plant_timer(pt.above, plantname) - if not minetest.setting_getbool("creative_mode") then + if not minetest.settings:get_bool("creative_mode", false) then itemstack:take_item() end return itemstack diff --git a/df_farming/plump_helmet.lua b/df_farming/plump_helmet.lua index 9ff15ae..6967572 100644 --- a/df_farming/plump_helmet.lua +++ b/df_farming/plump_helmet.lua @@ -50,7 +50,7 @@ local plump_helmet_on_place = function(itemstack, placer, pointed_thing, plantn -- add the node and remove 1 item from the itemstack minetest.add_node(pt.above, {name = plantname, param2 = math.random(0,3)}) df_farming.plant_timer(pt.above, plantname) - if not minetest.setting_getbool("creative_mode") then + if not minetest.settings:get_bool("creative_mode", false) then itemstack:take_item() end return itemstack diff --git a/df_mapitems/util.lua b/df_mapitems/util.lua index ea876c3..3867e01 100644 --- a/df_mapitems/util.lua +++ b/df_mapitems/util.lua @@ -59,7 +59,7 @@ df_mapitems.place_against_surface = function(itemstack, placer, pointed_thing) end -- add the node and remove 1 item from the itemstack minetest.add_node(above_pos, {name = itemstack:get_name(), param2 = param2}) - if not minetest.setting_getbool("creative_mode") and not minetest.check_player_privs(placer, "creative") then + if not minetest.settings:get_bool("creative_mode", false) and not minetest.check_player_privs(placer, "creative") then itemstack:take_item() end return itemstack diff --git a/df_trees/spindlestem.lua b/df_trees/spindlestem.lua index a10e306..2e893ed 100644 --- a/df_trees/spindlestem.lua +++ b/df_trees/spindlestem.lua @@ -46,7 +46,7 @@ local stem_on_place = function(itemstack, placer, pointed_thing) -- add the node and remove 1 item from the itemstack minetest.add_node(pt.above, {name = itemstack:get_name(), param2 = new_param2}) - if not minetest.setting_getbool("creative_mode") then + if not minetest.settings:get_bool("creative_mode", false) then itemstack:take_item() end return itemstack @@ -149,23 +149,34 @@ local register_spindlestem_type = function(item_suffix, colour_name, colour_code on_place = stem_on_place, on_timer = function(pos, elapsed) - local above = vector.add(pos, {x=0,y=1,z=0}) - local node_above = minetest.get_node(above) - local above_def = minetest.registered_nodes[node_above.name] - if not above_def or not above_def.buildable_to then - -- can't grow any more, exit - return - end local meta = minetest.get_meta(pos) local height = meta:get_int("spindlestem_to_grow") + local delay = meta:get_int("spindlestem_delay") + if delay == 0 then + delay = growth_delay() -- compatibility code to ensure no crash for previous version + end local node = minetest.get_node(pos) - minetest.set_node(pos, {name="df_trees:spindlestem_stem", param2 = node.param2}) - minetest.set_node(above, {name=cap_item, param2 = node.param2}) - height = height - 1 + + while height > 0 and elapsed >= delay do + elapsed = elapsed - delay + local this_pos = pos + pos = vector.add(this_pos, {x=0,y=1,z=0}) + local node_above = minetest.get_node(pos) + local above_def = minetest.registered_nodes[node_above.name] + if not above_def or not above_def.buildable_to then + -- can't grow any more, exit + return + end + minetest.set_node(this_pos, {name="df_trees:spindlestem_stem", param2 = node.param2}) + minetest.set_node(pos, {name=cap_item, param2 = node.param2}) + height = height - 1 + end + if height > 0 then meta = minetest.get_meta(above) meta:set_int("spindlestem_to_grow", height) - minetest.get_node_timer(above):start(growth_delay()) + meta:set_int("spindlestem_delay", delay) + minetest.get_node_timer(above):start(delay-elapsed) end end, }) @@ -255,7 +266,7 @@ minetest.register_node("df_trees:spindlestem_seedling", { minetest.get_node_timer(pos):stop() end, - on_timer = function(pos) + on_timer = function(pos, elapsed) if df_farming and df_farming.kill_if_sunlit(pos) then return end @@ -270,8 +281,10 @@ minetest.register_node("df_trees:spindlestem_seedling", { local height = math.random(1,3) if count > 10 then height = height + 2 end -- if there are a lot of nearby spindlestems, grow taller if height > 0 then + local delay = growth_delay() meta:set_int("spindlestem_to_grow", height) - minetest.get_node_timer(pos):start(growth_delay()) + meta:set_int("spindlestem_delay", delay) + minetest.get_node_timer(pos):start(delay) end end, }) @@ -320,7 +333,7 @@ local c_cyan = minetest.get_content_id("df_trees:spindlestem_cap_cyan") local c_golden = minetest.get_content_id("df_trees:spindlestem_cap_golden") get_spindlestem_cap_type = function(pos) - if pos.y > -100 or minetest.find_node_near(pos, 15, "group:tower_cap") then + if minetest.find_node_near(pos, 15, "group:tower_cap") then return c_white end if minetest.find_node_near(pos, 15, "group:goblin_cap") then @@ -336,7 +349,6 @@ get_spindlestem_cap_type = function(pos) if copper then table.insert(possibilities, c_green) end if iron then table.insert(possibilities, c_red) end if iron and copper then table.insert(possibilities, c_cyan) end - if #possibilities == 0 then return c_white else diff --git a/df_trees/torchspine.lua b/df_trees/torchspine.lua index b84f1d0..bad9227 100644 --- a/df_trees/torchspine.lua +++ b/df_trees/torchspine.lua @@ -43,7 +43,7 @@ local stal_on_place = function(itemstack, placer, pointed_thing) -- add the node and remove 1 item from the itemstack minetest.add_node(pt.above, {name = itemstack:get_name(), param2 = new_param2}) - if not minetest.setting_getbool("creative_mode") then + if not minetest.settings:get_bool("creative_mode", false) then itemstack:take_item() end return itemstack diff --git a/subterrane b/subterrane index 6940ae1..1abfc23 160000 --- a/subterrane +++ b/subterrane @@ -1 +1 @@ -Subproject commit 6940ae15859f671afbeb2231f90ce58914bb774f +Subproject commit 1abfc23dd369899c1b6c4888799bcdc4525558a4