Increase mass storage cap; add mass storage upgrades

This commit is contained in:
Zenon Seth 2023-11-11 11:55:33 +00:00
parent 0d58cdfba4
commit 92914ba66b
8 changed files with 87 additions and 8 deletions

View File

@ -1,6 +1,4 @@
Missing Features:
- Network Importer need to be able to target Passive Suppliers Chests
- Passive Supplier Chests need to have configuration to accept from network
- Storage Access Point
- Crafting recipes

View File

@ -232,6 +232,13 @@ local function allow_mass_storage_inv_take(pos, listname, index, stack, player)
logistica.update_cache_at_pos(pos, LOG_CACHE_MASS_STORAGE)
return 0
end
if listname == "upgrade" then
if logistica.can_remove_mass_storage_upgrade(pos, stack:get_name()) then
return 1
else
return 0
end
end
return stack:get_count()
end
@ -254,6 +261,12 @@ local function allow_mass_storage_inv_put(pos, listname, index, stack, player)
logistica.update_cache_at_pos(pos, LOG_CACHE_MASS_STORAGE)
return 0
end
if listname == "upgrade" then
local inv = minetest.get_meta(pos):get_inventory()
if not logistica.is_valid_storage_upgrade(stack:get_name()) then return 0 end
if inv:get_stack(listname, index):is_empty() then return 1 end
return 0
end
return stack:get_count()
end
@ -278,11 +291,17 @@ local function on_mass_storage_inv_put(pos, listname, index, stack, player)
end
inv:set_stack(listname, index, fullstack)
end
elseif listname == "upgrade" then
local inv = minetest.get_meta(pos):get_inventory()
logistica.on_mass_storage_upgrade_change(pos, inv:get_stack(listname, index):get_name(), true)
end
end
local function on_mass_storage_inv_take(pos, listname, index, stack, player)
if minetest.is_protected(pos, player) then return 0 end
if listname == "upgrade" then
logistica.on_mass_storage_upgrade_change(pos, stack:get_name(), false)
end
end
local function on_mass_storage_punch(pos, node, puncher, pointed_thing)
@ -372,4 +391,4 @@ function logistica.register_mass_storage(simpleName, numSlots, numItemsPerSlot,
end
logistica.register_mass_storage("Basic", 8, 512, 2)
logistica.register_mass_storage("Basic", 8, 1024, 4)

View File

@ -7,6 +7,7 @@ logistica.MODPATH = minetest.get_modpath(logistica.MODNAME)
dofile(logistica.MODPATH.."/util/util.lua")
dofile(logistica.MODPATH.."/entity/entity.lua")
dofile(logistica.MODPATH.."/logic/logic.lua")
dofile(logistica.MODPATH.."/item/item.lua")
dofile(logistica.MODPATH.."/tools/tools.lua")
-- api should be below the other files except the registrations

4
item/item.lua Normal file
View File

@ -0,0 +1,4 @@
local path = logistica.MODPATH .. "/item"
logistica.craftitem = {}
dofile(path .. "/storage_upgrade.lua")

30
item/storage_upgrade.lua Normal file
View File

@ -0,0 +1,30 @@
local S = logistica.TRANSLATOR
logistica.craftitem.storage_upgrade = {}
local items = logistica.craftitem.storage_upgrade
items["logistica:storage_upgrade_1"] = {
description = S("Silverin Storage Upgrade\nAdds 512 Mass Storage Slot Capacity"),
storage_upgrade = 512,
inventory_image = "logistica_storage_upgrade_1.png",
stack_max = 99,
}
items["logistica:storage_upgrade_2"]= {
description = S("Diamond Storage Upgrade\nAdds 1024 Mass Storage Slot Capacity"),
storage_upgrade = 1024,
inventory_image = "logistica_storage_upgrade_2.png",
stack_max = 99,
}
--------------------------------
-- registration
--------------------------------
for name, info in pairs(items) do
minetest.register_craftitem(name, {
description = info.description,
inventory_image = info.inventory_image,
stack_max = info.stack_max,
})
end

View File

@ -1,12 +1,12 @@
local META_IMG_PIC = "logimgpick"
local META_RES_VAL = "logresval"
local META_UPGRADE_ADD = "logstorupgr"
local VALID_RESERVE_VALUES = {}
for i = 0,4096,128 do table.insert(VALID_RESERVE_VALUES, i) end
for i = 0,5120,128 do VALID_RESERVE_VALUES[i/128 + 1] = i end
local BASE_TRANSFER_RATE = 10
local function mass_storage_room_for_item(pos, meta, stack)
local stackName = stack:get_name()
local targetStackSize = stack:get_count()
local maxNum = logistica.get_mass_storage_max_size(pos)
local filterList = meta:get_inventory():get_list("filter")
local storageList = meta:get_inventory():get_list("storage")
@ -32,8 +32,9 @@ function logistica.get_mass_storage_max_size(pos)
if not node then return 0 end
local def = minetest.registered_nodes[node.name]
if def and def.logistica and def.logistica.maxItems then
-- TODO: account for upgrades
return def.logistica.maxItems
local meta = minetest.get_meta(pos)
local storageUpgrade = meta:get_int(META_UPGRADE_ADD)
return def.logistica.maxItems + storageUpgrade
end
return 0
end
@ -233,4 +234,30 @@ function logistica.get_mass_storage_imgname_or_first_item(meta)
if not v:is_empty() then return "\n(Has: "..v:get_description()..")" end
end
return "\n(Empty)"
end
end
function logistica.is_valid_storage_upgrade(stackName)
return logistica.craftitem.storage_upgrade[stackName] ~= nil
end
function logistica.on_mass_storage_upgrade_change(pos, upgradeName, wasAdded)
local upgradeDef = logistica.craftitem.storage_upgrade[upgradeName]
if not upgradeDef or not upgradeDef.storage_upgrade then return true end
local meta = minetest.get_meta(pos)
local storageUpgrade = meta:get_int(META_UPGRADE_ADD)
if wasAdded then storageUpgrade = storageUpgrade + upgradeDef.storage_upgrade
else storageUpgrade = storageUpgrade - upgradeDef.storage_upgrade end
meta:set_int(META_UPGRADE_ADD, storageUpgrade)
end
function logistica.can_remove_mass_storage_upgrade(pos, upgradeName)
local upgradeDef = logistica.craftitem.storage_upgrade[upgradeName]
if not upgradeDef or not upgradeDef.storage_upgrade then return true end
local inv = minetest.get_meta(pos):get_inventory()
local maxStored = 0
for _, st in ipairs(inv:get_list("storage") or {}) do
if st:get_count() > maxStored then maxStored = st:get_count() end
end
local currMax = logistica.get_mass_storage_max_size(pos)
return (currMax - upgradeDef.storage_upgrade) >= maxStored
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.1 KiB