Compare commits

...

2 Commits

@ -326,8 +326,9 @@ end
---accepts a recipe table ---accepts a recipe table
---@param search string search for an craftable item ---@param search string search for an craftable item
---@param amount number how many items to craft
---@return boolean ---@return boolean
local function craft_item(search) local function craft_item(search, amount)
search = string.lower(search) -- convert to unified lowercase search = string.lower(search) -- convert to unified lowercase
local matches = {} local matches = {}
@ -374,67 +375,72 @@ local function craft_item(search)
local recipe = recipes[selected] local recipe = recipes[selected]
print('Trying to craft ' .. recipe.result) print('Trying to craft ' .. amount .. 'x ' .. recipe.result)
local available_items = read_chest_contents() local repeating = false
if not available_items then
print('Not facing a chest')
return false
end
local required_items, crafting_order = craft_recipe_recursion(recipe, clone(available_items), {}) local count = math.ceil(amount / recipe.count)
print('\nRequires these items:') for _ = 1, count do
local failed = false local available_items = read_chest_contents()
for required_item, required_count in pairs(required_items) do if not available_items then
local available = available_items[required_item] print('Not facing a chest')
if not available then return false
available = 0
end
if available < required_count then
print(available .. "/" .. required_count .. "\t" .. required_item .. "\t- Missing " .. required_count - available)
failed = true
else
print(available .. "/" .. required_count .. "\t" .. required_item)
end end
end
if failed then
return false
end
if not confirm() then local required_items, crafting_order = craft_recipe_recursion(recipe, clone(available_items), {})
print('Operation cancelled')
return false
end
-- print('\nCrafting in order:') print('\nRequires these items:')
-- for i, rec in ipairs(crafting_order) do local failed = false
-- print(i, rec.result) for required_item, required_count in pairs(required_items) do
-- end local available = available_items[required_item]
if not available then
-- if not confirm() then available = 0
-- print('Operation cancelled') end
-- return false if available < required_count then
-- end print(available .. "/" .. required_count .. "\t" .. required_item .. "\t- Missing " .. required_count - available)
failed = true
-- proceed to crafting the things else
for i, rec in ipairs(crafting_order) do print(available .. "/" .. required_count .. "\t" .. required_item)
print('Step #' .. i .. ' - ' .. rec.result) end
if not craft_single_recipe(rec, 1) then end
print('Unexpected error') if failed then
return false return false
end end
if not repeating then
if not confirm() then
print('Operation cancelled')
return false
end
end
-- proceed to crafting the things
local steps = #crafting_order
for i, rec in ipairs(crafting_order) do
print('Step ' .. i .. '/' .. steps .. ' - ' .. rec.result)
if not craft_single_recipe(rec, 1) then
print('Unexpected error')
return false
end
end
repeating = true
end end
return true return true
end end
local target = ... local target, amount = ...
if not target then if not target then
print("Usage: craft <item>") print("Usage: craft <item> [count]")
return return
end end
craft_item(target) if not amount then
amount = 1
end
craft_item(target, amount)

@ -844,6 +844,54 @@ return {
nil, 'opencomputers:material;5', 'minecraft:obsidian;0', nil, 'opencomputers:material;5', 'minecraft:obsidian;0',
} }
}, },
-- Data card (Tier 1)
['opencomputers:card;10'] = {
result = 'opencomputers:card;10;data card 1',
count = 1,
requires = {
['minecraft:iron_nugget;0'] = 1,
['opencomputers:material;10'] = 1, -- ALU
['opencomputers:material;8'] = 1, -- Microchip (Tier 2)
['opencomputers:material;5'] = 1, -- Card Base
},
shape = {
nil, nil, nil,
'minecraft:iron_nugget;0', 'opencomputers:material;10', 'opencomputers:material;8',
nil, 'opencomputers:material;5', nil,
}
},
-- Data card (Tier 2)
['opencomputers:card;11'] = {
result = 'opencomputers:card;11;data card 2',
count = 1,
requires = {
['minecraft:gold_nugget;0'] = 1,
['opencomputers:component;0'] = 1, -- CPU 1
['opencomputers:material;9'] = 1, -- Microchip (Tier 3)
['opencomputers:material;5'] = 1, -- Card Base
},
shape = {
nil, nil, nil,
'minecraft:gold_nugget;0', 'opencomputers:component;0', 'opencomputers:material;9',
nil, 'opencomputers:material;5', nil,
}
},
-- Data card (Tier 3)
['opencomputers:card;12'] = {
result = 'opencomputers:card;12;data card 3',
count = 1,
requires = {
['opencomputers:material;29'] = 1, -- Diamond Chip
['opencomputers:component;1'] = 1, -- CPU 2
['opencomputers:component;10'] = 1, -- RAM 3
['opencomputers:material;5'] = 1, -- Card Base
},
shape = {
nil, nil, nil,
'opencomputers:material;29', 'opencomputers:component;1', 'opencomputers:component;10',
nil, 'opencomputers:material;5', nil,
}
},
-- EEPROM -- EEPROM
['opencomputers:storage;0'] = { ['opencomputers:storage;0'] = {

Loading…
Cancel
Save