Add chests, the beginnings of a machines API, and other things
This commit is contained in:
parent
3720070a28
commit
4d8312b79d
22 changed files with 557 additions and 16 deletions
0
mods/rgt_machines/modpack.conf
Normal file
0
mods/rgt_machines/modpack.conf
Normal file
109
mods/rgt_machines/rgt_furnace/init.lua
Normal file
109
mods/rgt_machines/rgt_furnace/init.lua
Normal 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
|
||||
})
|
||||
2
mods/rgt_machines/rgt_furnace/mod.conf
Normal file
2
mods/rgt_machines/rgt_furnace/mod.conf
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_furnace
|
||||
depends = rgt_machines_core
|
||||
27
mods/rgt_machines/rgt_machines_core/init.lua
Normal file
27
mods/rgt_machines/rgt_machines_core/init.lua
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
rgt_machines = {
|
||||
registered_machines = {}
|
||||
}
|
||||
local ns = rgt_machines
|
||||
|
||||
-- This abstracts away the use of multiple nodes for visual state feedback by
|
||||
-- copying all node callbacks into each node, so that by default the machine
|
||||
-- behaves exactly the same regardless of the underlying node type.
|
||||
--[[
|
||||
{
|
||||
states = { ... }, -- Alternate visual states for this node. All properties of the resultant node may be overriden.
|
||||
...
|
||||
}
|
||||
--]]
|
||||
function ns.register_machine(name, def)
|
||||
if not def.groups then
|
||||
def.groups = {}
|
||||
end
|
||||
def.groups.rgt_machine = 1
|
||||
def.groups.run_on_activate = 1
|
||||
def.groups[name] = 1
|
||||
ns.registered_machines[name] = def
|
||||
for state, x in pairs(def.states) do
|
||||
rgt.register_node(name.."_"..state, extend(table.copy(def), x))
|
||||
end
|
||||
end
|
||||
|
||||
2
mods/rgt_machines/rgt_machines_core/mod.conf
Normal file
2
mods/rgt_machines/rgt_machines_core/mod.conf
Normal file
|
|
@ -0,0 +1,2 @@
|
|||
name = rgt_machines_core
|
||||
depends = rgt_world, rgt_player
|
||||
Loading…
Add table
Add a link
Reference in a new issue