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
|
-- basic actions
|
||||||
function craft (item_type, conversion_type)
|
function craft (item_type, conversion_type)
|
||||||
-- TODO double check this
|
-- TODO double check this
|
||||||
local relay_num, face = string.match(target[item_type][conversion_type],
|
local relay_num, face = string.match(
|
||||||
"(d+):(%l+)"
|
target[item_type][conversion_type],
|
||||||
|
"(%d+):(%l+)"
|
||||||
)
|
)
|
||||||
local periph = string.format("redstone_relay_%d", relay_num)
|
local periph = string.format("redstone_relay_%d", relay_num)
|
||||||
peripheral.call(periph, "setOutput", face, true)
|
peripheral.call(periph, "setOutput", face, true)
|
||||||
|
|
@ -78,24 +79,21 @@ function craft_multiple (item_type, conversion_type, count)
|
||||||
end
|
end
|
||||||
|
|
||||||
function execute_crafts (item_type, crafts)
|
function execute_crafts (item_type, crafts)
|
||||||
for type, num_crafts in pairs(crafts) do
|
local form = "nuggets"
|
||||||
if type == "nugget" then
|
if crafts[form] > 0 then
|
||||||
if num_crafts > 0 then
|
|
||||||
print(("Crafting %s nuggets"):format(item_type))
|
print(("Crafting %s nuggets"):format(item_type))
|
||||||
craft_multiple(item_type, 4, num_crafts)
|
craft_multiple(item_type, 4, num_crafts)
|
||||||
elseif num_crafts < 0 then
|
elseif crafts[form] < 0 then
|
||||||
print(("Crafting %s ingots"):format(item_type))
|
print(("Crafting %s ingots"):format(item_type))
|
||||||
craft_multiple(item_type, 1, num_crafts)
|
craft_multiple(item_type, 1, -num_crafts)
|
||||||
end
|
end
|
||||||
elseif type == "block" then
|
form = "blocks"
|
||||||
if num_crafts > 0 then
|
if crafts[form] > 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(item_type, 2, num_crafts)
|
||||||
elseif num_crafts < 0 then
|
elseif crafts[form] < 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)
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
@ -210,9 +208,9 @@ while true do
|
||||||
if num > MAX_NUM then set_production(item_type, false) end
|
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(current_dist, desired_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(dist)
|
local crafts = diff_to_crafts(diff)
|
||||||
execute_crafts(item_type, crafts)
|
execute_crafts(item_type, crafts)
|
||||||
else
|
else
|
||||||
set_production(item_type, true)
|
set_production(item_type, true)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue