compacting-storage.lua: more bugfixes
This commit is contained in:
parent
add0ad1400
commit
22c744ec46
1 changed files with 20 additions and 22 deletions
|
|
@ -58,8 +58,9 @@ target.electrum[4] = "17:top"
|
|||
-- basic actions
|
||||
function craft (item_type, conversion_type)
|
||||
-- TODO double check this
|
||||
local relay_num, face = string.match(target[item_type][conversion_type],
|
||||
"(d+):(%l+)"
|
||||
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)
|
||||
|
|
@ -78,24 +79,21 @@ function craft_multiple (item_type, conversion_type, count)
|
|||
end
|
||||
|
||||
function execute_crafts (item_type, crafts)
|
||||
for type, num_crafts in pairs(crafts) do
|
||||
if type == "nugget" then
|
||||
if num_crafts > 0 then
|
||||
local form = "nuggets"
|
||||
if crafts[form] > 0 then
|
||||
print(("Crafting %s nuggets"):format(item_type))
|
||||
craft_multiple(item_type, 4, num_crafts)
|
||||
elseif num_crafts < 0 then
|
||||
elseif crafts[form] < 0 then
|
||||
print(("Crafting %s ingots"):format(item_type))
|
||||
craft_multiple(item_type, 1, num_crafts)
|
||||
craft_multiple(item_type, 1, -num_crafts)
|
||||
end
|
||||
elseif type == "block" then
|
||||
if num_crafts > 0 then
|
||||
form = "blocks"
|
||||
if crafts[form] > 0 then
|
||||
print(("Crafting %s blocks"):format(item_type))
|
||||
craft_multiple(item_type, 2, num_crafts)
|
||||
elseif num_crafts < 0 then
|
||||
elseif crafts[form] < 0 then
|
||||
print(("Crafting %s ingots"):format(item_type))
|
||||
craft_multiple(item_type, 3, num_crafts)
|
||||
end
|
||||
end
|
||||
craft_multiple(item_type, 3, -num_crafts)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -210,9 +208,9 @@ while true do
|
|||
if num > MAX_NUM then set_production(item_type, false) end
|
||||
if num > MIN_NUM then
|
||||
local desired_dist = decide_dist(num)
|
||||
local diff = get_diff(current_dist, desired_dist)
|
||||
local diff = get_diff(desired_dist, current_dist)
|
||||
diff = filter_clamp(diff, current_dist)
|
||||
local crafts = diff_to_crafts(dist)
|
||||
local crafts = diff_to_crafts(diff)
|
||||
execute_crafts(item_type, crafts)
|
||||
else
|
||||
set_production(item_type, true)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue