mirror of
https://github.com/HybridDog/connected_chests.git
synced 2024-11-17 11:20:17 +01:00
use abms to disallow half chests
This commit is contained in:
parent
c07226694d
commit
afc271823c
@ -1,3 +1,2 @@
|
||||
TODO:
|
||||
— maybe use [combine for front and lock
|
||||
— use abms to ensure that noone made an half chest eg with a piston
|
||||
|
32
init.lua
32
init.lua
@ -65,6 +65,11 @@ local param_tab = {
|
||||
["0 1"] = 1,
|
||||
}
|
||||
|
||||
local param_tab2 = {}
|
||||
for n,i in pairs(param_tab) do
|
||||
param_tab2[i] = n
|
||||
end
|
||||
|
||||
local pars = {[0]=2, 3, 0, 1}
|
||||
|
||||
local function connect_chests(pu, pa, old_param2, name)
|
||||
@ -226,4 +231,31 @@ minetest.register_node("connected_chests:chest_locked_right", {
|
||||
end,
|
||||
})
|
||||
|
||||
for _,i in pairs({"chest", "chest_locked"}) do
|
||||
minetest.register_abm ({
|
||||
nodenames = {"connected_chests:"..i.."_right"},
|
||||
interval = 3,
|
||||
chance = 1,
|
||||
action = function (pos, node)
|
||||
local x, z = unpack(string.split(param_tab2[node.param2], " "))
|
||||
if minetest.get_node({x=pos.x+x, y=pos.y, z=pos.z+z}).name ~= "connected_chests:"..i.."_left" then
|
||||
minetest.remove_node(pos)
|
||||
end
|
||||
end,
|
||||
})
|
||||
minetest.register_abm ({
|
||||
nodenames = {"connected_chests:"..i.."_left"},
|
||||
interval = 3,
|
||||
chance = 1,
|
||||
action = function (pos, node)
|
||||
local par = node.param2
|
||||
local x, z = unpack(string.split(param_tab2[par], " "))
|
||||
pos = {x=pos.x-x, y=pos.y, z=pos.z-z}
|
||||
if minetest.get_node(pos).name == "air" then
|
||||
minetest.set_node(pos, {name="connected_chests:"..i.."_right", param2=par})
|
||||
end
|
||||
end,
|
||||
})
|
||||
end
|
||||
|
||||
print(string.format("[connected_chest] loaded after ca. %.2fs", os.clock() - load_time_start))
|
||||
|
Loading…
Reference in New Issue
Block a user