From 7493f657d99b764ea2b0c0f22890742bcfd4f8ae Mon Sep 17 00:00:00 2001 From: Zenon Seth Date: Mon, 22 Jul 2024 17:22:28 +0100 Subject: [PATCH] Improve auto-/supplier- crafting crafting inventory usability by allowing moving and replacement --- api/crafter_auto.lua | 10 ++++++++-- api/crafting_supplier.lua | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/api/crafter_auto.lua b/api/crafter_auto.lua index 5d3f8b6..7bf218c 100644 --- a/api/crafter_auto.lua +++ b/api/crafter_auto.lua @@ -87,8 +87,12 @@ local function autocrafter_allow_metadata_inv_put(pos, listname, index, stack, p if listname == INV_CRAFT then local inv = minetest.get_meta(pos):get_inventory() local st = inv:get_stack(listname, index) - st:add_item(stack) - inv:set_stack(listname, index, st) + if st:get_name() == stack:get_name() then + st:add_item(stack) + inv:set_stack(listname, index, st) + else + inv:set_stack(listname, index, stack) + end update_craft_output(inv) return 0 end @@ -112,11 +116,13 @@ end local function autocrafter_allow_metadata_inv_move(pos, from_list, from_index, to_list, to_index, count, player) if minetest.is_protected(pos, player:get_player_name()) then return 0 end if from_list == INV_DST and to_list == INV_SRC then return count end + if from_list == INV_CRAFT and to_list == INV_CRAFT then return count end return 0 end local function autocrafter_on_inv_change(pos) local inv = minetest.get_meta(pos):get_inventory() + update_craft_output(inv) logistica.start_node_timer(pos, TIMER_SHORT) end diff --git a/api/crafting_supplier.lua b/api/crafting_supplier.lua index 1092468..808d58f 100644 --- a/api/crafting_supplier.lua +++ b/api/crafting_supplier.lua @@ -82,8 +82,12 @@ local function allow_craftsup_storage_inv_put(pos, listname, index, stack, playe if listname == INV_CRAFT then local inv = minetest.get_meta(pos):get_inventory() local st = inv:get_stack(listname, index) - st:add_item(stack) - inv:set_stack(listname, index, st) + if st:get_name() == stack:get_name() then + st:add_item(stack) + inv:set_stack(listname, index, st) + else + inv:set_stack(listname, index, stack) + end update_craft_output(minetest.get_meta(pos):get_inventory()) logistica.update_cache_at_pos(pos, LOG_CACHE_SUPPLIER) end @@ -108,6 +112,7 @@ local function allow_craftsup_inv_take(pos, listname, index, stack, player) end local function allow_craftsup_inv_move(pos, from_list, from_index, to_list, to_index, count, player) + if from_list == INV_CRAFT and to_list == INV_CRAFT then return count end return 0 end @@ -121,6 +126,11 @@ local function on_craftsup_inventory_take(pos, listname, index, stack, player) logistica.update_cache_at_pos(pos, LOG_CACHE_SUPPLIER) end +local function on_craftsup_inventory_move(pos, from_list, from_index, to_list, to_index, count, player) + update_craft_output(minetest.get_meta(pos):get_inventory()) + logistica.update_cache_at_pos(pos, LOG_CACHE_SUPPLIER) +end + local function can_dig_craftsup(pos, player) local inv = minetest.get_meta(pos):get_inventory() local main = logistica.get_list(inv, INV_MAIN) @@ -176,6 +186,7 @@ function logistica.register_crafting_supplier(desc, name, tiles) allow_metadata_inventory_move = allow_craftsup_inv_move, on_metadata_inventory_put = on_craftsup_inventory_put, on_metadata_inventory_take = on_craftsup_inventory_take, + on_metadata_inventory_move = on_craftsup_inventory_move, can_dig = can_dig_craftsup, logistica = { on_power = on_craftsup_power,