diff --git a/compacting-storage.lua b/compacting-storage.lua index d138d12..07d31da 100644 --- a/compacting-storage.lua +++ b/compacting-storage.lua @@ -10,6 +10,8 @@ local MAIN_TICKER = "" local REQUEST_TICKER = "" local STORAGE_ADDRESS = "" local CRAFTING_REQUESTER = "" +local COMPACTING_ADDR = "" +local UNPACKING_ADDR = "" local SLEEP_TIME = 30 local NUGGET_RATIO = 63 -- amount of nuggets per craft local BLOCK_RATIO = 7 -- amount of blocks per craft @@ -30,21 +32,33 @@ local MIN_NUM = (4 * STACKS * NUGGETS) + (4 * STACKS * INGOTS) local MAX_NUM = (8 * STACKS * NUGGETS) + (8 * STACKS * INGOTS) -- basic actions -function craft (item_type, conversion_type) - -- TODO rework +function craft (requester, item_type, conversion_type) + -- conversion_type key: 1, nuggets to ingots; 2, ingots to blocks; + -- 3, blocks to ingots; 4, ingots to nuggets + -- TODO find name + local compacting = conversion_type <= 2 + local count, address + if compacting then + count = NUGGET_RATIO + address = COMPACTING_ADDR + else + count = BLOCK_RATIO end + address = UNPACKING_ADDR + end + requester.setRequest({ name, count }) end -function craft_multiple (item_type, conversion_type, count) +function craft_multiple (requester, item_type, conversion_type, count) if count < 1 then return else - craft(item_type, conversion_type) + craft(requester, item_type, conversion_type) os.sleep(1) - return craft_multiple(item_type, conversion_type, count - 1) + return craft_multiple(requester, item_type, conversion_type, count - 1) end end -function execute_crafts (item_type, crafts) +function execute_crafts (requester, item_type, crafts) local num_crafts = crafts.nuggets if num_crafts > 0 then print(("Crafting %s nuggets"):format(item_type)) @@ -56,7 +70,7 @@ function execute_crafts (item_type, crafts) num_crafts = crafts.blocks if num_crafts > 0 then print(("Crafting %s blocks"):format(item_type)) - craft_multiple(item_type, 2, num_crafts) + craft_multiple(requester, item_type, 2, num_crafts) elseif num_crafts < 0 then print(("Crafting %s ingots"):format(item_type)) craft_multiple(item_type, 3, -num_crafts) @@ -178,7 +192,7 @@ while true do local diff = get_diff(desired_dist, current_dist) diff = filter_clamp(diff, current_dist) local crafts = diff_to_crafts(diff) - execute_crafts(item_type, crafts) + execute_crafts(craft_requester, item_type, crafts) elseif num > MAX_NUM then -- keep requesting until above MAX_NUM requesting[item_type] = nil