2020-02-18 18:34:52 +01:00
|
|
|
local S = minetest.get_translator("pipeworks")
|
2013-10-04 17:56:03 +02:00
|
|
|
local autocrafterCache = {} -- caches some recipe data to avoid to call the slow function minetest.get_craft_result() every second
|
2013-01-19 15:37:27 +01:00
|
|
|
|
2015-01-27 05:27:36 +01:00
|
|
|
local craft_time = 1
|
|
|
|
|
2015-01-26 21:27:47 +01:00
|
|
|
local function count_index(invlist)
|
|
|
|
local index = {}
|
2015-01-27 03:45:38 +01:00
|
|
|
for _, stack in pairs(invlist) do
|
|
|
|
if not stack:is_empty() then
|
|
|
|
local stack_name = stack:get_name()
|
|
|
|
index[stack_name] = (index[stack_name] or 0) + stack:get_count()
|
|
|
|
end
|
2013-10-30 08:33:09 +01:00
|
|
|
end
|
2015-01-26 21:27:47 +01:00
|
|
|
return index
|
2013-10-30 08:33:09 +01:00
|
|
|
end
|
|
|
|
|
2015-01-29 17:00:05 +01:00
|
|
|
local function get_item_info(stack)
|
|
|
|
local name = stack:get_name()
|
|
|
|
local def = minetest.registered_items[name]
|
2020-02-18 18:34:52 +01:00
|
|
|
local description = def and def.description or S("Unknown item")
|
2015-01-29 17:00:05 +01:00
|
|
|
return description, name
|
|
|
|
end
|
|
|
|
|
2015-01-27 03:45:38 +01:00
|
|
|
local function get_craft(pos, inventory, hash)
|
|
|
|
local hash = hash or minetest.hash_node_position(pos)
|
|
|
|
local craft = autocrafterCache[hash]
|
|
|
|
if not craft then
|
|
|
|
local recipe = inventory:get_list("recipe")
|
|
|
|
local output, decremented_input = minetest.get_craft_result({method = "normal", width = 3, items = recipe})
|
|
|
|
craft = {recipe = recipe, consumption=count_index(recipe), output = output, decremented_input = decremented_input}
|
|
|
|
autocrafterCache[hash] = craft
|
|
|
|
end
|
2015-01-28 06:23:46 +01:00
|
|
|
return craft
|
2015-01-26 18:34:05 +01:00
|
|
|
end
|
|
|
|
|
2015-01-26 22:04:56 +01:00
|
|
|
local function autocraft(inventory, craft)
|
2015-01-27 03:45:38 +01:00
|
|
|
if not craft then return false end
|
2015-01-26 21:27:47 +01:00
|
|
|
local output_item = craft.output.item
|
2015-01-27 03:45:38 +01:00
|
|
|
|
2015-01-26 22:04:56 +01:00
|
|
|
-- check if we have enough room in dst
|
2015-01-29 17:00:05 +01:00
|
|
|
if not inventory:room_for_item("dst", output_item) then return false end
|
2015-01-26 21:34:32 +01:00
|
|
|
local consumption = craft.consumption
|
2015-01-26 21:27:47 +01:00
|
|
|
local inv_index = count_index(inventory:get_list("src"))
|
2015-01-27 03:45:38 +01:00
|
|
|
-- check if we have enough material available
|
2015-01-26 21:27:47 +01:00
|
|
|
for itemname, number in pairs(consumption) do
|
2015-01-26 22:04:56 +01:00
|
|
|
if (not inv_index[itemname]) or inv_index[itemname] < number then return false end
|
2015-01-26 21:27:47 +01:00
|
|
|
end
|
2015-01-27 03:45:38 +01:00
|
|
|
-- consume material
|
2015-01-26 21:27:47 +01:00
|
|
|
for itemname, number in pairs(consumption) do
|
2021-02-05 17:17:50 +01:00
|
|
|
for _ = 1, number do -- We have to do that since remove_item does not work if count > stack_max
|
2015-01-26 21:27:47 +01:00
|
|
|
inventory:remove_item("src", ItemStack(itemname))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- craft the result into the dst inventory and add any "replacements" as well
|
|
|
|
inventory:add_item("dst", output_item)
|
|
|
|
for i = 1, 9 do
|
|
|
|
inventory:add_item("dst", craft.decremented_input.items[i])
|
2014-11-02 09:35:43 +01:00
|
|
|
end
|
2015-01-26 22:04:56 +01:00
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2015-01-27 03:45:38 +01:00
|
|
|
-- returns false to stop the timer, true to continue running
|
|
|
|
-- is started only from start_autocrafter(pos) after sanity checks and cached recipe
|
|
|
|
local function run_autocrafter(pos, elapsed)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inventory = meta:get_inventory()
|
|
|
|
local craft = get_craft(pos, inventory)
|
2015-01-29 17:00:05 +01:00
|
|
|
local output_item = craft.output.item
|
2015-01-28 06:23:46 +01:00
|
|
|
-- only use crafts that have an actual result
|
2015-01-29 17:00:05 +01:00
|
|
|
if output_item:is_empty() then
|
2020-02-18 18:34:52 +01:00
|
|
|
meta:set_string("infotext", S("unconfigured Autocrafter: unknown recipe"))
|
2015-01-28 06:23:46 +01:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
2021-02-05 17:17:50 +01:00
|
|
|
for _ = 1, math.floor(elapsed/craft_time) do
|
2015-01-27 05:27:36 +01:00
|
|
|
local continue = autocraft(inventory, craft)
|
|
|
|
if not continue then return false end
|
|
|
|
end
|
|
|
|
return true
|
2015-01-27 03:45:38 +01:00
|
|
|
end
|
2015-01-26 22:04:56 +01:00
|
|
|
|
2015-01-28 16:30:22 +01:00
|
|
|
local function start_crafter(pos)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if meta:get_int("enabled") == 1 then
|
|
|
|
local timer = minetest.get_node_timer(pos)
|
|
|
|
if not timer:is_started() then
|
|
|
|
timer:start(craft_time)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function after_inventory_change(pos)
|
|
|
|
start_crafter(pos)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- note, that this function assumes allready being updated to virtual items
|
|
|
|
-- and doesn't handle recipes with stacksizes > 1
|
|
|
|
local function after_recipe_change(pos, inventory)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
-- if we emptied the grid, there's no point in keeping it running or cached
|
|
|
|
if inventory:is_empty("recipe") then
|
|
|
|
minetest.get_node_timer(pos):stop()
|
|
|
|
autocrafterCache[minetest.hash_node_position(pos)] = nil
|
2020-02-18 18:34:52 +01:00
|
|
|
meta:set_string("infotext", S("unconfigured Autocrafter"))
|
Add digilines support to autocrafter
"on" and "off" messages turn it on or off, "single" crafts one item, and sending nested tables in the shape of the crafting grid sets the craft. Example message:
{
{"default:wood","default:wood","default:wood"},
{"default:wood","","default:wood"},
{"default:wood","default:wood","default:wood"}
}
2017-02-26 22:33:14 +01:00
|
|
|
inventory:set_stack("output", 1, "")
|
2015-01-28 16:30:22 +01:00
|
|
|
return
|
|
|
|
end
|
|
|
|
local recipe = inventory:get_list("recipe")
|
|
|
|
|
|
|
|
local hash = minetest.hash_node_position(pos)
|
|
|
|
local craft = autocrafterCache[hash]
|
|
|
|
|
|
|
|
if craft then
|
|
|
|
-- check if it changed
|
|
|
|
local cached_recipe = craft.recipe
|
|
|
|
for i = 1, 9 do
|
|
|
|
if recipe[i]:get_name() ~= cached_recipe[i]:get_name() then
|
|
|
|
autocrafterCache[hash] = nil -- invalidate recipe
|
|
|
|
craft = nil
|
|
|
|
break
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
craft = craft or get_craft(pos, inventory, hash)
|
|
|
|
local output_item = craft.output.item
|
2015-01-29 17:00:05 +01:00
|
|
|
local description, name = get_item_info(output_item)
|
2020-02-18 18:34:52 +01:00
|
|
|
meta:set_string("infotext", S("'@1' Autocrafter (@2)", description, name))
|
2015-01-28 16:30:22 +01:00
|
|
|
inventory:set_stack("output", 1, output_item)
|
|
|
|
|
|
|
|
after_inventory_change(pos)
|
|
|
|
end
|
|
|
|
|
2015-01-28 20:56:26 +01:00
|
|
|
-- clean out unknown items and groups, which would be handled like unknown items in the crafting grid
|
|
|
|
-- if minetest supports query by group one day, this might replace them
|
|
|
|
-- with a canonical version instead
|
|
|
|
local function normalize(item_list)
|
|
|
|
for i = 1, #item_list do
|
|
|
|
local name = item_list[i]
|
|
|
|
if not minetest.registered_items[name] then
|
|
|
|
item_list[i] = ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return item_list
|
|
|
|
end
|
|
|
|
|
2015-01-28 16:30:22 +01:00
|
|
|
local function on_output_change(pos, inventory, stack)
|
|
|
|
if not stack then
|
|
|
|
inventory:set_list("output", {})
|
|
|
|
inventory:set_list("recipe", {})
|
|
|
|
else
|
|
|
|
local input = minetest.get_craft_recipe(stack:get_name())
|
|
|
|
if not input.items or input.type ~= "normal" then return end
|
2015-01-30 21:09:43 +01:00
|
|
|
local items, width = normalize(input.items), input.width
|
|
|
|
local item_idx, width_idx = 1, 1
|
2015-02-02 03:14:26 +01:00
|
|
|
for i = 1, 9 do
|
|
|
|
if width_idx <= width then
|
|
|
|
inventory:set_stack("recipe", i, items[item_idx])
|
|
|
|
item_idx = item_idx + 1
|
|
|
|
else
|
|
|
|
inventory:set_stack("recipe", i, ItemStack(""))
|
|
|
|
end
|
|
|
|
width_idx = (width_idx < 3) and (width_idx + 1) or 1
|
|
|
|
end
|
2015-01-28 16:30:22 +01:00
|
|
|
-- we'll set the output slot in after_recipe_change to the actual result of the new recipe
|
|
|
|
end
|
|
|
|
after_recipe_change(pos, inventory)
|
|
|
|
end
|
|
|
|
|
2015-01-29 17:00:05 +01:00
|
|
|
-- returns false if we shouldn't bother attempting to start the timer again after this
|
|
|
|
local function update_meta(meta, enabled)
|
2015-01-27 21:55:19 +01:00
|
|
|
local state = enabled and "on" or "off"
|
2015-01-29 17:00:05 +01:00
|
|
|
meta:set_int("enabled", enabled and 1 or 0)
|
Add digilines support to autocrafter
"on" and "off" messages turn it on or off, "single" crafts one item, and sending nested tables in the shape of the crafting grid sets the craft. Example message:
{
{"default:wood","default:wood","default:wood"},
{"default:wood","","default:wood"},
{"default:wood","default:wood","default:wood"}
}
2017-02-26 22:33:14 +01:00
|
|
|
local fs = "size[8,12]"..
|
2015-01-27 21:55:19 +01:00
|
|
|
"list[context;recipe;0,0;3,3;]"..
|
2015-01-28 06:23:46 +01:00
|
|
|
"image[3,1;1,1;gui_hb_bg.png^[colorize:#141318:255]"..
|
|
|
|
"list[context;output;3,1;1,1;]"..
|
2017-04-12 13:03:17 +02:00
|
|
|
"image_button[3,2;1,0.6;pipeworks_button_" .. state .. ".png;" .. state .. ";;;false;pipeworks_button_interm.png]" ..
|
Add digilines support to autocrafter
"on" and "off" messages turn it on or off, "single" crafts one item, and sending nested tables in the shape of the crafting grid sets the craft. Example message:
{
{"default:wood","default:wood","default:wood"},
{"default:wood","","default:wood"},
{"default:wood","default:wood","default:wood"}
}
2017-02-26 22:33:14 +01:00
|
|
|
"list[context;src;0,4.5;8,3;]"..
|
2015-01-27 21:55:19 +01:00
|
|
|
"list[context;dst;4,0;4,3;]"..
|
2015-01-28 01:36:13 +01:00
|
|
|
default.gui_bg..
|
|
|
|
default.gui_bg_img..
|
|
|
|
default.gui_slots..
|
Add digilines support to autocrafter
"on" and "off" messages turn it on or off, "single" crafts one item, and sending nested tables in the shape of the crafting grid sets the craft. Example message:
{
{"default:wood","default:wood","default:wood"},
{"default:wood","","default:wood"},
{"default:wood","default:wood","default:wood"}
}
2017-02-26 22:33:14 +01:00
|
|
|
default.get_hotbar_bg(0,8) ..
|
|
|
|
"list[current_player;main;0,8;8,4;]" ..
|
2016-08-29 18:28:43 +02:00
|
|
|
"listring[current_player;main]"..
|
|
|
|
"listring[context;src]" ..
|
|
|
|
"listring[current_player;main]"..
|
2017-03-29 01:02:10 +02:00
|
|
|
"listring[context;dst]" ..
|
|
|
|
"listring[current_player;main]"
|
Add digilines support to autocrafter
"on" and "off" messages turn it on or off, "single" crafts one item, and sending nested tables in the shape of the crafting grid sets the craft. Example message:
{
{"default:wood","default:wood","default:wood"},
{"default:wood","","default:wood"},
{"default:wood","default:wood","default:wood"}
}
2017-02-26 22:33:14 +01:00
|
|
|
if minetest.get_modpath("digilines") then
|
2021-05-29 09:37:10 +02:00
|
|
|
fs = fs.."field[0.3,3.5;4.5,1;channel;"..S("Channel")..";${channel}]"..
|
|
|
|
"button[4.5,3.2;1.5,1;set_channel;"..S("Set").."]"..
|
|
|
|
"button_exit[6,3.2;2,1;close;"..S("Close").."]"
|
Add digilines support to autocrafter
"on" and "off" messages turn it on or off, "single" crafts one item, and sending nested tables in the shape of the crafting grid sets the craft. Example message:
{
{"default:wood","default:wood","default:wood"},
{"default:wood","","default:wood"},
{"default:wood","default:wood","default:wood"}
}
2017-02-26 22:33:14 +01:00
|
|
|
end
|
|
|
|
meta:set_string("formspec",fs)
|
2015-01-29 17:00:05 +01:00
|
|
|
|
|
|
|
-- toggling the button doesn't quite call for running a recipe change check
|
|
|
|
-- so instead we run a minimal version for infotext setting only
|
|
|
|
-- this might be more written code, but actually executes less
|
|
|
|
local output = meta:get_inventory():get_stack("output", 1)
|
|
|
|
if output:is_empty() then -- doesn't matter if paused or not
|
2020-02-18 18:34:52 +01:00
|
|
|
meta:set_string("infotext", S("unconfigured Autocrafter"))
|
2015-01-29 17:00:05 +01:00
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
local description, name = get_item_info(output)
|
2020-02-18 18:34:52 +01:00
|
|
|
local infotext = enabled and S("'@1' Autocrafter (@2)", description, name)
|
|
|
|
or S("paused '@1' Autocrafter", description)
|
2015-01-29 17:00:05 +01:00
|
|
|
|
|
|
|
meta:set_string("infotext", infotext)
|
|
|
|
return enabled
|
2015-01-27 21:55:19 +01:00
|
|
|
end
|
|
|
|
|
2015-01-28 18:55:59 +01:00
|
|
|
-- 1st version of the autocrafter had actual items in the crafting grid
|
|
|
|
-- the 2nd replaced these with virtual items, dropped the content on update and set "virtual_items" to string "1"
|
|
|
|
-- the third added an output inventory, changed the formspec and added a button for enabling/disabling
|
|
|
|
-- so we work out way backwards on this history and update each single case to the newest version
|
2015-01-29 17:00:05 +01:00
|
|
|
local function upgrade_autocrafter(pos, meta)
|
2015-01-28 18:55:59 +01:00
|
|
|
local meta = meta or minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
|
|
|
|
if inv:get_size("output") == 0 then -- we are version 2 or 1
|
|
|
|
inv:set_size("output", 1)
|
|
|
|
-- migrate the old autocrafters into an "enabled" state
|
2015-01-29 17:00:05 +01:00
|
|
|
update_meta(meta, true)
|
2015-01-28 18:55:59 +01:00
|
|
|
|
|
|
|
if meta:get_string("virtual_items") == "1" then -- we are version 2
|
2020-02-18 18:34:52 +01:00
|
|
|
-- we already dropped stuff, so lets remove the metadatasetting (we are not being called again for this node)
|
2015-01-28 18:55:59 +01:00
|
|
|
meta:set_string("virtual_items", "")
|
|
|
|
else -- we are version 1
|
2015-01-29 17:04:07 +01:00
|
|
|
local recipe = inv:get_list("recipe")
|
|
|
|
if not recipe then return end
|
|
|
|
for idx, stack in ipairs(recipe) do
|
2015-01-28 19:41:38 +01:00
|
|
|
if not stack:is_empty() then
|
2016-04-02 07:18:44 +02:00
|
|
|
minetest.add_item(pos, stack)
|
2015-01-28 19:41:38 +01:00
|
|
|
stack:set_count(1)
|
|
|
|
stack:set_wear(0)
|
|
|
|
inv:set_stack("recipe", idx, stack)
|
|
|
|
end
|
2015-01-28 18:55:59 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- update the recipe, cache, and start the crafter
|
2015-01-28 19:41:38 +01:00
|
|
|
autocrafterCache[minetest.hash_node_position(pos)] = nil
|
2015-01-28 18:55:59 +01:00
|
|
|
after_recipe_change(pos, inv)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2013-10-04 17:03:27 +02:00
|
|
|
minetest.register_node("pipeworks:autocrafter", {
|
2020-02-18 18:34:52 +01:00
|
|
|
description = S("Autocrafter"),
|
2015-11-18 10:07:00 +01:00
|
|
|
drawtype = "normal",
|
|
|
|
tiles = {"pipeworks_autocrafter.png"},
|
|
|
|
groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1},
|
2013-10-04 17:03:27 +02:00
|
|
|
tube = {insert_object = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
2015-01-27 03:45:38 +01:00
|
|
|
local added = inv:add_item("src", stack)
|
2015-01-28 16:30:22 +01:00
|
|
|
after_inventory_change(pos)
|
2015-01-27 03:45:38 +01:00
|
|
|
return added
|
2015-11-18 10:07:00 +01:00
|
|
|
end,
|
2013-10-04 17:03:27 +02:00
|
|
|
can_insert = function(pos, node, stack, direction)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
return inv:room_for_item("src", stack)
|
2015-11-18 10:07:00 +01:00
|
|
|
end,
|
|
|
|
input_inventory = "dst",
|
|
|
|
connect_sides = {left = 1, right = 1, front = 1, back = 1, top = 1, bottom = 1}},
|
2013-01-19 15:37:27 +01:00
|
|
|
on_construct = function(pos)
|
2013-07-01 05:55:07 +02:00
|
|
|
local meta = minetest.get_meta(pos)
|
2013-01-19 15:37:27 +01:00
|
|
|
local inv = meta:get_inventory()
|
2013-10-04 17:03:27 +02:00
|
|
|
inv:set_size("src", 3*8)
|
|
|
|
inv:set_size("recipe", 3*3)
|
|
|
|
inv:set_size("dst", 4*3)
|
2015-01-28 06:23:46 +01:00
|
|
|
inv:set_size("output", 1)
|
2015-01-29 17:00:05 +01:00
|
|
|
update_meta(meta, false)
|
2014-11-02 09:35:43 +01:00
|
|
|
end,
|
2015-01-27 21:55:19 +01:00
|
|
|
on_receive_fields = function(pos, formname, fields, sender)
|
2021-12-26 07:12:15 +01:00
|
|
|
if (fields.quit and not fields.key_enter_field) or not pipeworks.may_configure(pos, sender) then
|
2021-05-06 18:02:19 +02:00
|
|
|
return
|
|
|
|
end
|
2015-01-27 21:55:19 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if fields.on then
|
2015-01-29 17:00:05 +01:00
|
|
|
update_meta(meta, false)
|
2015-01-27 21:55:19 +01:00
|
|
|
minetest.get_node_timer(pos):stop()
|
|
|
|
elseif fields.off then
|
2015-01-29 17:00:05 +01:00
|
|
|
if update_meta(meta, true) then
|
|
|
|
start_crafter(pos)
|
|
|
|
end
|
2021-05-29 09:37:10 +02:00
|
|
|
end
|
|
|
|
if fields.channel then
|
|
|
|
meta:set_string("channel", fields.channel)
|
2015-01-27 21:55:19 +01:00
|
|
|
end
|
|
|
|
end,
|
2013-10-04 17:03:27 +02:00
|
|
|
can_dig = function(pos, player)
|
2015-01-29 17:00:05 +01:00
|
|
|
upgrade_autocrafter(pos)
|
2014-11-02 09:35:43 +01:00
|
|
|
local meta = minetest.get_meta(pos)
|
2013-01-19 15:37:27 +01:00
|
|
|
local inv = meta:get_inventory()
|
2014-11-02 09:35:43 +01:00
|
|
|
return (inv:is_empty("src") and inv:is_empty("dst"))
|
2015-11-18 10:07:00 +01:00
|
|
|
end,
|
2015-01-28 16:30:22 +01:00
|
|
|
after_place_node = pipeworks.scan_for_tube_objects,
|
2013-10-04 17:56:03 +02:00
|
|
|
after_dig_node = function(pos)
|
2013-12-15 08:53:10 +01:00
|
|
|
pipeworks.scan_for_tube_objects(pos)
|
2015-01-28 21:47:50 +01:00
|
|
|
end,
|
|
|
|
on_destruct = function(pos)
|
2013-10-04 20:36:17 +02:00
|
|
|
autocrafterCache[minetest.hash_node_position(pos)] = nil
|
2014-11-02 09:35:43 +01:00
|
|
|
end,
|
|
|
|
allow_metadata_inventory_put = function(pos, listname, index, stack, player)
|
2015-03-05 11:14:30 +01:00
|
|
|
if not pipeworks.may_configure(pos, player) then return 0 end
|
2015-01-29 17:00:05 +01:00
|
|
|
upgrade_autocrafter(pos)
|
2014-11-02 09:35:43 +01:00
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
|
|
if listname == "recipe" then
|
2015-01-28 16:30:22 +01:00
|
|
|
stack:set_count(1)
|
|
|
|
inv:set_stack(listname, index, stack)
|
2015-01-28 00:27:17 +01:00
|
|
|
after_recipe_change(pos, inv)
|
2014-11-02 09:35:43 +01:00
|
|
|
return 0
|
2015-01-28 06:23:46 +01:00
|
|
|
elseif listname == "output" then
|
|
|
|
on_output_change(pos, inv, stack)
|
|
|
|
return 0
|
2014-11-02 09:35:43 +01:00
|
|
|
end
|
2015-01-28 16:30:22 +01:00
|
|
|
after_inventory_change(pos)
|
2015-01-28 06:23:46 +01:00
|
|
|
return stack:get_count()
|
2014-11-02 09:35:43 +01:00
|
|
|
end,
|
|
|
|
allow_metadata_inventory_take = function(pos, listname, index, stack, player)
|
2015-03-05 11:14:30 +01:00
|
|
|
if not pipeworks.may_configure(pos, player) then
|
|
|
|
minetest.log("action", string.format("%s attempted to take from autocrafter at %s", player:get_player_name(), minetest.pos_to_string(pos)))
|
|
|
|
return 0
|
|
|
|
end
|
2015-01-29 17:00:05 +01:00
|
|
|
upgrade_autocrafter(pos)
|
2014-11-02 09:35:43 +01:00
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
|
|
if listname == "recipe" then
|
|
|
|
inv:set_stack(listname, index, ItemStack(""))
|
2015-01-28 00:27:17 +01:00
|
|
|
after_recipe_change(pos, inv)
|
2014-11-02 09:35:43 +01:00
|
|
|
return 0
|
2015-01-28 06:23:46 +01:00
|
|
|
elseif listname == "output" then
|
|
|
|
on_output_change(pos, inv, nil)
|
|
|
|
return 0
|
2014-11-02 09:35:43 +01:00
|
|
|
end
|
2015-01-28 16:30:22 +01:00
|
|
|
after_inventory_change(pos)
|
2015-01-28 06:23:46 +01:00
|
|
|
return stack:get_count()
|
2014-11-02 09:35:43 +01:00
|
|
|
end,
|
|
|
|
allow_metadata_inventory_move = function(pos, from_list, from_index, to_list, to_index, count, player)
|
2015-03-05 11:14:30 +01:00
|
|
|
if not pipeworks.may_configure(pos, player) then return 0 end
|
2015-01-29 17:00:05 +01:00
|
|
|
upgrade_autocrafter(pos)
|
2014-11-02 09:35:43 +01:00
|
|
|
local inv = minetest.get_meta(pos):get_inventory()
|
|
|
|
local stack = inv:get_stack(from_list, from_index)
|
2015-01-28 06:23:46 +01:00
|
|
|
|
|
|
|
if to_list == "output" then
|
|
|
|
on_output_change(pos, inv, stack)
|
|
|
|
return 0
|
|
|
|
elseif from_list == "output" then
|
2015-01-28 21:42:34 +01:00
|
|
|
on_output_change(pos, inv, nil)
|
2015-01-28 16:51:07 +01:00
|
|
|
if to_list ~= "recipe" then
|
|
|
|
return 0
|
|
|
|
end -- else fall through to recipe list handling
|
2015-01-28 06:23:46 +01:00
|
|
|
end
|
|
|
|
|
2015-01-28 00:42:22 +01:00
|
|
|
if from_list == "recipe" or to_list == "recipe" then
|
2015-01-28 16:51:07 +01:00
|
|
|
if from_list == "recipe" then
|
|
|
|
inv:set_stack(from_list, from_index, ItemStack(""))
|
|
|
|
end
|
|
|
|
if to_list == "recipe" then
|
|
|
|
stack:set_count(1)
|
|
|
|
inv:set_stack(to_list, to_index, stack)
|
|
|
|
end
|
2015-01-28 00:27:17 +01:00
|
|
|
after_recipe_change(pos, inv)
|
2014-11-02 09:35:43 +01:00
|
|
|
return 0
|
|
|
|
end
|
2015-01-28 00:42:22 +01:00
|
|
|
|
2015-01-28 16:30:22 +01:00
|
|
|
after_inventory_change(pos)
|
|
|
|
return count
|
2014-11-02 09:35:43 +01:00
|
|
|
end,
|
Add digilines support to autocrafter
"on" and "off" messages turn it on or off, "single" crafts one item, and sending nested tables in the shape of the crafting grid sets the craft. Example message:
{
{"default:wood","default:wood","default:wood"},
{"default:wood","","default:wood"},
{"default:wood","default:wood","default:wood"}
}
2017-02-26 22:33:14 +01:00
|
|
|
on_timer = run_autocrafter,
|
|
|
|
digiline = {
|
|
|
|
receptor = {},
|
|
|
|
effector = {
|
|
|
|
action = function(pos,node,channel,msg)
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
if channel ~= meta:get_string("channel") then return end
|
|
|
|
if type(msg) == "table" then
|
|
|
|
if #msg < 3 then return end
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
for y=0,2,1 do
|
|
|
|
for x=1,3,1 do
|
|
|
|
local slot = y*3+x
|
|
|
|
if minetest.registered_items[msg[y+1][x]] then
|
|
|
|
inv:set_stack("recipe",slot,ItemStack(msg[y+1][x]))
|
|
|
|
else
|
|
|
|
inv:set_stack("recipe",slot,ItemStack(""))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
after_recipe_change(pos,inv)
|
2020-07-23 01:49:37 +02:00
|
|
|
elseif msg == "get_recipe" then
|
|
|
|
local meta = minetest.get_meta(pos)
|
|
|
|
local inv = meta:get_inventory()
|
|
|
|
local recipe = {}
|
|
|
|
for y=0,2,1 do
|
|
|
|
local row = {}
|
|
|
|
for x=1,3,1 do
|
|
|
|
local slot = y*3+x
|
|
|
|
table.insert(row, inv:get_stack("recipe",slot):get_name())
|
|
|
|
end
|
|
|
|
table.insert(recipe, row)
|
|
|
|
end
|
|
|
|
local setchan = meta:get_string("channel")
|
|
|
|
local output = inv:get_stack("output", 1)
|
|
|
|
digiline:receptor_send(pos, digiline.rules.default, setchan, {
|
|
|
|
recipe = recipe,
|
|
|
|
result = {
|
|
|
|
name = output:get_name(),
|
|
|
|
count = output:get_count(),
|
|
|
|
}
|
|
|
|
})
|
Add digilines support to autocrafter
"on" and "off" messages turn it on or off, "single" crafts one item, and sending nested tables in the shape of the crafting grid sets the craft. Example message:
{
{"default:wood","default:wood","default:wood"},
{"default:wood","","default:wood"},
{"default:wood","default:wood","default:wood"}
}
2017-02-26 22:33:14 +01:00
|
|
|
elseif msg == "off" then
|
|
|
|
update_meta(meta, false)
|
|
|
|
minetest.get_node_timer(pos):stop()
|
|
|
|
elseif msg == "on" then
|
|
|
|
if update_meta(meta, true) then
|
|
|
|
start_crafter(pos)
|
|
|
|
end
|
|
|
|
elseif msg == "single" then
|
|
|
|
run_autocrafter(pos,1)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
},
|
|
|
|
},
|
rewrote autoplacement code to make it more aware of filters,
autocrafter, nodebreaker, deployer, and made sure each item will only
initiate a connection to those sides which can accept such. Fixed
various autorouting bugs as I ran across them. Autorouting for various
devices is now:
filters: left and right sides only
nodebreaker, deployer: back only
autocrafter: all six sides
chests: top, bottom, left, right, back (not front)
furnace: bottom, left, right, back (not the top or front)
2013-06-24 03:36:13 +02:00
|
|
|
})
|
2021-04-02 21:48:28 +02:00
|
|
|
pipeworks.ui_cat_tube_list[#pipeworks.ui_cat_tube_list+1] = "pipeworks:autocrafter"
|
2015-01-29 20:10:45 +01:00
|
|
|
|
|
|
|
minetest.register_craft( {
|
|
|
|
output = "pipeworks:autocrafter 2",
|
|
|
|
recipe = {
|
|
|
|
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" },
|
2018-11-15 01:51:56 +01:00
|
|
|
{ "basic_materials:plastic_sheet", "default:steel_ingot", "basic_materials:plastic_sheet" },
|
2015-01-29 20:10:45 +01:00
|
|
|
{ "default:steel_ingot", "default:mese_crystal", "default:steel_ingot" }
|
|
|
|
},
|
|
|
|
})
|