Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.clear()
- Energizer = peripheral.find("powah:energizing_orb")
- if not Energizer then
- error("Cannot find energizer.")
- end
- Recipes = {}
- Recipes["powah:blazing_crystal_block"] = {
- ["botania:blaze_block"] = 1
- }
- Recipes["powah:niotic_crystal_block"] = {
- ["minecraft:diamond_block"] = 1
- }
- Recipes["powah:spirited_crystal_block"] = {
- ["minecraft:emerald_block"] = 1
- }
- Recipes["powah:dry_ice"] = {
- ["minecraft:blue_ice"] = 2
- }
- Recipes["powah:energized_steel_block"] = {
- ["minecraft:gold_block"] = 1,
- ["minecraft:iron_block"] = 1
- }
- Recipes["powah:nitro_crystal"] = {
- ["minecraft:nether_star"] = 1,
- ["minecraft:redstone_block"] = 2,
- ["powah:blazing_crystal_block"] = 1
- }
- Recipes["allthemodium:unobtainium_vibranium_alloy_ingot"] = {
- ["allthemodium:piglich_heart"] = 1,
- ["allthemodium:unobtainium_ingot"] = 1,
- ["allthemodium:vibranium_ingot"] = 1
- }
- Recipes["allthemodium:unobtainium_allthemodium_alloy_ingot"] = {
- ["allthemodium:piglich_heart"] = 1,
- ["allthemodium:unobtainium_ingot"] = 1,
- ["allthemodium:allthemodium_ingot"] = 1
- }
- Recipes["allthemodium:vibranium_allthemodium_alloy_ingot"] = {
- ["allthemodium:piglich_heart"] = 1,
- ["allthemodium:vibranium_ingot"] = 1,
- ["allthemodium:allthemodium_ingot"] = 1
- }
- function FindItemInInv(itemName) --to fix double dropping items if requested craft requires >64 of one input ( and for readability :) )
- write("\nFIND_ITEM: Finding " .. itemName .. ".")
- for i = 1, 16 do
- os.sleep(0.05)
- write(".")
- local info = turtle.getItemDetail(i)
- if info and info.name == itemName then
- write("\nFIND_ITEM: " .. info.count .. " of " .. itemName .. " found in slot " .. i .. "! ")
- return i, info.count
- end
- end
- write("\nFIND_ITEM: " .. itemName .. " not found. ")
- return false
- end
- function CheckCraft(recipeOutput, recipeTable) --will return item to craft, iterations, and recipe output, if recipe can be crafted
- write("\nCHECK_CRAFT: Searching for ingredients for " .. recipeOutput .. ".")
- local lowestCount = 64
- for k, v in pairs(recipeTable) do
- os.sleep(0.05)
- local slot, invCount = FindItemInInv(k)
- if slot ~= false then --check how many we can potentially craft
- local low = math.floor( invCount / v )
- if lowestCount > low then
- lowestCount = low
- end
- else
- write("\nCHECK_CRAFT: Missing " .. k .. " for recipe " .. recipeOutput .. ". ")
- return false
- end
- end
- write("\nCHECK_CRAFT: Can craft " .. recipeOutput .. " " .. lowestCount .. " times.")
- return recipeTable, lowestCount, recipeOutput
- end
- function CheckAvailCrafts() --run CheckCraft on all available recipes
- write("\nCHECK_ALL: Checking inventory...")
- for k, v in pairs(Recipes) do --key; recipe output : value; recipe ingredient table
- local recipeTable, lowestCount, recipeOutput = CheckCraft(k, v)
- if recipeTable and lowestCount and recipeOutput then
- write("\nCHECK_ALL: Crafting first recipe match found for " .. recipeOutput ..", " .. lowestCount .. " times. ")
- return recipeTable, lowestCount, recipeOutput
- end
- end
- write("\nCHECK_ALL: No recipes found.")
- return false
- end
- function CraftItem(recipeTable, amount, recipeOutput)
- repeat
- write("\nCRAFT_ITEM: Checking slots containing items required in recipe for " .. recipeOutput .. ". ")
- for k, v in pairs(recipeTable) do
- local slot = FindItemInInv(k)
- turtle.select(slot)
- for i = 1, v do
- turtle.drop()
- end
- end
- write("\nCRAFT_ITEM: Recipe inserted.")
- amount = amount - 1
- write(" There are " .. amount .. " iterations of this recipe left.")
- local eInv = true --Handles crafts that take longer than process run time to complete
- write("\nCRAFT_ITEM: Waiting for craft to complete.")
- repeat
- eInv = Energizer.list()
- os.sleep(0.75)
- write(".")
- until next(eInv) == nil
- write("\nCRAFT_ITEM: Craft complete!")
- until amount == 0
- return true
- end
- function Main()
- write("\nMAIN: Checking inventory...")
- local craftAvailable, count, r = CheckAvailCrafts()
- if craftAvailable then
- if count > 64 then
- count = 64
- end
- write("\nMAIN: Craft found. Initiating craft for " .. r .. ", " .. count .. " time(s).")
- CraftItem(craftAvailable, count, r)
- else
- write("\nMAIN: No craft available. Waiting to craft...")
- os.pullEvent("turtle_inventory")
- write("\nMAIN: Inventory changed. Initiating...")
- Main()
- end
- Main()
- end
- Main()
Add Comment
Please, Sign In to add comment