compacting-storage.lua: more bugfixes and logic work

This commit is contained in:
Emerson Rosen-Jones 2025-11-17 20:29:26 -05:00
parent 8981badcf9
commit add0ad1400

View file

@ -108,7 +108,7 @@ function set_production (item_type, produce)
)
local periph = string.format("redstone_relay_%d", relay_num)
-- ON is disable production
if produce then print(("Producing %s"):format(item_type))
if produce then print(("Producing %s"):format(item_type)) end
peripheral.call(periph, "setOutput", face, not produce)
end
@ -163,20 +163,20 @@ end
function filter_clamp (diff, current_dist)
-- reduce diff numbers to what can be crafted using current resources
local new_diff = { nuggets = 0, ingots = 0, blocks = 0 }
if diff.blocks > 0 then
new_diff.blocks = math.min(
diff.blocks,
diff.blocks = math.min(
diff.blocks - (diff.blocks % BLOCK_RATIO),
math.floor(current_dist.ingots / 9)
)
end
if diff.nuggets > 0 then
new_diff.nuggets = math.min(
diff.nuggets,
diff.nuggets = math.min(
diff.nuggets - (diff.nuggets % NUGGET_RATIO),
current_dist.ingots * 9
)
end
new_diff.ingots = (new_diff.nuggets / 9) + (new_diff.blocks * 9)
diff.ingots = (-diff.nuggets / 9) + (-diff.blocks * 9)
return diff
end
function diff_to_crafts (diff)