Fix return of replacement items (#5)

This commit is contained in:
fluxionary 2021-08-21 00:42:22 -07:00 committed by GitHub
parent 69083ed6f5
commit 64e7ee216b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -65,10 +65,10 @@ minetest.register_node("crafting_bench:workbench",{
end, end,
}) })
local get_recipe = function ( inv ) local get_recipe = function ( inv )
local result, needed, input local output, needed, decremented_input
needed = inv:get_list( 'rec' ) needed = inv:get_list( 'rec' )
result, input = minetest.get_craft_result( { output, decremented_input = minetest.get_craft_result( {
method = 'normal', method = 'normal',
width = 3, width = 3,
items = needed items = needed
@ -76,13 +76,13 @@ local get_recipe = function ( inv )
local totalneed = {} local totalneed = {}
if result.item:is_empty() then if output.item:is_empty() then
result = nil output = nil
else else
result = result.item output = output.item
for _, item in ipairs( needed ) do for _, item in ipairs( needed ) do
if item ~= nil and not item:is_empty() and not inv:contains_item( 'src', item ) then if item ~= nil and not item:is_empty() and not inv:contains_item( 'src', item ) then
result = nil output = nil
break break
end end
if item ~= nil and not item:is_empty() then if item ~= nil and not item:is_empty() then
@ -106,13 +106,13 @@ local get_recipe = function ( inv )
end end
end end
if number > 0 then if number > 0 then
result = nil output = nil
break break
end end
end end
end end
return needed, input, result return needed, decremented_input, output
end end
minetest.register_abm( { minetest.register_abm( {
@ -122,32 +122,25 @@ minetest.register_abm( {
action = function ( pos, node ) action = function ( pos, node )
local meta = minetest.get_meta( pos ) local meta = minetest.get_meta( pos )
local inv = meta:get_inventory() local inv = meta:get_inventory()
local result, newinput, needed local output, decremented_input, needed
if not inv:is_empty( 'src' ) then if not inv:is_empty( 'src' ) then
-- Check for a valid recipe and sufficient resources to craft it -- Check for a valid recipe and sufficient resources to craft it
needed, newinput, result = get_recipe( inv ) needed, decremented_input, output = get_recipe( inv )
if result ~= nil and inv:room_for_item( 'dst', result ) then if output ~= nil and inv:room_for_item( 'dst', output) then
inv:add_item( 'dst', result ) inv:add_item( 'dst', output)
for i, item in pairs( needed ) do for _, item in pairs( needed ) do
if item ~= nil and item ~= '' then if item ~= nil and item ~= '' then
inv:remove_item( 'src', ItemStack( item ) ) inv:remove_item( 'src', ItemStack( item ) )
end end
if newinput[i] ~= nil and not newinput[i]:is_empty() then
inv:add_item( 'src', newinput[i] )
end end
for i = 1, 9 do
inv:add_item( 'dst', decremented_input.items[i] )
end end
end end
end end
end end
} ) } )
local function has_locked_chest_privilege(meta, player)
if player:get_player_name() ~= meta:get_string("owner") then
return false
end
return true
end
minetest.register_craft({ minetest.register_craft({
output = "crafting_bench:workbench", output = "crafting_bench:workbench",
recipe = { recipe = {