prevent fermenter and reformer from disappearing if placed somewhere they don't fit

This commit is contained in:
flux 2019-09-08 01:54:09 +00:00
parent a80bad678b
commit 68e30349ae
2 changed files with 60 additions and 50 deletions

@ -97,7 +97,8 @@ local function place_top(pos, facedir, placer)
return false
end
local node = minetest.get_node(pos)
if node.name ~= "air" then
local def = minetest.registered_nodes[node.name]
if not def or not def.buildable_to then
return false
end
minetest.add_node(pos, {name="tubelib_addons1:fermenter_top", param2=facedir})
@ -186,12 +187,14 @@ minetest.register_node("tubelib_addons1:fermenter", {
after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) == false then
minetest.remove_node(pos)
return
end
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) then
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number)
else
minetest.remove_node(pos)
minetest.chat_send_player(placer:get_player_name(), "Fermenter will not fit there")
return true
end
end,
-- the fermenter needs 'on_dig' to be able to remove the upper node
@ -252,13 +255,15 @@ minetest.register_node("tubelib_addons1:fermenter_defect", {
after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) == false then
minetest.remove_node(pos)
return
end
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) then
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number)
State:defect(pos, M(pos))
else
minetest.remove_node(pos)
minetest.chat_send_player(placer:get_player_name(), "Fermenter will not fit there")
return true
end
end,
-- the fermenter needs 'on_dig' to be able to remove the upper node

@ -91,7 +91,8 @@ local function place_top(pos, facedir, placer)
return false
end
local node = minetest.get_node(pos)
if node.name ~= "air" then
local def = minetest.registered_nodes[node.name]
if not def or not def.buildable_to then
return false
end
minetest.add_node(pos, {name="tubelib_addons1:reformer_top", param2=facedir})
@ -182,12 +183,14 @@ minetest.register_node("tubelib_addons1:reformer", {
after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) == false then
minetest.remove_node(pos)
return
end
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) then
local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number)
else
minetest.remove_node(pos)
minetest.chat_send_player(placer:get_player_name(), "Reformer will not fit there")
return true
end
end,
-- the reformer needs 'on_dig' to be able to remove the upper node
@ -248,13 +251,15 @@ minetest.register_node("tubelib_addons1:reformer_defect", {
after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false)
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) == false then
minetest.remove_node(pos)
return
end
if place_top({x=pos.x, y=pos.y+1, z=pos.z}, facedir, placer) then
local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number)
State:defect(pos, M(pos))
else
minetest.remove_node(pos)
minetest.chat_send_player(placer:get_player_name(), "Reformer will not fit there")
return true
end
end,
-- the reformer needs 'on_dig' to be able to remove the upper node