From 56362cdd2acd8e855ceb79b46ce0b62f205776da Mon Sep 17 00:00:00 2001 From: thetaepsilon-gamedev Date: Mon, 18 Dec 2017 23:07:40 +0000 Subject: item_transport.lua: factor out tube overload code into separate function --- item_transport.lua | 31 +++++++++++++++++++++---------- 1 file 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 -- cgit v1.2.3