Compare commits

..

No commits in common. "31ebbb66c0b2ec7179672e5c2491b75076e29018" and "28e72b142fc05e47b41d8546511dfbb12a844ce9" have entirely different histories.

View file

@ -40,33 +40,21 @@ local PRODUCTS = {
-- these will be crafted when needed -- these will be crafted when needed
local RECIPES = { local RECIPES = {
["minecraft:iron_nugget"] = { ["minecraft:iron_nugget"] = {
ingredients = {
{"minecraft:iron_nugget", 60}, {"minecraft:iron_nugget", 60},
{"minecraft:gravel", 24}, {"minecraft:gravel", 24},
}, },
addr = PRESS_ADDR,
},
["minecraft:gold_nugget"] = { ["minecraft:gold_nugget"] = {
ingredients = {
{"minecraft:gold_nugget", 64}, {"minecraft:gold_nugget", 64},
{"minecraft:gravel", 64}, {"minecraft:gravel", 64},
}, },
addr = PRESS_ADDR,
},
["create:zinc_nugget"] = { ["create:zinc_nugget"] = {
ingredients = {
{"create:zinc_nugget", 64}, {"create:zinc_nugget", 64},
{"minecraft:gravel", 32}, {"minecraft:gravel", 32},
}, },
addr = PRESS_ADDR,
},
["create:copper_nugget"] = { ["create:copper_nugget"] = {
ingredients = {
{"create:copper_nugget", 63}, {"create:copper_nugget", 63},
{"minecraft:gravel", 18}, {"minecraft:gravel", 18},
}, },
addr = PRESS_ADDR,
},
} }
local SLEEP_T = 20 local SLEEP_T = 20
@ -121,7 +109,7 @@ function cycleItems (ticker, items)
} }
ticker.requestFiltered(addr, request) ticker.requestFiltered(addr, request)
os.sleep(1) os.sleep(1)
return makeRequest(item, amt - limit, addr) return makeRequest(item, amt - limit)
end end
for _, pair in pairs(PRODUCTS) do for _, pair in pairs(PRODUCTS) do
local name, addr = pair[1], pair[2] local name, addr = pair[1], pair[2]
@ -141,10 +129,10 @@ function getAmounts (storage_f)
return result return result
end end
function getNumCraftable (ingredients, current_stock) function getNumCraftable (recipe, current_stock)
local result = nil local result = nil
local item, count local item, count
for _, ingredient in ipairs(ingredients) do for _, ingredient in ipairs(recipe) do
item, count = ingredient[1], ingredient[2] item, count = ingredient[1], ingredient[2]
if current_stock[item] == nil then return 0 end if current_stock[item] == nil then return 0 end
local num = math.floor(current_stock[item] / count) local num = math.floor(current_stock[item] / count)
@ -154,25 +142,23 @@ function getNumCraftable (ingredients, current_stock)
result = math.min(result, num) result = math.min(result, num)
end end
end end
if result == nil then result = 0 end
return result return result
end end
function craftRecipe (ticker, recipe, count) function craftRecipe (ticker, recipe, count)
if count == nil then count = 1 end if count == nil then count = 1 end
local createRequest local createRequest
createRequest = function (recipe, i) createRequest = function (recipe)
if i == nil then i = 1 end local ingredient = table.remove(recipe)
local ingredient = recipe.ingredients[i]
if ingredient == nil then return end if ingredient == nil then return end
local item = { local item = {
name = ingredient[1], name = ingredient[1],
_requestCount = ingredient[2], _requestCount = ingredient[2],
} }
return item, createRequest(recipe, i + 1) return item, createRequest(recipe)
end end
while count > 0 do while count > 0 do
ticker.requestFiltered(recipe.addr, createRequest(recipe)) ticker.requestFiltered(PRESS_ADDR, createRequest(recipe))
os.sleep(1) os.sleep(1)
count = count - 1 count = count - 1
end end
@ -201,7 +187,7 @@ function run (ticker, export_storage, current_modes)
if mode[1] == "recipe" then if mode[1] == "recipe" then
-- make as many recipes as you can with current stock -- make as many recipes as you can with current stock
local recipe = RECIPES[item] local recipe = RECIPES[item]
local count = getNumCraftable(recipe.ingredients, stock_amounts) local count = getNumCraftable(recipe, stock_amounts)
craftRecipe(ticker, recipe, count) craftRecipe(ticker, recipe, count)
elseif mode[1] == "export" then elseif mode[1] == "export" then
local export_amt = export_amounts[item] local export_amt = export_amounts[item]