From 9775af22f3d2b4b0944b6ecd11bb3a014cb1fc73 Mon Sep 17 00:00:00 2001 From: crabman77 Date: Wed, 16 Mar 2016 12:17:01 +0100 Subject: [PATCH] avoid lag if full chest, limit items to 50, remove others --- mods/pipeworks/vacuum_tubes.lua | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/mods/pipeworks/vacuum_tubes.lua b/mods/pipeworks/vacuum_tubes.lua index 51f6f810..1f453c5d 100755 --- a/mods/pipeworks/vacuum_tubes.lua +++ b/mods/pipeworks/vacuum_tubes.lua @@ -87,21 +87,27 @@ local tube_inject_item = pipeworks.tube_inject_item local get_objects_inside_radius = minetest.get_objects_inside_radius local function vacuum(pos, radius) radius = radius + 0.5 + local max_items = 0 for _, object in pairs(get_objects_inside_radius(pos, sqrt_3 * radius)) do local lua_entity = object:get_luaentity() if not object:is_player() and lua_entity and lua_entity.name == "__builtin:item" then - local obj_pos = object:getpos() - local x1, y1, z1 = pos.x, pos.y, pos.z - local x2, y2, z2 = obj_pos.x, obj_pos.y, obj_pos.z - - if x1 - radius <= x2 and x2 <= x1 + radius - and y1 - radius <= y2 and y2 <= y1 + radius - and z1 - radius <= z2 and z2 <= z1 + radius then - if lua_entity.itemstring ~= "" then - tube_inject_item(pos, pos, vector.new(0, 0, 0), lua_entity.itemstring) - lua_entity.itemstring = "" - end + max_items = max_items + 1 + if max_items > 50 then object:remove() + else + local obj_pos = object:getpos() + local x1, y1, z1 = pos.x, pos.y, pos.z + local x2, y2, z2 = obj_pos.x, obj_pos.y, obj_pos.z + + if x1 - radius <= x2 and x2 <= x1 + radius + and y1 - radius <= y2 and y2 <= y1 + radius + and z1 - radius <= z2 and z2 <= z1 + radius then + if lua_entity.itemstring ~= "" then + tube_inject_item(pos, pos, vector.new(0, 0, 0), lua_entity.itemstring) + lua_entity.itemstring = "" + end + object:remove() + end end end end