robocyclone

Turtle Crafting Host 1.0.lua

Mar 10th, 2023
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.84 KB | None | 0 0
  1. term.clear()
  2. Energizer = peripheral.find("powah:energizing_orb")
  3. if not Energizer then print("Cannot find energizer.") return false end
  4. Recipes = {}
  5. Recipes["powah:blazing_crystal_block"] = { input = {
  6.     ["botania:blaze_mesh"] = 1
  7. }   }
  8. Recipes["powah:niotic_crystal_block"] = { input = {
  9.     ["minecraft:diamond_block"] = 1
  10. }   }
  11. Recipes["powah:spirited_crystal_block"] = { input = {
  12.     ["minecraft:emerald_block"] = 1
  13. }   }
  14. Recipes["powah:dry_ice"] = { input = {
  15.     ["minecraft:blue_ice"] = 2
  16. }   }
  17. Recipes["powah:energized_steel_block"] = { input = {
  18.     ["minecraft:gold_block"] = 1,
  19.     ["minecraft:iron_block"] = 1
  20. }   }
  21. Recipes["powah:nitro_crystal"] = { input = {
  22.     ["minecraft:nether_star"] = 1,
  23.     ["minecraft:redstone_block"] = 2,
  24.     ["powah:blazing_crystal_block"] = 1
  25. }   }
  26. Recipes["allthemodium:unobtanium_vibranium_alloy_ingot"] = { input = {
  27.     ["allthemodium:piglich_heart"] = 1,
  28.     ["allthemodium:unobtanium_ingot"] = 1,
  29.     ["allthemodium:vibranium_ingot"] = 1
  30. }   }
  31. Recipes["allthemodium:unobtanium_allthemodium_alloy_ingot"] = { input = {
  32.     ["allthemodium:piglich_heart"] = 1,
  33.     ["allthemodium:unobtanium_ingot"] = 1,
  34.     ["allthemodium:allthemodium_ingot"] = 1
  35. }   }
  36. Recipes["allthemodium:vibranium_allthemodium_alloy_ingot"] = { input = {
  37.     ["allthemodium:piglich_heart"] = 1,
  38.     ["allthemodium:vibranium_ingot"] = 1,
  39.     ["allthemodium:allthemodium_ingot"] = 1
  40. }  }
  41.  
  42. function CheckAvailCraft()
  43.     print("CHECK_AVAILABILITY: Checking inventory...")
  44.     for i = 1, 16 do
  45.         turtle.select(i)
  46.         local info = turtle.getItemDetail(i)
  47.         if info then
  48.             print("CHECK_AVAILABILITY: Selected " .. info.count .. " of " .. info.name .. ". ")
  49.             for k, v in pairs(Recipes) do
  50.                 print("CHECK_AVAILABILITY: Searching recipe for " .. k)
  51.                 for ik, iv in pairs(v.input) do
  52.                     if tostring(ik) == info.name and tonumber(iv) <= info.count then
  53.                         print("CHECK_AVAILABILITY: Craft for " .. k .. " found.")
  54.                         return k
  55.                     elseif tostring(ik) == info.name and tonumber(iv) > info.count then
  56.                         print("CHECK_AVAILABILITY: Not enough " .. info.name .. " to craft " .. k)
  57.                         return false
  58.                     end
  59.                 end
  60.             end
  61.             print("CHECK_AVAILABILITY: Item not found in recipe database. Please remove " .. info.name .. " from inventory, or add a recipe to handle it.")
  62.         end
  63.     end
  64.     print("CHECK_AVAILABILITY: No craft available.")
  65.     return false
  66. end
  67.  
  68. function CraftItem(rOutput)
  69.     print("CRAFT_ITEM: Checking slots containing items required in recipe for " .. rOutput .. ". ")
  70.     local recipeInputTable = Recipes[rOutput].input
  71.     for k, v in pairs(recipeInputTable) do
  72.         for i = 1, 16 do
  73.             turtle.select(i)
  74.             local info = turtle.getItemDetail()
  75.             if info then
  76.                 if info.name == k then
  77.                     for j = 1, v do
  78.                         turtle.drop(1)
  79.                     end
  80.                 end
  81.             end
  82.         end
  83.     end
  84.     print("CRAFT_ITEM: Craft performed!")
  85.     local eInv = true
  86.     repeat
  87.         eInv = Energizer.list()
  88.         os.sleep(0.5)
  89.         print("CRAFT_ITEM: Waiting for craft to complete...")
  90.     until next(eInv) == nil
  91.     return true
  92. end
  93.  
  94. function Main()
  95.     print("MAIN: Checking inventory...")
  96.     local craftAvailable = CheckAvailCraft()
  97.     if craftAvailable then
  98.         print("MAIN: Craft found. Initiating craft for " .. craftAvailable .. ". ")
  99.         CraftItem(craftAvailable)
  100.     else
  101.         print("MAIN: Waiting to craft...")
  102.         os.pullEvent("turtle_inventory")
  103.         print("MAIN: Inventory changed. Initiating...")
  104.         Main()
  105.     end
  106.     Main()
  107. end
  108.  
  109. Main()
Add Comment
Please, Sign In to add comment