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

@ -7,9 +7,9 @@
LGPLv2.1+ LGPLv2.1+
See LICENSE.txt for more information See LICENSE.txt for more information
fermenter.lua fermenter.lua
The Fermenter converts 3 leave items of any kind into one Bio Gas item, The Fermenter converts 3 leave items of any kind into one Bio Gas item,
needed by the Reformer to produce Bio Fuel. needed by the Reformer to produce Bio Fuel.
@ -97,7 +97,8 @@ local function place_top(pos, facedir, placer)
return false return false
end end
local node = minetest.get_node(pos) 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 return false
end end
minetest.add_node(pos, {name="tubelib_addons1:fermenter_top", param2=facedir}) minetest.add_node(pos, {name="tubelib_addons1:fermenter_top", param2=facedir})
@ -107,13 +108,13 @@ end
local function convert_leaves_to_biogas(pos, meta) local function convert_leaves_to_biogas(pos, meta)
local inv = meta:get_inventory() local inv = meta:get_inventory()
local biogas = ItemStack("tubelib_addons1:biogas") local biogas = ItemStack("tubelib_addons1:biogas")
-- Not enough output space? -- Not enough output space?
if not inv:room_for_item("dst", biogas) then if not inv:room_for_item("dst", biogas) then
State:blocked(pos, meta) State:blocked(pos, meta)
return return
end end
-- take NUM_LEAVES items -- take NUM_LEAVES items
local items = {} local items = {}
for i = 1, NUM_LEAVES do for i = 1, NUM_LEAVES do
@ -128,14 +129,14 @@ local function convert_leaves_to_biogas(pos, meta)
end end
end end
end end
-- put result into dst inventory -- put result into dst inventory
if #items == NUM_LEAVES then if #items == NUM_LEAVES then
inv:add_item("dst", biogas) inv:add_item("dst", biogas)
State:keep_running(pos, meta, COUNTDOWN_TICKS) State:keep_running(pos, meta, COUNTDOWN_TICKS)
return return
end end
-- put leaves back to src inventory -- put leaves back to src inventory
for i = 1, #items do for i = 1, #items do
inv:add_item("src", items[i]) inv:add_item("src", items[i])
@ -176,22 +177,24 @@ minetest.register_node("tubelib_addons1:fermenter", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 }, fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 },
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = M(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 9) inv:set_size('src', 9)
inv:set_size('dst', 9) inv:set_size('dst', 9)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false) 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 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.remove_node(pos)
return minetest.chat_send_player(placer:get_player_name(), "Fermenter will not fit there")
return true
end end
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number)
end, end,
-- the fermenter needs 'on_dig' to be able to remove the upper node -- the fermenter needs 'on_dig' to be able to remove the upper node
@ -208,7 +211,7 @@ minetest.register_node("tubelib_addons1:fermenter", {
tubelib.remove_node(pos) tubelib.remove_node(pos)
State:after_dig_node(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
on_timer = keep_running, on_timer = keep_running,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
@ -242,23 +245,25 @@ minetest.register_node("tubelib_addons1:fermenter_defect", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 }, fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 },
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = M(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 9) inv:set_size('src', 9)
inv:set_size('dst', 9) inv:set_size('dst', 9)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false) 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 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.remove_node(pos)
return minetest.chat_send_player(placer:get_player_name(), "Fermenter will not fit there")
return true
end end
local number = tubelib.add_node(pos, "tubelib_addons1:fermenter")
State:node_init(pos, number)
State:defect(pos, M(pos))
end, end,
-- the fermenter needs 'on_dig' to be able to remove the upper node -- the fermenter needs 'on_dig' to be able to remove the upper node
@ -274,7 +279,7 @@ minetest.register_node("tubelib_addons1:fermenter_defect", {
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos) tubelib.remove_node(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
@ -327,14 +332,14 @@ if minetest.global_exists("unified_inventory") then
height = 2, height = 2,
}) })
unified_inventory.register_craft({ unified_inventory.register_craft({
items = {"group:leaves", "group:leaves"}, items = {"group:leaves", "group:leaves"},
output = "tubelib_addons1:biogas", output = "tubelib_addons1:biogas",
type = "fermenting" type = "fermenting"
}) })
unified_inventory.register_craft({ unified_inventory.register_craft({
items = {"tubelib_addons1:biogas", "tubelib_addons1:biogas", items = {"tubelib_addons1:biogas", "tubelib_addons1:biogas",
"tubelib_addons1:biogas", "tubelib_addons1:biogas"}, "tubelib_addons1:biogas", "tubelib_addons1:biogas"},
output = "tubelib_addons1:biofuel", output = "tubelib_addons1:biofuel",
type = "reforming" type = "reforming"
}) })
end end
@ -373,4 +378,4 @@ tubelib.register_node("tubelib_addons1:fermenter", {"tubelib_addons1:fermenter_d
on_node_repair = function(pos) on_node_repair = function(pos)
return State:on_node_repair(pos) return State:on_node_repair(pos)
end, end,
}) })

@ -9,10 +9,10 @@
See LICENSE.txt for more information See LICENSE.txt for more information
reformer.lua reformer.lua
The Reformer converts 4 Bio Gas items into one Bio Fuel item, The Reformer converts 4 Bio Gas items into one Bio Fuel item,
needed by Harvester and Quarry. needed by Harvester and Quarry.
]]-- ]]--
-- for lazy programmers -- for lazy programmers
@ -91,7 +91,8 @@ local function place_top(pos, facedir, placer)
return false return false
end end
local node = minetest.get_node(pos) 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 return false
end end
minetest.add_node(pos, {name="tubelib_addons1:reformer_top", param2=facedir}) minetest.add_node(pos, {name="tubelib_addons1:reformer_top", param2=facedir})
@ -172,24 +173,26 @@ minetest.register_node("tubelib_addons1:reformer", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 }, fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 },
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = M(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 9) inv:set_size('src', 9)
inv:set_size('dst', 9) inv:set_size('dst', 9)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false) 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 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.remove_node(pos)
return minetest.chat_send_player(placer:get_player_name(), "Reformer will not fit there")
return true
end end
local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number)
end, end,
-- the reformer needs 'on_dig' to be able to remove the upper node -- the reformer needs 'on_dig' to be able to remove the upper node
on_dig = function(pos, node, puncher, pointed_thing) on_dig = function(pos, node, puncher, pointed_thing)
local meta = M(pos) local meta = M(pos)
@ -199,12 +202,12 @@ minetest.register_node("tubelib_addons1:reformer", {
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z}) minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos) tubelib.remove_node(pos)
State:after_dig_node(pos, oldnode, oldmetadata, digger) State:after_dig_node(pos, oldnode, oldmetadata, digger)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
on_timer = keep_running, on_timer = keep_running,
on_receive_fields = on_receive_fields, on_receive_fields = on_receive_fields,
@ -238,23 +241,25 @@ minetest.register_node("tubelib_addons1:reformer_defect", {
type = "fixed", type = "fixed",
fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 }, fixed = { -8/16, -8/16, -8/16, 8/16, 24/16, 8/16 },
}, },
on_construct = function(pos) on_construct = function(pos)
local meta = M(pos) local meta = M(pos)
local inv = meta:get_inventory() local inv = meta:get_inventory()
inv:set_size('src', 9) inv:set_size('src', 9)
inv:set_size('dst', 9) inv:set_size('dst', 9)
end, end,
after_place_node = function(pos, placer) after_place_node = function(pos, placer)
local facedir = minetest.dir_to_facedir(placer:get_look_dir(), false) 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 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.remove_node(pos)
return minetest.chat_send_player(placer:get_player_name(), "Reformer will not fit there")
return true
end end
local number = tubelib.add_node(pos, "tubelib_addons1:reformer")
State:node_init(pos, number)
State:defect(pos, M(pos))
end, end,
-- the reformer needs 'on_dig' to be able to remove the upper node -- the reformer needs 'on_dig' to be able to remove the upper node
@ -266,11 +271,11 @@ minetest.register_node("tubelib_addons1:reformer_defect", {
minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z}) minetest.remove_node({x=pos.x, y=pos.y+1, z=pos.z})
end end
end, end,
after_dig_node = function(pos, oldnode, oldmetadata, digger) after_dig_node = function(pos, oldnode, oldmetadata, digger)
tubelib.remove_node(pos) tubelib.remove_node(pos)
end, end,
on_rotate = screwdriver.disallow, on_rotate = screwdriver.disallow,
allow_metadata_inventory_put = allow_metadata_inventory_put, allow_metadata_inventory_put = allow_metadata_inventory_put,
allow_metadata_inventory_move = allow_metadata_inventory_move, allow_metadata_inventory_move = allow_metadata_inventory_move,
@ -351,4 +356,4 @@ tubelib.register_node("tubelib_addons1:reformer", {"tubelib_addons1:reformer_def
on_node_repair = function(pos) on_node_repair = function(pos)
return State:on_node_repair(pos) return State:on_node_repair(pos)
end, end,
}) })