API for getting objects inside one node.
This commit is contained in:
parent
db5ff04b1c
commit
266de04987
@ -403,3 +403,14 @@ end
|
||||
function nodecore.near_unloaded(pos, radius)
|
||||
return minetest.find_node_near(pos, radius or 1, {"ignore"}, true)
|
||||
end
|
||||
|
||||
function nodecore.get_objects_at_pos(pos)
|
||||
pos = vector.round(pos)
|
||||
local t = {}
|
||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 0.866025403784)) do
|
||||
if vector.equals(vector.round(obj:get_pos()), pos) then
|
||||
t[#t + 1] = obj
|
||||
end
|
||||
end
|
||||
return t
|
||||
end
|
||||
|
@ -104,12 +104,10 @@ function nodecore.entity_settle_check(on_settle, isnode)
|
||||
if not on_settle(self, pos, collides) then return end
|
||||
|
||||
pos.y = pos.y + 1
|
||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 2)) do
|
||||
if vector.equals(vector.round(obj:get_pos()), pos) then
|
||||
obj = obj.get_luaentity and obj:get_luaentity()
|
||||
if obj and obj.settle_check then
|
||||
obj:settle_check()
|
||||
end
|
||||
for _, obj in pairs(nodecore.get_objects_at_pos(pos)) do
|
||||
obj = obj.get_luaentity and obj:get_luaentity()
|
||||
if obj and obj.settle_check then
|
||||
obj:settle_check()
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -16,26 +16,24 @@ function nodecore.item_ent_merge(pos)
|
||||
cache[hash] = (t or nodecore.gametime) + 0.75 + 0.5 * math_random()
|
||||
|
||||
local db = {}
|
||||
for _, obj in pairs(minetest.get_objects_inside_radius(pos, 1)) do
|
||||
if vector.equals(vector.round(obj:get_pos()), pos) then
|
||||
local lua = obj.get_luaentity and obj:get_luaentity()
|
||||
if lua and lua.name == "__builtin:item" then
|
||||
local stack = ItemStack(lua.itemstring or "")
|
||||
if not stack:is_empty() then
|
||||
local qty = stack:get_count()
|
||||
stack:set_count(1)
|
||||
local key = stack:to_string()
|
||||
local entry = db[key]
|
||||
if entry then
|
||||
entry.qty = entry.qty + qty
|
||||
entry.objs[#entry.objs + 1] = {obj = obj, lua = lua}
|
||||
else
|
||||
db[key] = {
|
||||
stack = stack,
|
||||
qty = qty,
|
||||
objs = {{obj = obj, lua = lua}}
|
||||
}
|
||||
end
|
||||
for _, obj in pairs(nodecore.get_objects_at_pos(pos, 1)) do
|
||||
local lua = obj.get_luaentity and obj:get_luaentity()
|
||||
if lua and lua.name == "__builtin:item" then
|
||||
local stack = ItemStack(lua.itemstring or "")
|
||||
if not stack:is_empty() then
|
||||
local qty = stack:get_count()
|
||||
stack:set_count(1)
|
||||
local key = stack:to_string()
|
||||
local entry = db[key]
|
||||
if entry then
|
||||
entry.qty = entry.qty + qty
|
||||
entry.objs[#entry.objs + 1] = {obj = obj, lua = lua}
|
||||
else
|
||||
db[key] = {
|
||||
stack = stack,
|
||||
qty = qty,
|
||||
objs = {{obj = obj, lua = lua}}
|
||||
}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -51,7 +51,7 @@ function nodecore.visinv_update_ents(pos, node)
|
||||
local max = def.groups and def.groups.visinv and 1 or 0
|
||||
|
||||
local found = {}
|
||||
for _, v in pairs(minetest.get_objects_inside_radius(pos, 0.5)) do
|
||||
for _, v in pairs(nodecore.get_objects_at_pos(pos)) do
|
||||
if v and v.get_luaentity and v:get_luaentity()
|
||||
and v:get_luaentity().is_stack then
|
||||
found[#found + 1] = v
|
||||
|
Loading…
x
Reference in New Issue
Block a user