Add pre-assignment menu to the furnace

This commit is contained in:
Joachim Stolberg 2024-07-14 22:26:54 +02:00
parent a1485b6eab
commit 9a699a361f
3 changed files with 40 additions and 5 deletions

View File

@ -10,9 +10,12 @@
Configured inventory lib
Assuming the inventory has the name "conf"
Otherwise the name has to be provided as argument
]]--
local StackName = ... or "conf"
-- for lazy programmers
local M = minetest.get_meta
@ -22,7 +25,7 @@ function inv_lib.preassigned_stacks(pos, xsize, ysize)
local inv = M(pos):get_inventory()
local tbl = {}
for idx = 1, xsize * ysize do
local item_name = inv:get_stack("conf", idx):get_name()
local item_name = inv:get_stack(StackName, idx):get_name()
if item_name ~= "" then
local x = (idx - 1) % xsize
local y = math.floor((idx - 1) / xsize)
@ -36,7 +39,7 @@ function inv_lib.item_filter(pos, size)
local inv = M(pos):get_inventory()
local filter = {}
for idx = 1, size do
local item_name = inv:get_stack("conf", idx):get_name()
local item_name = inv:get_stack(StackName, idx):get_name()
if item_name == "" then item_name = "unconfigured" end
if not filter[item_name] then
filter[item_name] = {}

View File

@ -129,7 +129,11 @@ local function generate_formspec_substring(pos, meta, form_def, player_name)
tbl[#tbl+1] = "dropdown[4.72," .. (offs) .. ";5.5,1.4;" .. elem.name .. ";" .. elem.choices .. ";" .. idx .. "]"
end
elseif elem.type == "items" then -- inventory
if elem.size then
tbl[#tbl+1] = "list[detached:" .. minetest.formspec_escape(player_name) .. "_techage_wrench_menu;cfg;4.75," .. offs .. ";" .. elem.size .. ",1;]"
else
tbl[#tbl+1] = "list[detached:" .. minetest.formspec_escape(player_name) .. "_techage_wrench_menu;cfg;4.75," .. offs .. ";" .. elem.width .. "," .. elem.height .. ";]"
end
player_inv_needed = true
end
end

View File

@ -30,7 +30,19 @@ local reset_cooking = techage.furnace.reset_cooking
local get_ingredients = techage.furnace.get_ingredients
local check_if_worth_to_wakeup = techage.furnace.check_if_worth_to_wakeup
local range = techage.in_range
local MP = minetest.get_modpath(minetest.get_current_modname())
local mConf = assert(loadfile(MP .. "/basis/conf_inv.lua"))("cfg")
local WRENCH_MENU3 = {
{
type = "items",
name = "config",
label = S("Pre-Assignment Input Inv."),
tooltip = S("Stack locations can be pre-assigned to specific items,\nto be filled only with those items."),
width = 2,
height = 2,
}
}
local function update_recipe_menu(pos, nvm)
local ingr = get_ingredients(pos)
@ -47,7 +59,9 @@ local function formspec(self, pos, nvm)
default.gui_bg..
default.gui_bg_img..
default.gui_slots..
techage.wrench_image(7.6, -0.2) ..
"list[context;src;0,0;2,2;]"..
mConf.preassigned_stacks(pos, 2, 2)..
"image[2,0.5;1,1;techage_form_arrow_bg.png^[lowpart:"..
(nvm.item_percent or 0)..":techage_form_arrow_fg.png^[transformR270]"..
"image_button[2,2;1,1;".. self:get_state_button_image(nvm) ..";state_button;]"..
@ -239,8 +253,19 @@ local tubing = {
local meta = minetest.get_meta(pos)
if meta:get_int("push_dir") == in_dir or in_dir == 5 then
local inv = M(pos):get_inventory()
local mem = techage.get_mem(pos)
mem.filter = mem.filter or mConf.item_filter(pos, 4)
mem.chest_configured = mem.chest_configured or not inv:is_empty("cfg")
if mem.chest_configured then
local name = stack:get_name()
local stacks = mem.filter[name] or mem.filter["unconfigured"]
return mConf.put_items(pos, inv, "src", stack, stacks, idx)
else
return techage.put_items(inv, "src", stack, idx)
end
end
end,
on_unpull_item = function(pos, in_dir, stack)
local meta = minetest.get_meta(pos)
@ -283,6 +308,7 @@ local _, node_name_ta3, _ =
local inv = M(pos):get_inventory()
inv:set_size("src", 2*2)
inv:set_size("dst", 2*2)
inv:set_size("cfg", 2*2)
end,
can_dig = can_dig,
node_timer = keep_running,
@ -293,6 +319,8 @@ local _, node_name_ta3, _ =
on_metadata_inventory_put = on_metadata_inventory,
on_metadata_inventory_take = on_metadata_inventory,
on_metadata_inventory_move = on_metadata_inventory,
ta3_formspec = WRENCH_MENU3,
on_rightclick = on_rightclick,
groups = {choppy=2, cracky=2, crumbly=2},
sounds = default.node_sound_wood_defaults(),
num_items = {0,1,1,1},