feat: start craft function

This commit is contained in:
Emerson Rosen-Jones 2026-01-17 16:32:14 -05:00
parent 47c3db46f9
commit fa433f3c62

View file

@ -10,6 +10,8 @@ local MAIN_TICKER = ""
local REQUEST_TICKER = "" local REQUEST_TICKER = ""
local STORAGE_ADDRESS = "" local STORAGE_ADDRESS = ""
local CRAFTING_REQUESTER = "" local CRAFTING_REQUESTER = ""
local COMPACTING_ADDR = ""
local UNPACKING_ADDR = ""
local SLEEP_TIME = 30 local SLEEP_TIME = 30
local NUGGET_RATIO = 63 -- amount of nuggets per craft local NUGGET_RATIO = 63 -- amount of nuggets per craft
local BLOCK_RATIO = 7 -- amount of blocks 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) local MAX_NUM = (8 * STACKS * NUGGETS) + (8 * STACKS * INGOTS)
-- basic actions -- basic actions
function craft (item_type, conversion_type) function craft (requester, item_type, conversion_type)
-- TODO rework -- 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 end
function craft_multiple (item_type, conversion_type, count) function craft_multiple (requester, item_type, conversion_type, count)
if count < 1 then if count < 1 then
return return
else else
craft(item_type, conversion_type) craft(requester, item_type, conversion_type)
os.sleep(1) os.sleep(1)
return craft_multiple(item_type, conversion_type, count - 1) return craft_multiple(requester, item_type, conversion_type, count - 1)
end end
end end
function execute_crafts (item_type, crafts) function execute_crafts (requester, item_type, crafts)
local num_crafts = crafts.nuggets local num_crafts = crafts.nuggets
if num_crafts > 0 then if num_crafts > 0 then
print(("Crafting %s nuggets"):format(item_type)) print(("Crafting %s nuggets"):format(item_type))
@ -56,7 +70,7 @@ function execute_crafts (item_type, crafts)
num_crafts = crafts.blocks num_crafts = crafts.blocks
if num_crafts > 0 then if num_crafts > 0 then
print(("Crafting %s blocks"):format(item_type)) 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 elseif num_crafts < 0 then
print(("Crafting %s ingots"):format(item_type)) print(("Crafting %s ingots"):format(item_type))
craft_multiple(item_type, 3, -num_crafts) craft_multiple(item_type, 3, -num_crafts)
@ -178,7 +192,7 @@ while true do
local diff = get_diff(desired_dist, current_dist) local diff = get_diff(desired_dist, current_dist)
diff = filter_clamp(diff, current_dist) diff = filter_clamp(diff, current_dist)
local crafts = diff_to_crafts(diff) local crafts = diff_to_crafts(diff)
execute_crafts(item_type, crafts) execute_crafts(craft_requester, item_type, crafts)
elseif num > MAX_NUM then elseif num > MAX_NUM then
-- keep requesting until above MAX_NUM -- keep requesting until above MAX_NUM
requesting[item_type] = nil requesting[item_type] = nil