mirror of
https://github.com/joe7575/techpack.git
synced 2024-11-22 23:33:44 +01:00
prevent calls to random w/ illegal numbers
This commit is contained in:
parent
6be62b6660
commit
013013149a
@ -305,7 +305,7 @@ function NodeStates:keep_running(pos, meta, val, num_items)
|
|||||||
if self.aging_level1 then
|
if self.aging_level1 then
|
||||||
local cnt = meta:get_int("tubelib_aging") + num_items
|
local cnt = meta:get_int("tubelib_aging") + num_items
|
||||||
meta:set_int("tubelib_aging", cnt)
|
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
|
or cnt >= 999999 then
|
||||||
self:defect(pos, meta)
|
self:defect(pos, meta)
|
||||||
end
|
end
|
||||||
@ -431,7 +431,7 @@ end
|
|||||||
function NodeStates:after_dig_node(pos, oldnode, oldmetadata, digger)
|
function NodeStates:after_dig_node(pos, oldnode, oldmetadata, digger)
|
||||||
local inv = minetest.get_inventory({type="player", name=digger:get_player_name()})
|
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 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
|
if self.node_name_defect and is_defect then
|
||||||
inv:add_item("main", ItemStack(self.node_name_defect))
|
inv:add_item("main", ItemStack(self.node_name_defect))
|
||||||
else
|
else
|
||||||
|
Loading…
Reference in New Issue
Block a user