diff --git a/ROADMAP.md b/ROADMAP.md index 1e400fd..782be47 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -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 diff --git a/api/mass_storage.lua b/api/mass_storage.lua index adfb9f0..7005cc8 100644 --- a/api/mass_storage.lua +++ b/api/mass_storage.lua @@ -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) diff --git a/init.lua b/init.lua index 3f3a6e1..9f73f00 100644 --- a/init.lua +++ b/init.lua @@ -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 diff --git a/item/item.lua b/item/item.lua new file mode 100644 index 0000000..72242cb --- /dev/null +++ b/item/item.lua @@ -0,0 +1,4 @@ +local path = logistica.MODPATH .. "/item" +logistica.craftitem = {} + +dofile(path .. "/storage_upgrade.lua") diff --git a/item/storage_upgrade.lua b/item/storage_upgrade.lua new file mode 100644 index 0000000..0fd6b08 --- /dev/null +++ b/item/storage_upgrade.lua @@ -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 diff --git a/logic/mass_storage.lua b/logic/mass_storage.lua index e934e23..fd346d0 100644 --- a/logic/mass_storage.lua +++ b/logic/mass_storage.lua @@ -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 \ No newline at end of file +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 diff --git a/textures/logistica_storage_upgrade_1.png b/textures/logistica_storage_upgrade_1.png new file mode 100644 index 0000000..956456b Binary files /dev/null and b/textures/logistica_storage_upgrade_1.png differ diff --git a/textures/logistica_storage_upgrade_2.png b/textures/logistica_storage_upgrade_2.png new file mode 100644 index 0000000..890505a Binary files /dev/null and b/textures/logistica_storage_upgrade_2.png differ