From 013013149af2f5465db4464ceb3b9025e98222ae Mon Sep 17 00:00:00 2001 From: y Date: Thu, 16 May 2019 23:05:59 +0100 Subject: [PATCH] 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