Skip to content

Instantly share code, notes, and snippets.

@spacehare
Last active September 12, 2023 18:11
Show Gist options
  • Save spacehare/d8fb4d3976020f0484f59be494cd59e4 to your computer and use it in GitHub Desktop.
Save spacehare/d8fb4d3976020f0484f59be494cd59e4 to your computer and use it in GitHub Desktop.
ComputerCraft Tweaked script for Ars Nouveau's Imbuement Chamber automation. Stoneblock 3.
local args = { ... }
local expected_args = 2
if args[2] == nil then args[2] = 1 end
if #args ~= expected_args then
if #args > expected_args then
print('Too many arguments. Expected ' .. expected_args .. '.')
elseif #args < expected_args then
print('Too few arguments. Expected ' .. expected_args .. '.')
end
if args[1] ~= type('string') and args[2] ~= type('number') then
print('Wrong arguments.')
end
error('Usage: imbue <essence name> <amount>', 0)
return
end
-- barrels
local ingredient_barrel = peripheral.wrap('minecraft:barrel_0')
local output_barrel = peripheral.wrap('minecraft:barrel_1')
local gem_barrel = peripheral.wrap('minecraft:barrel_2')
local pedestals = {
peripheral.wrap('ars_nouveau:arcane_pedestal_0'),
peripheral.wrap('ars_nouveau:arcane_pedestal_1'),
peripheral.wrap('ars_nouveau:arcane_pedestal_2'),
}
if #pedestals ~= 3 then
error('Expected 3 pedestals...', 0)
end
local gem = "ars_nouveau:source_gem"
local chamber = peripheral.find('ars_nouveau:imbuement_chamber')
local product = 0
-- local monitor = peripheral.wrap('top')
-- https://stackoverflow.com/questions/56097297/two-instances-of-a-lua-class-are-the-same-object
local Essence = {}
function Essence:new(name, a, b, c)
local o = {}
setmetatable(o, { __index = self })
o.name = name
o.ingredient = { a, b, c }
return o
end
local Essences = {
air = Essence:new('air',
'minecraft:feather',
'minecraft:arrow',
'ars_nouveau:wilden_wing'),
fire = Essence:new('fire',
'minecraft:flint_and_steel',
'minecraft:gunpowder',
'minecraft:torch'),
conjuration = Essence:new('conjuration',
'ars_nouveau:wilden_horn',
'minecraft:book',
'ars_nouveau:starbuncle_shards'),
earth = Essence:new('earth',
'minecraft:iron_ingot',
'minecraft:dirt',
'minecraft:wheat_seeds'),
water = Essence:new('water',
'minecraft:water_bucket',
'minecraft:kelp',
'minecraft:snow_block'),
abjuration = Essence:new('abjuration',
'minecraft:fermented_spider_eye',
'minecraft:milk_bucket',
'minecraft:sugar'),
manipulation = Essence:new('manipulation',
'minecraft:stone_button',
'minecraft:clock',
'minecraft:redstone'),
}
local function find_item_slot(inventory, item_name)
print('searching for ' .. item_name)
for slot, item in pairs(inventory.list()) do
if item and item.name == item_name then
print(inventory.getItemDetail(slot).displayName .. ' found at ' .. slot)
return slot
end
end
error('error, ' .. item_name .. ' is missing from ' .. peripheral.getName(inventory), 0)
end
-- https://github.com/cc-tweaked/CC-Tweaked/issues/697
-- https://github.com/cc-tweaked/CC-Tweaked/issues/697#issuecomment-767077222
local function craft(essence_string)
local essence = nil
for key, value in pairs(Essences) do
if essence_string == value.name then
essence = value
break
end
end
if essence == nil then
print('No such element: ' .. essence_string)
return
end
-- grab each ingredient
if product == 0 then
for i = 1, #pedestals do
ingredient_barrel.pushItems(peripheral.getName(pedestals[i]),
find_item_slot(ingredient_barrel, essence.ingredient[i]), 1, 1)
end
end
-- grab a gem. can only insert gem after there is a valid recipe
chamber.pullItems(peripheral.getName(gem_barrel),
find_item_slot(gem_barrel, gem), 1)
repeat sleep(1) until chamber.getItemDetail(1).name ~= gem
product = product + 1
print('successfully crafted ' .. chamber.getItemDetail(1).displayName .. ' ' .. product .. '/' .. args[2])
chamber.pushItems(peripheral.getName(output_barrel), 1)
end
-- return ingredients to ingredient_barrel
local function yoink()
for i = 1, #pedestals do
ingredient_barrel.pullItems(peripheral.getName(pedestals[i]), 1)
end
end
print('Crafting ' .. args[2] .. ' ' .. args[1] .. ' essence.')
-- craft args[2] times
for i = 1, args[2] do craft(args[1]) end
yoink() -- put the ingredients back
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment