mirror of
https://github.com/minetest-mods/drawers.git
synced 2024-11-22 14:43:45 +01:00
Adjust restore visual lbm, Add new drawers.remove_visuals
This commit is contained in:
parent
a53dac2929
commit
768edb4d09
12
lua/api.lua
12
lua/api.lua
@ -59,20 +59,12 @@ function drawers.drawer_on_construct(pos)
|
|||||||
i = i + 1
|
i = i + 1
|
||||||
end
|
end
|
||||||
|
|
||||||
drawers.spawn_visual(pos)
|
drawers.spawn_visuals(pos)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- destruct drawer
|
-- destruct drawer
|
||||||
function drawers.drawer_on_destruct(pos)
|
function drawers.drawer_on_destruct(pos)
|
||||||
local objs = core.get_objects_inside_radius(pos, 0.537)
|
drawers.remove_visuals(pos)
|
||||||
if not objs then return end
|
|
||||||
|
|
||||||
for _, obj in pairs(objs) do
|
|
||||||
if obj and obj:get_luaentity() and
|
|
||||||
obj:get_luaentity().name == "drawers:visual" then
|
|
||||||
obj:remove()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- drop all items
|
-- drop all items
|
||||||
|
@ -66,7 +66,7 @@ function drawers.get_inv_image(name)
|
|||||||
return texture
|
return texture
|
||||||
end
|
end
|
||||||
|
|
||||||
function drawers.spawn_visual(pos)
|
function drawers.spawn_visuals(pos)
|
||||||
local node = core.get_node(pos)
|
local node = core.get_node(pos)
|
||||||
local ndef = core.registered_nodes[node.name]
|
local ndef = core.registered_nodes[node.name]
|
||||||
local drawerType = ndef.groups.drawer
|
local drawerType = ndef.groups.drawer
|
||||||
@ -150,6 +150,18 @@ function drawers.spawn_visual(pos)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function drawers.remove_visuals(pos)
|
||||||
|
local objs = core.get_objects_inside_radius(pos, 0.537)
|
||||||
|
if not objs then return end
|
||||||
|
|
||||||
|
for _, obj in pairs(objs) do
|
||||||
|
if obj and obj:get_luaentity() and
|
||||||
|
obj:get_luaentity().name == "drawers:visual" then
|
||||||
|
obj:remove()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function drawers.randomize_pos(pos)
|
function drawers.randomize_pos(pos)
|
||||||
local rndpos = table.copy(pos)
|
local rndpos = table.copy(pos)
|
||||||
local x = math.random(-50, 50) * 0.01
|
local x = math.random(-50, 50) * 0.01
|
||||||
|
@ -260,17 +260,24 @@ core.register_lbm({
|
|||||||
nodenames = {"group:drawer"},
|
nodenames = {"group:drawer"},
|
||||||
run_at_every_load = true,
|
run_at_every_load = true,
|
||||||
action = function(pos, node)
|
action = function(pos, node)
|
||||||
|
local drawerType = core.registered_nodes[node.name].groups.drawer
|
||||||
|
local foundVisuals = 0
|
||||||
local objs = core.get_objects_inside_radius(pos, 0.537)
|
local objs = core.get_objects_inside_radius(pos, 0.537)
|
||||||
if objs then
|
if objs then
|
||||||
for _, obj in pairs(objs) do
|
for _, obj in pairs(objs) do
|
||||||
if obj and obj:get_luaentity() and
|
if obj and obj:get_luaentity() and
|
||||||
obj:get_luaentity().name == "drawers:visual" then
|
obj:get_luaentity().name == "drawers:visual" then
|
||||||
return
|
foundVisuals = foundVisuals + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
-- if all drawer visuals were found, return
|
||||||
|
if foundVisuals == drawerType then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
-- no visual found, create a new one
|
-- not enough visuals found, remove existing and create new ones
|
||||||
drawers.spawn_visual(pos)
|
drawers.remove_visuals(pos)
|
||||||
|
drawers.spawn_visuals(pos)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
|
Loading…
Reference in New Issue
Block a user