ta4_chest bugfix
This commit is contained in:
parent
09fbe588d1
commit
6c0737be1b
@ -96,7 +96,7 @@ local function sort_in(inv, nvm, stack)
|
|||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
local function max_stack_size(item_name)
|
local function max_stacksize(item_name)
|
||||||
local ndef = minetest.registered_nodes[item_name] or minetest.registered_items[item_name] or minetest.registered_craftitems[item_name]
|
local ndef = minetest.registered_nodes[item_name] or minetest.registered_items[item_name] or minetest.registered_craftitems[item_name]
|
||||||
if ndef then
|
if ndef then
|
||||||
return ndef.stack_max
|
return ndef.stack_max
|
||||||
@ -104,6 +104,13 @@ local function max_stack_size(item_name)
|
|||||||
return 0
|
return 0
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function get_stacksize(pos)
|
||||||
|
local size = M(pos):get_int("stacksize")
|
||||||
|
if size == 0 then
|
||||||
|
return STACK_SIZE
|
||||||
|
end
|
||||||
|
return size
|
||||||
|
end
|
||||||
|
|
||||||
local function get_item(inv, nvm, item_name, count)
|
local function get_item(inv, nvm, item_name, count)
|
||||||
local stack = {count = 0}
|
local stack = {count = 0}
|
||||||
@ -119,7 +126,7 @@ local function get_item(inv, nvm, item_name, count)
|
|||||||
end
|
end
|
||||||
for _,item in ipairs(nvm.inventory or {}) do
|
for _,item in ipairs(nvm.inventory or {}) do
|
||||||
if (item_name == nil and stack.name == nil) or item.name == item_name then
|
if (item_name == nil and stack.name == nil) or item.name == item_name then
|
||||||
local num = math.min(item.count, count - stack.count, max_stack_size(item.name))
|
local num = math.min(item.count, count - stack.count, max_stacksize(item.name))
|
||||||
item.count = item.count - num
|
item.count = item.count - num
|
||||||
stack.count = stack.count + num
|
stack.count = stack.count + num
|
||||||
if item.name ~= "" then
|
if item.name ~= "" then
|
||||||
@ -163,8 +170,7 @@ end
|
|||||||
local function formspec(pos)
|
local function formspec(pos)
|
||||||
local nvm = techage.get_nvm(pos)
|
local nvm = techage.get_nvm(pos)
|
||||||
local inv = M(pos):get_inventory()
|
local inv = M(pos):get_inventory()
|
||||||
local size = M(pos):get_int("stacksize")
|
local size = get_stacksize(pos)
|
||||||
if size == 0 then size = STACK_SIZE end
|
|
||||||
return "size[8,7.6]"..
|
return "size[8,7.6]"..
|
||||||
default.gui_bg..
|
default.gui_bg..
|
||||||
default.gui_bg_img..
|
default.gui_bg_img..
|
||||||
@ -273,7 +279,7 @@ local function move_from_nvm_to_inv(pos, idx)
|
|||||||
local nvm_stack = get_stack(nvm, idx)
|
local nvm_stack = get_stack(nvm, idx)
|
||||||
|
|
||||||
if nvm_stack.count > 0 and inv_stack:get_count() == 0 then
|
if nvm_stack.count > 0 and inv_stack:get_count() == 0 then
|
||||||
local count = math.min(nvm_stack.count, max_stack_size(nvm_stack.name))
|
local count = math.min(nvm_stack.count, max_stacksize(nvm_stack.name))
|
||||||
nvm_stack.count = nvm_stack.count - count
|
nvm_stack.count = nvm_stack.count - count
|
||||||
inv:set_stack("main", idx, {name = nvm_stack.name, count = count})
|
inv:set_stack("main", idx, {name = nvm_stack.name, count = count})
|
||||||
if nvm_stack.count == 0 then
|
if nvm_stack.count == 0 then
|
||||||
@ -291,7 +297,7 @@ local function move_from_inv_to_nvm(pos, idx)
|
|||||||
|
|
||||||
if inv_stack:get_count() > 0 then
|
if inv_stack:get_count() > 0 then
|
||||||
if nvm_stack.count == 0 or nvm_stack.name == inv_stack:get_name() then
|
if nvm_stack.count == 0 or nvm_stack.name == inv_stack:get_name() then
|
||||||
local count = math.min(inv_stack:get_count(), STACK_SIZE - nvm_stack.count)
|
local count = math.min(inv_stack:get_count(), get_stacksize(pos) - nvm_stack.count)
|
||||||
nvm_stack.count = nvm_stack.count + count
|
nvm_stack.count = nvm_stack.count + count
|
||||||
nvm_stack.name = inv_stack:get_name()
|
nvm_stack.name = inv_stack:get_name()
|
||||||
inv_stack:set_count(inv_stack:get_count() - count)
|
inv_stack:set_count(inv_stack:get_count() - count)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user