summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEkdohibs <nathanael.courant@laposte.net>2017-04-05 03:31:57 +0200
committerEkdohibs <nathanael.courant@laposte.net>2017-04-06 03:46:23 +0200
commit7680820d3e85ac06976b26e86211866cdf90a99d (patch)
treed6e58088df4d0088e29def2409cadddaac2cbe44
parent33c4c9d552c7f113a21405456e67c0e4752674a8 (diff)
downloadpipeworks-7680820d3e85ac06976b26e86211866cdf90a99d.tar
pipeworks-7680820d3e85ac06976b26e86211866cdf90a99d.tar.gz
pipeworks-7680820d3e85ac06976b26e86211866cdf90a99d.tar.bz2
pipeworks-7680820d3e85ac06976b26e86211866cdf90a99d.tar.xz
pipeworks-7680820d3e85ac06976b26e86211866cdf90a99d.zip
Make item counting more reliable and more efficient.
-rw-r--r--item_transport.lua23
1 files changed, 16 insertions, 7 deletions
diff --git a/item_transport.lua b/item_transport.lua
index 215b65e..40e0d2d 100644
--- a/item_transport.lua
+++ b/item_transport.lua
@@ -2,8 +2,6 @@ local luaentity = pipeworks.luaentity
local enable_max_limit = minetest.setting_get("pipeworks_enable_items_per_tube_limit")
local max_tube_limit = minetest.setting_get("pipeworks_max_items_per_tube") or 40
-pipeworks.tube_item_count = {}
-
function pipeworks.tube_item(pos, item)
error("obsolete pipeworks.tube_item() called; change caller to use pipeworks.tube_inject_item() instead")
end
@@ -35,6 +33,21 @@ function pipeworks.notvel(tbl, vel)
return tbl2
end
+local tube_item_count = {}
+
+minetest.register_globalstep(function(dtime)
+ if not luaentity.entities then
+ return
+ end
+ tube_item_count = {}
+ for id, entity in pairs(luaentity.entities) do
+ if entity.name == "pipeworks:tubed_item" then
+ local h = minetest.hash_node_position(vector.round(entity._pos))
+ tube_item_count[h] = (tube_item_count[h] or 0) + 1
+ end
+ end
+end)
+
local function go_next(pos, velocity, stack)
local next_positions = {}
local max_priority = 0
@@ -82,17 +95,13 @@ local function go_next(pos, velocity, stack)
end
if enable_max_limit then
- local itemcount = #minetest.get_objects_inside_radius(pos, 0.5)
-
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)
- pipeworks.tube_item_count[h] = 0
- else
- pipeworks.tube_item_count[h] = itemcount
end
end