From 33c4c9d552c7f113a21405456e67c0e4752674a8 Mon Sep 17 00:00:00 2001 From: Novatux Date: Wed, 5 Apr 2017 02:57:22 -0400 Subject: let tubes break if they're "over-pressure" that is, if there are more than X number of items in a tube. Default is 40 in a tube, but breaking is also disabled by default. (original framework by Novatux, with changes by VanessaE) --- item_transport.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'item_transport.lua') diff --git a/item_transport.lua b/item_transport.lua index 12d9e7a..215b65e 100644 --- a/item_transport.lua +++ b/item_transport.lua @@ -1,4 +1,8 @@ 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") @@ -77,6 +81,21 @@ local function go_next(pos, velocity, stack) end end + if enable_max_limit then + local itemcount = #minetest.get_objects_inside_radius(pos, 0.5) + + local h = minetest.hash_node_position(pos) + 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 + if not next_positions[1] then return false, nil end -- cgit v1.2.3