summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-12-18 23:07:40 +0000
committerthetaepsilon-gamedev <thetaepsilon-gamedev@noreply.users.github.com>2017-12-18 23:07:40 +0000
commit56362cdd2acd8e855ceb79b46ce0b62f205776da (patch)
tree8027c3e8993285c40a9bbba550c622a645c50dc1
parent28a3ba44d165cce068491b90233a58f3cea4d1c2 (diff)
downloadpipeworks-56362cdd2acd8e855ceb79b46ce0b62f205776da.tar
pipeworks-56362cdd2acd8e855ceb79b46ce0b62f205776da.tar.gz
pipeworks-56362cdd2acd8e855ceb79b46ce0b62f205776da.tar.bz2
pipeworks-56362cdd2acd8e855ceb79b46ce0b62f205776da.tar.xz
pipeworks-56362cdd2acd8e855ceb79b46ce0b62f205776da.zip
item_transport.lua: factor out tube overload code into separate function
-rw-r--r--item_transport.lua31
1 files changed, 21 insertions, 10 deletions
diff --git a/item_transport.lua b/item_transport.lua
index 64e4624..cf9e5c4 100644
--- a/item_transport.lua
+++ b/item_transport.lua
@@ -50,6 +50,26 @@ minetest.register_globalstep(function(dtime)
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 next_positions = {}
local max_priority = 0
@@ -96,16 +116,7 @@ local function go_next(pos, velocity, stack, owner)
end
end
- 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
+ crunch_tube(pos, cnode, cmeta)
if not next_positions[1] then
return false, nil