CaptainSpaceCat

Powah OrbCrafting Auto

Oct 16th, 2021 (edited)
898
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.96 KB | None | 0 0
  1. print("Starting OrbCrafting Auto V1.0")
  2.  
  3. local SLOT_SUCK = 1
  4. local SLOT_LIST = {
  5.     ["minecraft:iron_ingot"] = 2,
  6.     ["minecraft:gold_ingot"] = 3,
  7.     ["minecraft:blaze_rod"] = 4,
  8.     ["emendatusenigmatica:uranium_block"] = 5,
  9.     ["minecraft:blue_ice"] = 6,
  10.     ["powah:dielectric_casing"] = 7,
  11.     ["minecraft:ender_eye"] = 8,
  12.     ["powah:capacitor_basic_tiny"] = 9,
  13.     ["minecraft:emerald_block"] = 10,
  14.  
  15. }
  16. local RECIPE_LIST = {
  17.     ["minecraft:iron_ingot"] = {
  18.         {SLOT_LIST["minecraft:iron_ingot"], 1},
  19.         {SLOT_LIST["minecraft:gold_ingot"], 1}
  20.     },
  21.     ["minecraft:gold_ingot"] = {
  22.         {SLOT_LIST["minecraft:iron_ingot"], 1},
  23.         {SLOT_LIST["minecraft:gold_ingot"], 1}
  24.     },
  25.     ["minecraft:blaze_rod"] = {
  26.         {SLOT_LIST["minecraft:blaze_rod"], 1}
  27.     },
  28.     ["emendatusenigmatica:uranium_block"] = {
  29.         {SLOT_LIST["emendatusenigmatica:uranium_block"], 1}
  30.     },
  31.     ["minecraft:blue_ice"] = {
  32.         {SLOT_LIST["minecraft:blue_ice"], 2}
  33.     },
  34.  
  35.     ["powah:dielectric_casing"] = {
  36.         {SLOT_LIST["powah:dielectric_casing"], 1},
  37.         {SLOT_LIST["minecraft:ender_eye"], 1},
  38.         {SLOT_LIST["powah:capacitor_basic_tiny"], 1}
  39.     },
  40.     ["minecraft:ender_eye"] = {
  41.         {SLOT_LIST["powah:dielectric_casing"], 1},
  42.         {SLOT_LIST["minecraft:ender_eye"], 1},
  43.         {SLOT_LIST["powah:capacitor_basic_tiny"], 1}
  44.     },
  45.     ["powah:capacitor_basic_tiny"] = {
  46.         {SLOT_LIST["powah:dielectric_casing"], 1},
  47.         {SLOT_LIST["minecraft:ender_eye"], 1},
  48.         {SLOT_LIST["powah:capacitor_basic_tiny"], 1}
  49.     },
  50.     ["minecraft:emerald_block"] = {
  51.         {SLOT_LIST["minecraft:emerald_block"], 1}
  52.     }
  53. }
  54.  
  55.  
  56. local function delayfn(start, delay, name)
  57.     if os.clock() - start >= delay then
  58.         error("Timelatch " .. name .. " broken")
  59.         return false
  60.     end
  61.     return true
  62. end
  63.  
  64. --class that returns true for n seconds past when this is created
  65. local function timeLatch(n, name)
  66.     latch = {}
  67.     latch.eval = function() delayfn(latch.start, latch.delay, latch.name) end
  68.     latch.start = os.clock()
  69.     latch.delay = n
  70.     latch.name = name or "latch"
  71.     return latch
  72. end
  73.  
  74. local function safeSuck()
  75.     turtle.select(SLOT_SUCK)
  76.     if turtle.suckUp() then
  77.         if not turtle.transferTo(SLOT_LIST[turtle.getItemDetail().name]) then
  78.             turtle.dropUp()
  79.         end
  80.         return true
  81.     end
  82.     return false
  83. end
  84.  
  85. function idle()
  86.     while not safeSuck() do
  87.         sleep(0.1)
  88.     end
  89.     while safeSuck() do
  90.         sleep(0.1)
  91.     end
  92. end
  93.  
  94. function scanRecipe()
  95.     for i, v in pairs(SLOT_LIST) do
  96.         turtle.select(v)
  97.         if turtle.getItemCount() > 0 then
  98.             return RECIPE_LIST[i]
  99.         end
  100.     end
  101. end
  102.  
  103. function waitForRecipeCompletion()
  104.     sleep(0.5)
  105.     while rs.getInput("back") do
  106.         sleep(0.5)
  107.     end
  108. end
  109.  
  110.  
  111. function performRecipe(recipe)
  112.     if recipe then
  113.         while true do
  114.             for i, v in pairs(recipe) do
  115.                 turtle.select(v[1])
  116.                 if turtle.getItemCount() == 0 then return end
  117.                 turtle.dropDown(v[2])
  118.             end
  119.             waitForRecipeCompletion()
  120.         end
  121.     end
  122. end
  123.  
  124.  
  125. while true do
  126.     idle()
  127.     recipe = scanRecipe()
  128.     while recipe do
  129.         performRecipe(recipe)
  130.         recipe = scanRecipe()
  131.     end
  132. end
  133.  
Add Comment
Please, Sign In to add comment