Fixed some bugs in castle grilles mod
parent
6d3491d8ae
commit
2ae23d6e55
|
@ -16,43 +16,48 @@ minetest.register_node("castle_grille:grille", {
|
||||||
paramtype = "light",
|
paramtype = "light",
|
||||||
tile_images = {"grille_gril.png"},
|
tile_images = {"grille_gril.png"},
|
||||||
is_ground_content = true,
|
is_ground_content = true,
|
||||||
material = minetest.digprop_constanttime(90),
|
material = minetest.digprop_constanttime(10),
|
||||||
drop = "",
|
drop = "",
|
||||||
})
|
})
|
||||||
|
|
||||||
local function add_down(node,pos)
|
local function add_down(pos)
|
||||||
for i = 1, GRILLE_HEIGHT do
|
for i = 1, GRILLE_HEIGHT do
|
||||||
local current_pos = {x = pos.x, y = pos.y - i, z = pos.z}
|
local current_pos = {x = pos.x, y = pos.y - i, z = pos.z}
|
||||||
local current_node = minetest.env:get_node(current_pos)
|
local current_node = minetest.env:get_node(current_pos)
|
||||||
if current_node.name == "air" then
|
if current_node.name == "air" then
|
||||||
table.insert(grilles_to_add,{pos = current_pos, time = i})
|
grilles_to_add[current_pos] = i
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function remove_up(node,pos)
|
local function remove_up(pos, height, reversed)
|
||||||
for i = 1, GRILLE_HEIGHT do
|
if height > GRILLE_HEIGHT then
|
||||||
local current_pos = {x = pos.x, y = pos.y - i, z = pos.z}
|
return height
|
||||||
local current_node = minetest.env:get_node(current_pos)
|
end
|
||||||
if current_node.name == "castle_grille:grille" then
|
local current_node = minetest.env:get_node(pos)
|
||||||
table.insert(grilles_to_remove,{pos = current_pos, time = GRILLE_HEIGHT - i + 1})
|
if current_node.name ~= "castle_grille:grille" then
|
||||||
else
|
return height
|
||||||
return
|
end
|
||||||
end
|
local max_h = remove_up({x = pos.x, y = pos.y - 1, z = pos.z}, height + 1)
|
||||||
end
|
if reversed == true then
|
||||||
|
grilles_to_remove[pos] = height + 1
|
||||||
|
else
|
||||||
|
grilles_to_remove[pos] = max_h - height
|
||||||
|
end
|
||||||
|
return max_h
|
||||||
end
|
end
|
||||||
|
|
||||||
mesecon:register_on_signal_on(function (pos, node)
|
mesecon:register_on_signal_on(function (pos, node)
|
||||||
if node.name == "castle_grille:mechanism" then
|
if node.name == "castle_grille:mechanism" then
|
||||||
add_down(node,pos)
|
add_down(pos)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
mesecon:register_on_signal_off(function (pos,node)
|
mesecon:register_on_signal_off(function (pos,node)
|
||||||
if node.name == "castle_grille:mechanism" then
|
if node.name == "castle_grille:mechanism" then
|
||||||
remove_up(node,pos)
|
remove_up({x = pos.x, y = pos.y - 1, z = pos.z}, 0)
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
@ -61,28 +66,31 @@ minetest.register_globalstep(function(dtime)
|
||||||
delta = delta + dtime
|
delta = delta + dtime
|
||||||
while delta >= 3 do
|
while delta >= 3 do
|
||||||
delta = delta - 3
|
delta = delta - 3
|
||||||
for num, grille in ipairs(grilles_to_remove) do
|
for pos, time in pairs(grilles_to_remove) do
|
||||||
if grille.time == 1 then
|
if time == 1 and minetest.env:get_node(pos).name == "castle_grille:grille" then
|
||||||
minetest.env:remove_node(grille.pos)
|
minetest.env:remove_node(pos)
|
||||||
grille.time = nil
|
grilles_to_remove[pos] = nil
|
||||||
grille.pos = nil
|
else
|
||||||
elseif grille.time then
|
grilles_to_remove[pos] = time - 1
|
||||||
grille.time = grille.time - 1
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for num, grille in ipairs(grilles_to_add) do
|
for pos, time in pairs(grilles_to_add) do
|
||||||
if grille.time == 1 then
|
if time == 1 and minetest.env:get_node(pos).name == "air" then
|
||||||
minetest.env:remove_node(grille.pos)
|
minetest.env:add_node(pos, {name = "castle_grille:grille"})
|
||||||
minetest.env:add_node(grille.pos, {name = "castle_grille:grille"})
|
grilles_to_add[pos] = nil
|
||||||
grille.time = nil
|
else
|
||||||
grille.pos = nil
|
grilles_to_add[pos] = time - 1
|
||||||
elseif grille.time then
|
end
|
||||||
grille.time = grille.time - 1
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
minetest.register_on_dignode(function(pos, oldnode)
|
||||||
|
if oldnode.name == "castle_grille:grille" or oldnode.name == "castle_grille:mechanism" then
|
||||||
|
remove_up({x = pos.x, y = pos.y - 1, z = pos.z}, 0, true)
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
|
||||||
minetest.register_craft({
|
minetest.register_craft({
|
||||||
output = 'castle_grille:mechanism',
|
output = 'castle_grille:mechanism',
|
||||||
recipe = {
|
recipe = {
|
||||||
|
|
Loading…
Reference in New Issue