forked from mtcontrib/pipeworks
item_transport.lua: factor out tube overload code into separate function
This commit is contained in:
parent
28a3ba44d1
commit
56362cdd2a
@ -50,6 +50,26 @@ minetest.register_globalstep(function(dtime)
|
|||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
-- tube overload mechanism:
|
||||||
|
-- when the tube's item count (tracked in the above tube_item_count table)
|
||||||
|
-- exceeds the limit configured per tube, replace it with a broken one.
|
||||||
|
local crunch_tube = function(pos, cnode, cmeta)
|
||||||
|
if enable_max_limit then
|
||||||
|
local h = minetest.hash_node_position(pos)
|
||||||
|
local itemcount = tube_item_count[h] or 0
|
||||||
|
if itemcount > max_tube_limit then
|
||||||
|
cmeta:set_string("the_tube_was", minetest.serialize(cnode))
|
||||||
|
print("[Pipeworks] Warning - a tube at "..minetest.pos_to_string(pos).." broke due to too many items ("..itemcount..")")
|
||||||
|
minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
|
||||||
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
local function go_next(pos, velocity, stack, owner)
|
local function go_next(pos, velocity, stack, owner)
|
||||||
local next_positions = {}
|
local next_positions = {}
|
||||||
local max_priority = 0
|
local max_priority = 0
|
||||||
@ -96,16 +116,7 @@ local function go_next(pos, velocity, stack, owner)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if enable_max_limit then
|
crunch_tube(pos, cnode, cmeta)
|
||||||
local h = minetest.hash_node_position(pos)
|
|
||||||
local itemcount = tube_item_count[h] or 0
|
|
||||||
if itemcount > max_tube_limit then
|
|
||||||
cmeta:set_string("the_tube_was", minetest.serialize(cnode))
|
|
||||||
print("[Pipeworks] Warning - a tube at "..minetest.pos_to_string(pos).." broke due to too many items ("..itemcount..")")
|
|
||||||
minetest.swap_node(pos, {name = "pipeworks:broken_tube_1"})
|
|
||||||
pipeworks.scan_for_tube_objects(pos)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if not next_positions[1] then
|
if not next_positions[1] then
|
||||||
return false, nil
|
return false, nil
|
||||||
|
Loading…
Reference in New Issue
Block a user