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
- print("Cannot find energizer.")
- return false
- 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:unobtanium_vibranium_alloy_ingot"] = {
- ["allthemodium:piglich_heart"] = 1,
- ["allthemodium:unobtanium_ingot"] = 1,
- ["allthemodium:vibranium_ingot"] = 1
- }
- Recipes["allthemodium:unobtanium_allthemodium_alloy_ingot"] = {
- ["allthemodium:piglich_heart"] = 1,
- ["allthemodium:unobtanium_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 :) )
- print("FIND_ITEM: Finding " .. itemName .. "... ")
- for i = 1, 16 do
- os.sleep(1)
- local info = turtle.getItemDetail(i)
- if info and info.name == itemName then
- print("FIND_ITEM: " .. info.count .. " of " .. itemName .. " found in slot " .. i .. "! ")
- return i, info.count
- end
- end
- os.sleep(1)
- print("FIND_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
- print("CHECK_CRAFT: Searching for ingredients for " .. recipeOutput .. ". ")
- local lowestCount = 64
- for k, v in pairs(recipeTable) do
- os.sleep(1)
- 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
- print("CHECK_CRAFT: Missing " .. k .. "for recipe " .. recipeOutput .. ". ")
- return false
- end
- end
- print("CHECK_CRAFT: Can craft " .. recipeOutput .. " " .. lowestCount .. " times.")
- return recipeTable, lowestCount, recipeOutput
- end
- function CheckAvailCrafts() --run CheckCraft on all available recipes
- print("CHECK_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
- print("CHECK_ALL: Crafting first recipe match found for " .. recipeOutput ..", " .. lowestCount .. " times. ")
- return recipeTable, lowestCount, recipeOutput
- end
- end
- print("CHECK_ALL: No recipes found.")
- return false
- end
- function CraftItem(recipeTable, amount, recipeOutput)
- repeat
- print("CRAFT_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
- print("CRAFT_ITEM: Recipe inserted.")
- amount = amount - 1
- local eInv = true --Handles crafts that take longer than process run time to complete
- repeat
- eInv = Energizer.list()
- os.sleep(0.5)
- print("CRAFT_ITEM: Waiting for craft to complete...")
- until next(eInv) == nil
- print("CRAFT_ITEM: Craft complete!")
- until amount == 0
- return true
- end
- function Main()
- print("MAIN: Checking inventory...")
- local craftAvailable, count, r = CheckAvailCrafts()
- if craftAvailable then
- if count > 64 then
- count = 64
- end
- print("MAIN: Craft found. Initiating craft for " .. r .. ". ")
- CraftItem(craftAvailable, count, r)
- else
- print("MAIN: No craft available. Waiting to craft...")
- os.pullEvent("turtle_inventory")
- print("MAIN: Inventory changed. Initiating...")
- Main()
- end
- Main()
- end
- Main()
Add Comment
Please, Sign In to add comment