summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--vacuum_tubes.lua84
1 files changed, 35 insertions, 49 deletions
diff --git a/vacuum_tubes.lua b/vacuum_tubes.lua
index c1560cb..1e9df6c 100644
--- a/vacuum_tubes.lua
+++ b/vacuum_tubes.lua
@@ -10,23 +10,7 @@ if pipeworks.enable_sand_tube then
pipeworks.register_tube("pipeworks:sand_tube", "Vacuuming Pneumatic Tube Segment", sand_plain_textures, sand_noctr_textures, sand_end_textures,
sand_short_texture, sand_inv_texture,
- {groups = {sand_tube = 1}})
-
- minetest.register_abm({nodenames = {"group:sand_tube"},
- interval = 1,
- chance = 1,
- action = function(pos, node, active_object_count, active_object_count_wider)
- for _, object in ipairs(minetest.get_objects_inside_radius(pos, 2)) do
- if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
- if object:get_luaentity().itemstring ~= "" then
- pipeworks.tube_inject_item(pos, pos, vector.new(0, 0, 0), object:get_luaentity().itemstring)
- end
- object:get_luaentity().itemstring = ""
- object:remove()
- end
- end
- end
- })
+ {groups = {vacuum_tube = 1}})
minetest.register_craft( {
output = "pipeworks:sand_tube_1 2",
@@ -66,7 +50,7 @@ if pipeworks.enable_mese_sand_tube then
pipeworks.register_tube("pipeworks:mese_sand_tube", "Adjustable Vacuuming Pneumatic Tube Segment", mese_sand_plain_textures, mese_sand_noctr_textures,
mese_sand_end_textures, mese_sand_short_texture,mese_sand_inv_texture,
- {groups = {mese_sand_tube = 1},
+ {groups = {vacuum_tube = 1},
on_construct = function(pos)
local meta = minetest.get_meta(pos)
meta:set_int("dist", 0)
@@ -83,36 +67,6 @@ if pipeworks.enable_mese_sand_tube then
end,
})
- local function get_objects_with_square_radius(pos, rad)
- rad = rad + .5;
- local objs = {}
- for _,object in ipairs(minetest.get_objects_inside_radius(pos, math.sqrt(3)*rad)) do
- if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
- local opos = object:getpos()
- if pos.x - rad <= opos.x and opos.x <= pos.x + rad and pos.y - rad <= opos.y and opos.y <= pos.y + rad and pos.z - rad <= opos.z and opos.z <= pos.z + rad then
- objs[#objs + 1] = object
- end
- end
- end
- return objs
- end
-
- minetest.register_abm({nodenames = {"group:mese_sand_tube"},
- interval = 1,
- chance = 1,
- action = function(pos, node, active_object_count, active_object_count_wider)
- for _,object in ipairs(get_objects_with_square_radius(pos, minetest.get_meta(pos):get_int("dist"))) do
- if not object:is_player() and object:get_luaentity() and object:get_luaentity().name == "__builtin:item" then
- if object:get_luaentity().itemstring ~= "" then
- pipeworks.tube_inject_item(pos, pos, vector.new(0, 0, 0), object:get_luaentity().itemstring)
- end
- object:get_luaentity().itemstring = ""
- object:remove()
- end
- end
- end
- })
-
minetest.register_craft( {
output = "pipeworks:mese_sand_tube_1 2",
recipe = {
@@ -135,7 +89,7 @@ if pipeworks.enable_mese_sand_tube then
type = "shapeless",
output = "pipeworks:mese_sand_tube_1",
recipe = {
- "pipeworks:sand_tube_1",
+ "pipeworks:sand_tube_1",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment",
"default:mese_crystal_fragment",
@@ -143,3 +97,35 @@ if pipeworks.enable_mese_sand_tube then
},
})
end
+
+local function vacuum(pos, radius)
+ radius = radius + 0.5
+ for _, object in pairs(minetest.get_objects_inside_radius(pos, math.sqrt(2) * 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()
+ if pos.x - radius <= obj_pos.x and obj_pos.x <= pos.x + radius
+ and pos.y - radius <= obj_pos.y and obj_pos.y <= pos.y + radius
+ and pos.z - radius <= obj_pos.z and obj_pos.z <= pos.z + radius then
+ if lua_entity.itemstring ~= "" then
+ pipeworks.tube_inject_item(pos, pos, vector.new(0, 0, 0), lua_entity.itemstring)
+ lua_entity.itemstring = ""
+ end
+ object:remove()
+ end
+ end
+ end
+end
+
+minetest.register_abm({nodenames = {"group:vacuum_tube"},
+ interval = 1,
+ chance = 1,
+ action = function(pos, node, active_object_count, active_object_count_wider)
+ if node.name == "pipeworks:sand_tube" then
+ vacuum(pos, 2)
+ else
+ local radius = minetest.get_meta(pos):get_int("dist")
+ vacuum(pos, radius)
+ end
+ end
+})