ME Chest: Fix drive item limit bug
Previously the math was incorrect, allowing a single 8k drive to store over 300,000 items. This also cleans up the storage area a bit, moving the API related to storage drives from the main API.lua to storage/api.lua.
This commit is contained in:
parent
0d917954eb
commit
0a9d8880a9
35
api.lua
35
api.lua
@ -57,38 +57,3 @@ function microexpansion.register_item(itemstring, def)
|
|||||||
register_recipe(BASENAME..":"..itemstring, def.recipe)
|
register_recipe(BASENAME..":"..itemstring, def.recipe)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
-- [function] register cell
|
|
||||||
function microexpansion.register_cell(itemstring, def)
|
|
||||||
if not def.inventory_image then
|
|
||||||
def.inventory_image = itemstring
|
|
||||||
end
|
|
||||||
|
|
||||||
-- register craftitem
|
|
||||||
minetest.register_craftitem(BASENAME..":"..itemstring, {
|
|
||||||
description = def.description,
|
|
||||||
inventory_image = BASENAME.."_"..def.inventory_image..".png",
|
|
||||||
groups = {microexpansion_cell = 1},
|
|
||||||
microexpansion = {
|
|
||||||
drive = {
|
|
||||||
capacity = def.capacity or 5000,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
-- if recipe, register recipe
|
|
||||||
if def.recipe then
|
|
||||||
-- if recipe, register recipe
|
|
||||||
if def.recipe then
|
|
||||||
register_recipe(BASENAME..":"..itemstring, def.recipe)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- [function] Get cell size
|
|
||||||
function microexpansion.get_cell_size(name)
|
|
||||||
local item = minetest.registered_craftitems[name]
|
|
||||||
if item then
|
|
||||||
return item.microexpansion.drive.capacity
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
48
modules/storage/api.lua
Normal file
48
modules/storage/api.lua
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
-- storage/api.lua
|
||||||
|
|
||||||
|
local BASENAME = "microexpansion"
|
||||||
|
|
||||||
|
-- [function] register cell
|
||||||
|
function microexpansion.register_cell(itemstring, def)
|
||||||
|
if not def.inventory_image then
|
||||||
|
def.inventory_image = itemstring
|
||||||
|
end
|
||||||
|
|
||||||
|
-- register craftitem
|
||||||
|
minetest.register_craftitem(BASENAME..":"..itemstring, {
|
||||||
|
description = def.description,
|
||||||
|
inventory_image = BASENAME.."_"..def.inventory_image..".png",
|
||||||
|
groups = {microexpansion_cell = 1},
|
||||||
|
microexpansion = {
|
||||||
|
drive = {
|
||||||
|
capacity = def.capacity or 5000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- if recipe, register recipe
|
||||||
|
if def.recipe then
|
||||||
|
-- if recipe, register recipe
|
||||||
|
if def.recipe then
|
||||||
|
register_recipe(BASENAME..":"..itemstring, def.recipe)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [function] Get cell size
|
||||||
|
function microexpansion.get_cell_size(name)
|
||||||
|
local item = minetest.registered_craftitems[name]
|
||||||
|
if item then
|
||||||
|
return item.microexpansion.drive.capacity
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [function] Calculate max stacks
|
||||||
|
function microexpansion.int_to_stacks(int)
|
||||||
|
return math.floor(int / 99)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- [function] Calculate number of pages
|
||||||
|
function microexpansion.int_to_pagenum(int)
|
||||||
|
return math.floor(microexpansion.int_to_stacks(int) / 32)
|
||||||
|
end
|
@ -2,6 +2,9 @@
|
|||||||
|
|
||||||
local module_path = microexpansion.get_module_path("storage")
|
local module_path = microexpansion.get_module_path("storage")
|
||||||
|
|
||||||
|
-- Load API
|
||||||
|
dofile(module_path.."/api.lua")
|
||||||
|
|
||||||
-- Load storage devices
|
-- Load storage devices
|
||||||
dofile(module_path.."/storage.lua")
|
dofile(module_path.."/storage.lua")
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
-- microexpansion/machines.lua
|
-- microexpansion/machines.lua
|
||||||
|
|
||||||
|
local me = microexpansion
|
||||||
|
|
||||||
-- [me chest] Get formspec
|
-- [me chest] Get formspec
|
||||||
local function chest_formspec(start_id, listname, page_max, query)
|
local function chest_formspec(start_id, listname, page_max, query)
|
||||||
local list
|
local list
|
||||||
@ -14,23 +16,27 @@ local function chest_formspec(start_id, listname, page_max, query)
|
|||||||
page_number = "label[6.05,4.5;" .. math.floor((start_id / 32)) + 1 ..
|
page_number = "label[6.05,4.5;" .. math.floor((start_id / 32)) + 1 ..
|
||||||
"/" .. page_max .."]"
|
"/" .. page_max .."]"
|
||||||
end
|
end
|
||||||
return "size[9,10]" ..
|
return [[
|
||||||
|
size[9,10]
|
||||||
|
]]..
|
||||||
microexpansion.gui_bg ..
|
microexpansion.gui_bg ..
|
||||||
microexpansion.gui_slots ..
|
microexpansion.gui_slots ..
|
||||||
list ..
|
list ..
|
||||||
"list[current_name;cells;8,1.8;1,1;]" ..
|
[[
|
||||||
"list[current_player;main;0,5.5;8,1;]" ..
|
list[current_name;cells;8,1.8;1,1;]
|
||||||
"list[current_player;main;0,6.73;8,3;8]" ..
|
list[current_player;main;0,5.5;8,1;]
|
||||||
"button[5.4,4.35;0.8,0.9;prev;<]" ..
|
list[current_player;main;0,6.73;8,3;8]
|
||||||
"button[7.25,4.35;0.8,0.9;next;>]" ..
|
button[5.4,4.35;0.8,0.9;prev;<]
|
||||||
"field[0.3,4.6;2.2,1;filter;;" .. query .. "]" ..
|
button[7.25,4.35;0.8,0.9;next;>]
|
||||||
"button[2.1,4.5;0.8,0.5;search;?]" ..
|
field[0.3,4.6;2.2,1;filter;;]]..query..[[]
|
||||||
"button[2.75,4.5;0.8,0.5;clear;X]" ..
|
button[2.1,4.5;0.8,0.5;search;?]
|
||||||
"tooltip[search;Search]" ..
|
button[2.75,4.5;0.8,0.5;clear;X]
|
||||||
"tooltip[clear;Reset]" ..
|
tooltip[search;Search]
|
||||||
"listring[current_name;main]" ..
|
tooltip[clear;Reset]
|
||||||
"listring[current_player;main]" ..
|
listring[current_name;main]
|
||||||
"field_close_on_enter[filter;false]" ..
|
listring[current_player;main]
|
||||||
|
field_close_on_enter[filter;false]
|
||||||
|
]]..
|
||||||
page_number
|
page_number
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -85,9 +91,9 @@ minetest.register_node("microexpansion:chest", {
|
|||||||
local meta = minetest.get_meta(pos)
|
local meta = minetest.get_meta(pos)
|
||||||
local inv = meta:get_inventory()
|
local inv = meta:get_inventory()
|
||||||
local items = minetest.deserialize(stack:get_meta():get_string("items"))
|
local items = minetest.deserialize(stack:get_meta():get_string("items"))
|
||||||
local size = microexpansion.get_cell_size(stack:get_name())
|
local size = me.get_cell_size(stack:get_name())
|
||||||
local page_max = math.floor(size / 32) + 1
|
local page_max = me.int_to_pagenum(size) + 1
|
||||||
inv:set_size("main", size)
|
inv:set_size("main", me.int_to_stacks(size))
|
||||||
if items then
|
if items then
|
||||||
inv:set_list("main", items)
|
inv:set_list("main", items)
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user