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 code readability :) )
- print("FIND_ITEM: Finding " .. itemName .. "... ")
- for i = 1, 16 do
- 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
- print("FIND_ITEM: " .. itemName .. " not found. ")
- return false
- end
- function CheckAvailCrafts() --will return item to craft and craft count, as a table
- print("CHECK_AVAILABILITY: Checking inventory...")
- for k, v in pairs(Recipes) do --key; recipe output : value; recipe ingredient table
- if #v == 1 then --don't need to iterate and declare var if recipe is only 1 ingredient
- local slot, invCount = FindItemInInv( v[1] )
- if slot and invCount >= v[1] then
- print("CHECK_AVAILABILITY: Recipe found for " .. v .. ". ")
- return v, math.floor( invCount / v[1] )
- end
- else --Handle all other recipes (>1 ingredients)
- local lowestCount = 64
- for rK, rV in pairs(v) do
- local slot, invCount = FindItemInInv(rK)
- if slot then --check how many we can craft
- local low = math.floor( invCount / v[1] )
- if lowestCount > low then
- lowestCount = low
- end
- end
- end
- print("CHECK_AVAILABILITY: Recipe found for " .. k .. ". ")
- return v, lowestCount
- end
- end
- end
- function CraftItem(recipeTable, amount)
- repeat
- print("CRAFT_ITEM: Checking slots containing items required in recipe for " .. recipeTable .. ". ")
- 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 = CheckAvailCrafts()
- if craftAvailable then
- if count > 64 then
- count = 64
- end
- print("MAIN: Craft found. Initiating craft for " .. craftAvailable .. ". ")
- CraftItem(craftAvailable, count)
- 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