From 5703f9037722096f1d9b313af27ba490e3ab7cfe Mon Sep 17 00:00:00 2001 From: Arigatas Date: Fri, 21 Aug 2020 11:29:50 +0200 Subject: [PATCH] solving bug issue #52 --- tubelib_addons3/pushing_chest.lua | 35 ++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/tubelib_addons3/pushing_chest.lua b/tubelib_addons3/pushing_chest.lua index d8ee7fd..1ab6b0a 100644 --- a/tubelib_addons3/pushing_chest.lua +++ b/tubelib_addons3/pushing_chest.lua @@ -143,6 +143,37 @@ local function formspec() "listring[current_player;main]" end +-- necessary function for a quick bugfix, doubles some code from local function "aging" +local function defect(pos, meta) + minetest.get_node_timer(pos):stop() + local node = minetest.get_node(pos) + node.name = "tubelib_addons3:pushing_chest_defect" + minetest.swap_node(pos, node) + return true +end + +-- code duplication of method "NodeStates:on_dig_node" (node_states.lua) +-- (in contrast to (all?) other tubelib nodes that can go defect class "NodeStates" isn't applied here) +function on_dig_node(pos, node, player) + local meta = minetest.get_meta(pos) + local cnt = tonumber(meta:get_string("tubelib_aging")) + if (not cnt or cnt < 1) then + cnt = 1 + end + + local is_defect = (cnt > AGING_LEVEL1) and ( math.random(math.max(1, math.floor(AGING_LEVEL2 / cnt))) == 1 ) + + if is_defect then + defect(pos, meta) -- replace node with defect one + node = minetest.get_node(pos) + end + + + minetest.node_dig(pos, node, player) -- default behaviour (this function is called automatically if on_dig() callback isn't set) + +end + + minetest.register_node("tubelib_addons3:pushing_chest", { description = "HighPerf Pushing Chest", tiles = { @@ -190,8 +221,10 @@ minetest.register_node("tubelib_addons3:pushing_chest", { return inv:is_empty("main") and inv:is_empty("shift") end, + + on_dig = function(pos, node, player) - State:on_dig_node(pos, node, player) + on_dig_node(pos, node, player) tubelib.remove_node(pos) end,