mirror of
https://github.com/theFox6/microexpansion.git
synced 2024-11-26 09:03:51 +01:00
Be sure to reset the size as it changes.
This commit is contained in:
parent
9e07d19b22
commit
3c91acd158
@ -47,7 +47,7 @@ local function chest_formspec(pos, start_id, listname, page_max, q, c)
|
|||||||
]]
|
]]
|
||||||
end
|
end
|
||||||
list = list .. [[
|
list = list .. [[
|
||||||
list[context;recipe;0.22,5.22;3,3;]
|
list[context;recipe;0.22,5.22;3,3;]
|
||||||
list[context;output;4,6.22;1,1;]
|
list[context;output;4,6.22;1,1;]
|
||||||
]]
|
]]
|
||||||
list = list .. [[
|
list = list .. [[
|
||||||
@ -323,17 +323,17 @@ local function on_output_change(pos, linv, stack)
|
|||||||
for i = 1, 9 do
|
for i = 1, 9 do
|
||||||
local prev = linv:get_stack("recipe", i)
|
local prev = linv:get_stack("recipe", i)
|
||||||
if prev and prev:get_name() ~= "" and not inv:room_for_item("main", prev) then
|
if prev and prev:get_name() ~= "" and not inv:room_for_item("main", prev) then
|
||||||
-- full, no room to remove
|
-- full, no room to remove
|
||||||
has_enough = false
|
has_enough = false
|
||||||
elseif prev and prev:get_name() ~= "" and me.insert_item(prev, net, inv, "main"):get_count() > 0 then
|
elseif prev and prev:get_name() ~= "" and me.insert_item(prev, net, inv, "main"):get_count() > 0 then
|
||||||
net:set_storage_space(true)
|
net:set_storage_space(true)
|
||||||
-- full, no room to remove
|
-- full, no room to remove
|
||||||
-- push into player inventory?
|
-- push into player inventory?
|
||||||
-- Don't have to worry about this happening until minetest is fully multithreaded
|
-- Don't have to worry about this happening until minetest is fully multithreaded
|
||||||
has_enough = false
|
has_enough = false
|
||||||
else
|
else
|
||||||
net:set_storage_space(true)
|
net:set_storage_space(true)
|
||||||
linv:set_stack("recipe", i, ItemStack(""))
|
linv:set_stack("recipe", i, ItemStack(""))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return has_enough
|
return has_enough
|
||||||
@ -354,19 +354,19 @@ local function on_output_change(pos, linv, stack)
|
|||||||
local typename = me.block_to_typename_map[machine_name]
|
local typename = me.block_to_typename_map[machine_name]
|
||||||
local recip = typename and me.get_recipe(typename, inputs)
|
local recip = typename and me.get_recipe(typename, inputs)
|
||||||
if recip and recip.output then
|
if recip and recip.output then
|
||||||
recip.intput = inputs
|
recip.intput = inputs
|
||||||
-- me.log("PROCESS: "..name.." was found for "..typename.." on a "..machine_name, "error")
|
-- me.log("PROCESS: "..name.." was found for "..typename.." on a "..machine_name, "error")
|
||||||
-- freezer can produce two outputs, we only care about the first.
|
-- freezer can produce two outputs, we only care about the first.
|
||||||
if recip.output[1] then
|
if recip.output[1] then
|
||||||
recip.output = recip.output[1]
|
recip.output = recip.output[1]
|
||||||
end
|
end
|
||||||
stack = ItemStack(recip.output)
|
stack = ItemStack(recip.output)
|
||||||
linv:set_stack("output", 1, stack)
|
linv:set_stack("output", 1, stack)
|
||||||
-- me.log("PROCESS: and the output is "..minetest.serialize(recip.output), "error")
|
-- me.log("PROCESS: and the output is "..minetest.serialize(recip.output), "error")
|
||||||
-- me.log("PROCESS: and the output is "..stack:get_name(), "error")
|
-- me.log("PROCESS: and the output is "..stack:get_name(), "error")
|
||||||
else
|
else
|
||||||
me.log("PROCESS: "..name.." was missing from recipe on a "..machine_name, "error")
|
me.log("PROCESS: "..name.." was missing from recipe on a "..machine_name, "error")
|
||||||
linv:set_stack("output", 1, ItemStack())
|
linv:set_stack("output", 1, ItemStack())
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return 0
|
return 0
|
||||||
@ -375,12 +375,12 @@ local function on_output_change(pos, linv, stack)
|
|||||||
if has_enough then
|
if has_enough then
|
||||||
local pos,ipos = next(net.autocrafters[name])
|
local pos,ipos = next(net.autocrafters[name])
|
||||||
if pos then
|
if pos then
|
||||||
local rinv = minetest.get_meta(pos):get_inventory()
|
local rinv = minetest.get_meta(pos):get_inventory()
|
||||||
stack = ItemStack(rinv:get_stack("output", 1))
|
stack = ItemStack(rinv:get_stack("output", 1))
|
||||||
linv:set_stack("output", 1, stack)
|
linv:set_stack("output", 1, stack)
|
||||||
else
|
else
|
||||||
-- me.log("pos in autocrafters was missing", "error")
|
-- me.log("pos in autocrafters was missing", "error")
|
||||||
linv:set_stack("output", 1, ItemStack())
|
linv:set_stack("output", 1, ItemStack())
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
linv:set_stack("output", 1, ItemStack())
|
linv:set_stack("output", 1, ItemStack())
|
||||||
@ -397,7 +397,7 @@ local function on_output_change(pos, linv, stack)
|
|||||||
-- full, no room to remove
|
-- full, no room to remove
|
||||||
has_enough = false
|
has_enough = false
|
||||||
if width_idx <= width then
|
if width_idx <= width then
|
||||||
item_idx = item_idx + 1
|
item_idx = item_idx + 1
|
||||||
end
|
end
|
||||||
elseif prev and prev:get_name() ~= "" and me.insert_item(prev, net, inv, "main"):get_count() > 0 then
|
elseif prev and prev:get_name() ~= "" and me.insert_item(prev, net, inv, "main"):get_count() > 0 then
|
||||||
net:set_storage_space(true)
|
net:set_storage_space(true)
|
||||||
@ -406,16 +406,16 @@ local function on_output_change(pos, linv, stack)
|
|||||||
-- Don't have to worry about this happening until minetest is fully multithreaded
|
-- Don't have to worry about this happening until minetest is fully multithreaded
|
||||||
has_enough = false
|
has_enough = false
|
||||||
if width_idx <= width then
|
if width_idx <= width then
|
||||||
item_idx = item_idx + 1
|
item_idx = item_idx + 1
|
||||||
end
|
end
|
||||||
elseif width_idx <= width then
|
elseif width_idx <= width then
|
||||||
net:set_storage_space(true)
|
net:set_storage_space(true)
|
||||||
if inv:contains_item("main", items[item_idx]) then
|
if inv:contains_item("main", items[item_idx]) then
|
||||||
me.remove_item(net, inv, "main", ItemStack(items[item_idx]))
|
me.remove_item(net, inv, "main", ItemStack(items[item_idx]))
|
||||||
linv:set_stack("recipe", i, items[item_idx])
|
linv:set_stack("recipe", i, items[item_idx])
|
||||||
else
|
else
|
||||||
has_enough = false
|
has_enough = false
|
||||||
linv:set_stack("recipe", i, ItemStack(""))
|
linv:set_stack("recipe", i, ItemStack(""))
|
||||||
end
|
end
|
||||||
item_idx = item_idx + 1
|
item_idx = item_idx + 1
|
||||||
else
|
else
|
||||||
@ -559,7 +559,7 @@ me.register_node("cterminal", {
|
|||||||
local inv = net:get_inventory()
|
local inv = net:get_inventory()
|
||||||
local leftovers = me.insert_item(stack, net, inv, "main")
|
local leftovers = me.insert_item(stack, net, inv, "main")
|
||||||
if leftovers:get_count() > 0 then
|
if leftovers:get_count() > 0 then
|
||||||
fixme()
|
fixme()
|
||||||
end
|
end
|
||||||
net:set_storage_space(true)
|
net:set_storage_space(true)
|
||||||
end
|
end
|
||||||
@ -577,21 +577,21 @@ me.register_node("cterminal", {
|
|||||||
local replace = true
|
local replace = true
|
||||||
-- This assumes that all inputs are only just 1 item, always true?
|
-- This assumes that all inputs are only just 1 item, always true?
|
||||||
for i = 1, 9 do
|
for i = 1, 9 do
|
||||||
local inp = linv:get_stack("recipe", i)
|
local inp = linv:get_stack("recipe", i)
|
||||||
if inp and inp:get_name() ~= "" then
|
if inp and inp:get_name() ~= "" then
|
||||||
local consume = ItemStack(inp:get_name())
|
local consume = ItemStack(inp:get_name())
|
||||||
replace = replace and (inp:get_count() > 1 or inv:contains_item("main", consume))
|
replace = replace and (inp:get_count() > 1 or inv:contains_item("main", consume))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for i = 1, 9 do
|
for i = 1, 9 do
|
||||||
local inp = linv:get_stack("recipe", i)
|
local inp = linv:get_stack("recipe", i)
|
||||||
if inp and inp:get_name() ~= "" then
|
if inp and inp:get_name() ~= "" then
|
||||||
if inp:get_count() == 1 then
|
if inp:get_count() == 1 then
|
||||||
if inv:contains_item("main", inp) then
|
if inv:contains_item("main", inp) then
|
||||||
local r = me.remove_item(net, inv, "main", inp)
|
local r = me.remove_item(net, inv, "main", inp)
|
||||||
if r:get_count() ~= 1 then
|
if r:get_count() ~= 1 then
|
||||||
linv:set_stack("recipe", i, ItemStack(""))
|
linv:set_stack("recipe", i, ItemStack(""))
|
||||||
replace = false
|
replace = false
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
linv:set_stack("recipe", i, ItemStack(""))
|
linv:set_stack("recipe", i, ItemStack(""))
|
||||||
@ -617,11 +617,11 @@ me.register_node("cterminal", {
|
|||||||
minetest.add_item(pos, leftovers)
|
minetest.add_item(pos, leftovers)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if replace then
|
if replace then
|
||||||
linv:set_stack("output", 1, craft.output.item)
|
linv:set_stack("output", 1, craft.output.item)
|
||||||
else
|
else
|
||||||
linv:set_list("output", {})
|
linv:set_list("output", {})
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
elseif listname == "recipe" then
|
elseif listname == "recipe" then
|
||||||
local linv = minetest.get_meta(pos):get_inventory()
|
local linv = minetest.get_meta(pos):get_inventory()
|
||||||
@ -729,50 +729,52 @@ me.register_node("cterminal", {
|
|||||||
me.log("CRAFT: got fields: "..dump(fields), "error")
|
me.log("CRAFT: got fields: "..dump(fields), "error")
|
||||||
inv_name = "main"
|
inv_name = "main"
|
||||||
if fields.crafts == "true" then
|
if fields.crafts == "true" then
|
||||||
crafts = true
|
crafts = true
|
||||||
meta:set_string("crafts", "true")
|
meta:set_string("crafts", "true")
|
||||||
inv_name = "crafts"
|
inv_name = "crafts"
|
||||||
local tab = {}
|
local tab = {}
|
||||||
if net then
|
if net then
|
||||||
if not net.process then
|
if not net.process then
|
||||||
net:reload_network()
|
net:reload_network()
|
||||||
end
|
end
|
||||||
for name,pos in pairs(net.autocrafters) do
|
for name,pos in pairs(net.autocrafters) do
|
||||||
tab[#tab + 1] = ItemStack(name)
|
tab[#tab + 1] = ItemStack(name)
|
||||||
end
|
end
|
||||||
tab[#tab + 1] = ItemStack("")
|
tab[#tab + 1] = ItemStack("")
|
||||||
for name,pos in pairs(net.process) do
|
for name,pos in pairs(net.process) do
|
||||||
tab[#tab + 1] = ItemStack(name)
|
tab[#tab + 1] = ItemStack(name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
own_inv:set_size(inv_name, #tab)
|
||||||
own_inv:set_list(inv_name, tab)
|
own_inv:set_list(inv_name, tab)
|
||||||
meta:set_string("inv_name", inv_name)
|
meta:set_string("inv_name", inv_name)
|
||||||
page_max = math.floor(own_inv:get_size(inv_name) / 32) + 1
|
page_max = math.floor(own_inv:get_size(inv_name) / 32) + 1
|
||||||
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.filter, crafts))
|
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.filter, crafts))
|
||||||
else
|
else
|
||||||
crafts = false
|
crafts = false
|
||||||
meta:set_string("crafts", "false")
|
meta:set_string("crafts", "false")
|
||||||
if fields.filter == "" then
|
if fields.filter == "" then
|
||||||
own_inv:set_size("crafts", 0)
|
own_inv:set_size("crafts", 0)
|
||||||
meta:set_string("inv_name", inv_name)
|
meta:set_string("inv_name", inv_name)
|
||||||
page_max = math.floor(ctrl_inv:get_size(inv_name) / 32) + 1
|
page_max = math.floor(ctrl_inv:get_size(inv_name) / 32) + 1
|
||||||
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.fields, crafts))
|
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.fields, crafts))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if fields.filter ~= "" then
|
if fields.filter ~= "" then
|
||||||
inv = own_inv
|
inv = own_inv
|
||||||
if inv_name == "main" then
|
if inv_name == "main" then
|
||||||
inv = ctrl_inv
|
inv = ctrl_inv
|
||||||
end
|
end
|
||||||
local tab = {}
|
local tab = {}
|
||||||
for i = 1, inv:get_size(inv_name) do
|
for i = 1, inv:get_size(inv_name) do
|
||||||
local match = inv:get_stack(inv_name, i):get_name():find(fields.filter)
|
local match = inv:get_stack(inv_name, i):get_name():find(fields.filter)
|
||||||
if match then
|
if match then
|
||||||
tab[#tab + 1] = inv:get_stack(inv_name, i)
|
tab[#tab + 1] = inv:get_stack(inv_name, i)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
inv_name = "search"
|
inv_name = "search"
|
||||||
own_inv:set_list(inv_name, tab)
|
own_inv:set_size(inv_name, #tab)
|
||||||
|
own_inv:set_list(inv_name, tab)
|
||||||
meta:set_string("inv_name", inv_name)
|
meta:set_string("inv_name", inv_name)
|
||||||
page_max = math.floor(own_inv:get_size(inv_name) / 32) + 1
|
page_max = math.floor(own_inv:get_size(inv_name) / 32) + 1
|
||||||
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.filter, crafts))
|
meta:set_string("formspec", chest_formspec(pos, 1, inv_name, page_max, fields.filter, crafts))
|
||||||
@ -784,7 +786,7 @@ me.register_node("cterminal", {
|
|||||||
inv_name = "main"
|
inv_name = "main"
|
||||||
inv = ctrl_inv
|
inv = ctrl_inv
|
||||||
if crafts then
|
if crafts then
|
||||||
inv_name = "crafts"
|
inv_name = "crafts"
|
||||||
inv = own_inv
|
inv = own_inv
|
||||||
end
|
end
|
||||||
if fields.filter == "" then
|
if fields.filter == "" then
|
||||||
|
Loading…
Reference in New Issue
Block a user