mirror of
https://github.com/mt-mods/pipeworks.git
synced 2025-06-30 07:10:45 +02:00
Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@ -35,25 +35,42 @@ end
|
||||
|
||||
local function autocraft(inventory, craft)
|
||||
if not craft then return false end
|
||||
local output_item = craft.output.item
|
||||
|
||||
-- check if we have enough room in dst
|
||||
if not inventory:room_for_item("dst", output_item) then return false end
|
||||
local consumption = craft.consumption
|
||||
local inv_index = count_index(inventory:get_list("src"))
|
||||
-- check if we have enough material available
|
||||
for itemname, number in pairs(consumption) do
|
||||
local inv_index = count_index(inventory:get_list("src"))
|
||||
for itemname, number in pairs(craft.consumption) do
|
||||
if (not inv_index[itemname]) or inv_index[itemname] < number then return false end
|
||||
end
|
||||
-- check if output and all replacements fit in dst
|
||||
local output = craft.output.item
|
||||
local out_items = count_index(craft.decremented_input.items)
|
||||
out_items[output:get_name()] = (out_items[output:get_name()] or 0) + output:get_count()
|
||||
local empty_count = 0
|
||||
for _,item in pairs(inventory:get_list("dst")) do
|
||||
if item:is_empty() then
|
||||
empty_count = empty_count + 1
|
||||
else
|
||||
local name = item:get_name()
|
||||
if out_items[name] then
|
||||
out_items[name] = out_items[name] - item:get_free_space()
|
||||
end
|
||||
end
|
||||
end
|
||||
for _,count in pairs(out_items) do
|
||||
if count > 0 then
|
||||
empty_count = empty_count - 1
|
||||
end
|
||||
end
|
||||
if empty_count < 0 then
|
||||
return false
|
||||
end
|
||||
-- consume material
|
||||
for itemname, number in pairs(consumption) do
|
||||
for itemname, number in pairs(craft.consumption) do
|
||||
for _ = 1, number do -- We have to do that since remove_item does not work if count > stack_max
|
||||
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)
|
||||
inventory:add_item("dst", output)
|
||||
for i = 1, 9 do
|
||||
inventory:add_item("dst", craft.decremented_input.items[i])
|
||||
end
|
||||
@ -176,7 +193,7 @@ local function update_meta(meta, enabled)
|
||||
local state = enabled and "on" or "off"
|
||||
meta:set_int("enabled", enabled and 1 or 0)
|
||||
local list_backgrounds = ""
|
||||
if minetest.get_modpath("i3") then
|
||||
if minetest.get_modpath("i3") or minetest.get_modpath("mcl_formspec") then
|
||||
list_backgrounds = "style_type[box;colors=#666]"
|
||||
for i=0, 2 do
|
||||
for j=0, 2 do
|
||||
@ -275,8 +292,8 @@ minetest.register_node("pipeworks:autocrafter", {
|
||||
description = S("Autocrafter"),
|
||||
drawtype = "normal",
|
||||
tiles = {"pipeworks_autocrafter.png"},
|
||||
groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1, dig_generic = 1, axey=5},
|
||||
_mcl_hardness=1.6,
|
||||
groups = {snappy = 3, tubedevice = 1, tubedevice_receiver = 1, dig_generic = 1, axey=1, handy=1, pickaxey=1},
|
||||
_mcl_hardness=0.8,
|
||||
tube = {insert_object = function(pos, node, stack, direction)
|
||||
local meta = minetest.get_meta(pos)
|
||||
local inv = meta:get_inventory()
|
||||
|
Reference in New Issue
Block a user