|
|
|
@ -11,7 +11,7 @@ local inventory = component.inventory_controller
|
|
|
|
|
RESULT_SLOT = 4
|
|
|
|
|
|
|
|
|
|
-- robots inventory is 4 wide and crafting uses the top left portion
|
|
|
|
|
local slot_map = {
|
|
|
|
|
SLOT_MAP = {
|
|
|
|
|
1, 2, 3,
|
|
|
|
|
5, 6, 7,
|
|
|
|
|
9, 10, 11
|
|
|
|
@ -177,6 +177,20 @@ local function fetch_item(item, output_slot, count)
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---clear the 3x3 grid of any leftover items
|
|
|
|
|
local function clear_crafting_space()
|
|
|
|
|
for _, slot in ipairs(SLOT_MAP) do
|
|
|
|
|
if inventory.getStackInInternalSlot(slot) then
|
|
|
|
|
robot.select(slot)
|
|
|
|
|
store_item()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
if inventory.getStackInInternalSlot(RESULT_SLOT) then
|
|
|
|
|
robot.select(RESULT_SLOT)
|
|
|
|
|
store_item()
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
---accepts a recipe table containing result and ingredients
|
|
|
|
|
---@param recipe table
|
|
|
|
|
---@param count number how many items to craft
|
|
|
|
@ -188,7 +202,7 @@ local function craft_single_recipe(recipe, count)
|
|
|
|
|
end
|
|
|
|
|
for i, ingredient in pairs(recipe.shape) do
|
|
|
|
|
-- print('Fetching ' .. ingredient)
|
|
|
|
|
if not fetch_item(ingredient, slot_map[i], count) then
|
|
|
|
|
if not fetch_item(ingredient, SLOT_MAP[i], count) then
|
|
|
|
|
print('Failed to fetch ' .. ingredient)
|
|
|
|
|
confirm()
|
|
|
|
|
end
|
|
|
|
@ -391,6 +405,8 @@ local function craft_item(search)
|
|
|
|
|
return false
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
clear_crafting_space()
|
|
|
|
|
|
|
|
|
|
-- proceed to crafting the things
|
|
|
|
|
for i, rec in ipairs(crafting_order) do
|
|
|
|
|
print('Step #' .. i .. ' - ' .. rec.result)
|
|
|
|
|