diff --git a/data/products.lua b/data/products.lua index b8c82f0..098c20e 100644 --- a/data/products.lua +++ b/data/products.lua @@ -23,4 +23,16 @@ id = "minecraft:paper", metaname = "ppa", }, + { + displayName = "Fishing Rod", + price = 2, + id = "minecraft:fishing_rod", + metaname = "fish" + }, + { + displayName = "Brown Bed", + price = 1, + id = "minecraft:brown_bed", + metaname = "bb" + } } diff --git a/src/backend.lua b/src/backend.lua index 8bae493..1a3471f 100644 --- a/src/backend.lua +++ b/src/backend.lua @@ -55,7 +55,7 @@ logger:info("Configuration loaded. Indexing chests") local storage = ctx.storage -storage.refreshStorage() +storage.refreshStorage(true) logger:info("Chests indexed.") local ws = kristly.websocket(config.pkey) @@ -141,8 +141,10 @@ logger:info("Dispensing " .. amount .. "x " .. product.id .. " (s).") - local turns = math.ceil(amount / 64 / 16) - local lastTurn = amount - ((turns - 1) * 64 * 16) + local stackSize = storage.getItem(product.id) + print(textutils.serialise(stackSize)) + local turns = math.ceil(amount / stackSize / 16) + local lastTurn = amount - ((turns - 1) * stackSize * 16) logger:debug("Taking " .. turns .. " turn(s), last one has " .. lastTurn) @@ -154,7 +156,7 @@ storage.pushItems(config.self, product.id, lastTurn, nil, nil, { optimal = false }) else logger:debug("Not last turn") - storage.pushItems(config.self, product.id, 64 * 16, nil, nil, { optimal = false }) + storage.pushItems(config.self, product.id, stackSize * 16, nil, nil, { optimal = false }) end for i = 1, 16 do diff --git a/src/frontend.lua b/src/frontend.lua index 0065b88..72e35b3 100644 --- a/src/frontend.lua +++ b/src/frontend.lua @@ -2,7 +2,7 @@ local basalt = require("libs/basalt") local storage = ctx.storage -storage.refreshStorage() +storage.refreshStorage(true) local function searchObject(base, id) local obj = base:getObject(id) diff --git a/src/utils.lua b/src/utils.lua index f73f69e..38fbc32 100644 --- a/src/utils.lua +++ b/src/utils.lua @@ -37,4 +37,19 @@ return false end +---Returns a set of keys for a table +---@param table table The table to inspect +---@return table keyset A table containing keys for the original table +function utils.keyset(table) + local keyset = {} + local n = 0 + + for k, v in pairs(table) do + n = n + 1 + keyset[n] = k + end + + return keyset +end + return utils