Add chests, the beginnings of a machines API, and other things

This commit is contained in:
Signal 2025-10-22 18:25:22 -04:00
parent 3720070a28
commit 4d8312b79d
22 changed files with 557 additions and 16 deletions

View file

@ -0,0 +1,109 @@
local function update_formspec(pos)
end
local function on_input(pos, m, inv)
end
local function on_add_fuel(pos, m, inv)
end
local function destination_list(s)
return minetest.get_item_group(s:get_name(), "furnace_fuel") > 0 and "fuel" or "input"
end
local function can_run(pos, m, inv)
return false
end
rgt_machines.register_machine("fuel_furnace", {
states = {
idle = {
tiles = {"rgt_stone.png"},
},
active = {
tiles = {"rgt_stone.png"},
}
},
on_construct = function(pos)
local m = minetest.get_meta(pos)
local inv = m:get_inventory()
inv:set_size("input", 1)
inv:set_size("output", 1)
-- Dummy list handle Shift-adding properly.
inv:set_size("sort", 1)
inv:set_size("fuel", 1)
end,
get_gui = function(pos)
local loc = "nodemeta:"..pos.x..","..pos.y..","..pos.z
local fs = "\
formspec_version[10]\
size[12,12]\
\
image["..(2 -0.0625)..","..(2 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
list["..loc..";input;2,2;1,1;]\
\
image["..(5 -0.0625)..","..(3 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
list["..loc..";output;5,3;1,1;]\
\
image["..(2 -0.0625)..","..(4 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
list["..loc..";fuel;2,4;1,1;]\
"
for x = 0, 7 do
for y = 0, 3 do
fs = fs.."\
image["..(x *1.25 +1.125 -0.0625)..","..(y *1.25 +6.5 -0.0625)..";1.14,1.14;rgt_other_button_bg.png;8,8]\
"
end
end
fs = fs.."\
list[current_player;main;1.125,6.5;8,4;]\
\
listring["..loc..";output]\
listring[current_player;main]\
listring["..loc..";sort]\
listring[current_player;main]\
listring["..loc..";input]\
listring[current_player;main]\
listring["..loc..";fuel]\
listring[current_player;main]\
"
end,
allow_metadata_inventory_put = function(pos, list, idx, s, p)
local inv = minetest.get_meta(pos):get_inventory()
if list == "output" then
return 0
elseif list == "input" then
return s:get_count()
elseif list == "fuel" then
return minetest.get_item_group(s:get_name(), "furnace_fuel") > 0 and s:get_count() or 0
elseif list == "sort" then
local dst = destination_list(s)
if dst then
-- Add everything if we can.
if inv:room_for_item(dst, s) then
return s:get_count()
-- If not, and the stacks are compatible, add as much as possible.
elseif inv:room_for_item(dst, s:take_item()) then
return s:get_stack_max() -inv:get_stack(dst, 1):get_count()
end
end
return 0
end
return 0
end,
on_metadata_inventory_put = function(pos, list, idx, s, p)
if list == "sort" then
local inv = minetest.get_meta(pos):get_inventory()
local dst = destination_list(s)
inv:add_item(dst, s)
-- Ensure the sorter list never has anything in it.
inv:set_stack("sort", 1, ItemStack(""))
end
end
})