misc: demo old code

This commit is contained in:
Emerson Rosen-Jones 2026-01-03 20:23:31 -05:00
parent 55635e4b64
commit 25eae158b1

View file

@ -31,51 +31,9 @@ local BLOCKS = 81
local MIN_NUM = (4 * STACKS * NUGGETS) + (4 * STACKS * INGOTS) 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)
-- TODO map targets to specific relays and faces
-- Key - 1: nuggets_to_ingots, 2: ingots_to_blocks, 3: blocks_to_ingots,
-- 4: ingots_to_nuggets, 5: enable/disable production
local target = {}
target.iron = {}
target.iron[1] = "0:front"
target.iron[2] = "0:top"
target.iron[3] = "0:back"
target.iron[4] = "16:front"
target.iron[5] = "17:back"
target.copper = {}
target.copper[1] = "1:front"
target.copper[2] = "1:top"
target.copper[3] = "1:back"
target.copper[4] = "16:top"
target.copper[5] = "18:front"
target.zinc = {}
target.zinc[1] = "2:front"
target.zinc[2] = "2:top"
target.zinc[3] = "2:back"
target.zinc[4] = "16:back"
target.zinc[5] = "18:top"
target.gold = {}
target.gold[1] = "3:front"
target.gold[2] = "3:top"
target.gold[3] = "3:back"
target.gold[4] = "17:front"
target.gold[5] = "18:back"
target.electrum = {}
target.electrum[1] = "4:front"
target.electrum[2] = "4:top"
target.electrum[3] = "4:back"
target.electrum[4] = "17:top"
-- basic actions -- basic actions
function craft (item_type, conversion_type) function craft (item_type, conversion_type)
-- TODO double check this -- TODO rework
local relay_num, face = string.match(
target[item_type][conversion_type],
"(%d+):(%l+)"
)
local periph = string.format("redstone_relay_%d", relay_num)
peripheral.call(periph, "setOutput", face, true)
os.sleep(0.1)
peripheral.call(periph, "setOutput", face, false)
end end
function craft_multiple (item_type, conversion_type, count) function craft_multiple (item_type, conversion_type, count)
@ -107,17 +65,8 @@ function execute_crafts (item_type, crafts)
end end
end end
function set_production (item_type, produce) function request_more (item_type, amt)
local target_string = target[item_type][5] -- TODO
if target_string == nil then return end
local relay_num, face = string.match(
target_string,
"(%d+):(%l+)"
)
local periph = string.format("redstone_relay_%d", relay_num)
-- ON is disable production
if produce then print(("Producing %s"):format(item_type)) end
peripheral.call(periph, "setOutput", face, not produce)
end end
-- logic -- logic
@ -136,6 +85,7 @@ function dist_to_num (dist)
end end
function get_dist (item_type, items) function get_dist (item_type, items)
-- TODO redo, incorporate sum_items. DRY!
local dist = { nuggets = 0, ingots = 0, blocks = 0 } local dist = { nuggets = 0, ingots = 0, blocks = 0 }
for item, count in pairs(items) do for item, count in pairs(items) do
local type, form = item:match":(%l-)_(%l*)" local type, form = item:match":(%l-)_(%l*)"
@ -188,7 +138,6 @@ function filter_clamp (diff, current_dist)
end end
function diff_to_crafts (diff) function diff_to_crafts (diff)
-- TODO double-check this one
-- go from one end e.g. nuggets to the other e.g. blocks, removing -- go from one end e.g. nuggets to the other e.g. blocks, removing
-- from the diff to create crafts until the diff is empty -- from the diff to create crafts until the diff is empty
local crafts = {} local crafts = {}
@ -215,7 +164,6 @@ while true do
for _, item_type in ipairs(ITEM_TYPES) do for _, item_type in ipairs(ITEM_TYPES) do
local current_dist = get_dist(item_type, items) local current_dist = get_dist(item_type, items)
local num = dist_to_num(current_dist) local num = dist_to_num(current_dist)
if num > MAX_NUM then set_production(item_type, false) end
if num > MIN_NUM then if num > MIN_NUM then
local desired_dist = decide_dist(num) local desired_dist = decide_dist(num)
local diff = get_diff(desired_dist, current_dist) local diff = get_diff(desired_dist, current_dist)
@ -223,7 +171,9 @@ while true do
local crafts = diff_to_crafts(diff) local crafts = diff_to_crafts(diff)
execute_crafts(item_type, crafts) execute_crafts(item_type, crafts)
else else
set_production(item_type, true) -- TODO
-- TODO potentially keep requesting until above MAX_NUM
request_more(item_type, amt)
end end
end end