From 6be62b6660ff306706125b035ec0bc81b872f7c6 Mon Sep 17 00:00:00 2001 From: y Date: Thu, 16 May 2019 23:03:36 +0100 Subject: [PATCH 1/2] set correct defaults if quarry depth and startlevel are not set --- tubelib_addons1/quarry.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/tubelib_addons1/quarry.lua b/tubelib_addons1/quarry.lua index 6bfbaa5..cd5a3dc 100644 --- a/tubelib_addons1/quarry.lua +++ b/tubelib_addons1/quarry.lua @@ -36,8 +36,10 @@ local Level2Idx = {[2]=1, [1]=2, [0]=3, [-1]=4, [-2]=5, [-3]=6, [-5]=7, [-10]=8, [-15]=9, [-20]=10} local function formspec(self, pos, meta) - local depth = meta:get_int("max_levels") or 1 - local start_level = meta:get_int("start_level") or 1 + local depth = meta:get_int("max_levels") + if not Depth2Idx[depth] then depth = 1 end + local start_level = meta:get_int("start_level") + if not Level2Idx[start_level] then start_level = 0 end local endless = meta:get_int("endless") or 0 local fuel = meta:get_int("fuel") or 0 -- some recalculations From 013013149af2f5465db4464ceb3b9025e98222ae Mon Sep 17 00:00:00 2001 From: y Date: Thu, 16 May 2019 23:05:59 +0100 Subject: [PATCH 2/2] prevent calls to random w/ illegal numbers --- tubelib/node_states.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tubelib/node_states.lua b/tubelib/node_states.lua index bd8f7b6..f261152 100644 --- a/tubelib/node_states.lua +++ b/tubelib/node_states.lua @@ -305,7 +305,7 @@ function NodeStates:keep_running(pos, meta, val, num_items) if self.aging_level1 then local cnt = meta:get_int("tubelib_aging") + num_items meta:set_int("tubelib_aging", cnt) - if (cnt > (self.aging_level1) and math.random(self.aging_level2/num_items) == 1) + if (cnt > (self.aging_level1) and math.random(math.max(1, math.floor(self.aging_level2/num_items))) == 1) or cnt >= 999999 then self:defect(pos, meta) end @@ -431,7 +431,7 @@ end function NodeStates:after_dig_node(pos, oldnode, oldmetadata, digger) local inv = minetest.get_inventory({type="player", name=digger:get_player_name()}) local cnt = oldmetadata.fields.tubelib_aging and tonumber(oldmetadata.fields.tubelib_aging) or 0 - local is_defect = cnt > self.aging_level1 and math.random(self.aging_level2 / cnt) == 1 + local is_defect = cnt > self.aging_level1 and math.random(math.max(1, math.floor(self.aging_level2 / cnt))) == 1 if self.node_name_defect and is_defect then inv:add_item("main", ItemStack(self.node_name_defect)) else