forked from mtcontrib/pipeworks
Make items in autocrafters virtual as well
This commit is contained in:
parent
cf9c4fa3b1
commit
3f85f83e35
|
@ -77,6 +77,17 @@ local function autocraft(inventory, pos)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function update_autocrafter(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
|
if meta:get_string("virtual_items") == "" then
|
||||||
|
meta:set_string("virtual_items", "1")
|
||||||
|
local inv = meta:get_inventory()
|
||||||
|
for _, stack in ipairs(inv:get_list("recipe")) do
|
||||||
|
minetest.item_drop(stack, "", pos)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
minetest.register_node("pipeworks:autocrafter", {
|
minetest.register_node("pipeworks:autocrafter", {
|
||||||
description = "Autocrafter",
|
description = "Autocrafter",
|
||||||
drawtype = "normal",
|
drawtype = "normal",
|
||||||
|
@ -103,15 +114,18 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||||
"list[current_name;dst;4,0;4,3;]"..
|
"list[current_name;dst;4,0;4,3;]"..
|
||||||
"list[current_player;main;0,7;8,4;]")
|
"list[current_player;main;0,7;8,4;]")
|
||||||
meta:set_string("infotext", "Autocrafter")
|
meta:set_string("infotext", "Autocrafter")
|
||||||
|
meta:set_string("virtual_items", "1")
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
inv:set_size("src", 3*8)
|
inv:set_size("src", 3*8)
|
||||||
inv:set_size("recipe", 3*3)
|
inv:set_size("recipe", 3*3)
|
||||||
inv:set_size("dst", 4*3)
|
inv:set_size("dst", 4*3)
|
||||||
end,
|
end,
|
||||||
|
on_punch = update_autocrafter,
|
||||||
can_dig = function(pos, player)
|
can_dig = function(pos, player)
|
||||||
local meta = minetest.get_meta(pos);
|
update_autocrafter(pos)
|
||||||
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
return (inv:is_empty("src") and inv:is_empty("recipe") and inv:is_empty("dst"))
|
return (inv:is_empty("src") and inv:is_empty("dst"))
|
||||||
end,
|
end,
|
||||||
after_place_node = function(pos)
|
after_place_node = function(pos)
|
||||||
pipeworks.scan_for_tube_objects(pos)
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
|
@ -119,7 +133,46 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||||
after_dig_node = function(pos)
|
after_dig_node = function(pos)
|
||||||
pipeworks.scan_for_tube_objects(pos)
|
pipeworks.scan_for_tube_objects(pos)
|
||||||
autocrafterCache[minetest.hash_node_position(pos)] = nil
|
autocrafterCache[minetest.hash_node_position(pos)] = nil
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
||||||
|
update_autocrafter(pos)
|
||||||
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
|
if listname == "recipe" then
|
||||||
|
local stack_copy = ItemStack(stack)
|
||||||
|
stack_copy:set_count(1)
|
||||||
|
inv:set_stack(listname, index, stack_copy)
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return stack:get_count()
|
||||||
end
|
end
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
||||||
|
update_autocrafter(pos)
|
||||||
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
|
if listname == "recipe" then
|
||||||
|
inv:set_stack(listname, index, ItemStack(""))
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return stack:get_count()
|
||||||
|
end
|
||||||
|
end,
|
||||||
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
||||||
|
update_autocrafter(pos)
|
||||||
|
local inv = minetest.get_meta(pos):get_inventory()
|
||||||
|
local stack = inv:get_stack(from_list, from_index)
|
||||||
|
stack:set_count(count)
|
||||||
|
if from_list == "recipe" then
|
||||||
|
inv:set_stack(from_list, from_index, ItemStack(""))
|
||||||
|
return 0
|
||||||
|
elseif to_list == "recipe" then
|
||||||
|
local stack_copy = ItemStack(stack)
|
||||||
|
stack_copy:set_count(1)
|
||||||
|
inv:set_stack(to_list, to_index, stack_copy)
|
||||||
|
return 0
|
||||||
|
else
|
||||||
|
return stack:get_count()
|
||||||
|
end
|
||||||
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
minetest.register_abm({nodenames = {"pipeworks:autocrafter"}, interval = 1, chance = 1,
|
minetest.register_abm({nodenames = {"pipeworks:autocrafter"}, interval = 1, chance = 1,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user