zPandro

orbHandler 2.1

Jul 6th, 2021 (edited)
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.94 KB | None | 0 0
  1. local SLOT_COUNT = 16
  2. local E_Orb = peripheral.wrap("bottom")
  3.  
  4. -- Checks if the energizing orb is busy or if it's free
  5. function itemsDroppable(orb)
  6.     item = orb.getItemDetail(2)
  7.     if(item == nil) then
  8.         for slot = 1, SLOT_COUNT, 1 do
  9.             local item = turtle.getItemDetail(slot)
  10.             if(item ~= nil) then
  11.                 return true
  12.             end
  13.         end
  14.     else
  15.         return false
  16.     end
  17. end
  18.  
  19. -- Inserts the items into the energizing orb
  20. function dropItems(orb)
  21.     local itemName = ""
  22.     local insert = true
  23.  
  24.     -- Cycle to insert items into the energizing orb
  25.     for slot = 1, SLOT_COUNT, 1 do
  26.         local item = turtle.getItemDetail(slot)
  27.         if (item ~= nil) then
  28.             if (insert) then
  29.                 turtle.select(slot)
  30.                 if (item["name"] == "minecraft:redstone_block") then
  31.                     turtle.dropDown(2)
  32.                 else
  33.                     turtle.dropDown(1)
  34.                 end
  35.             end
  36.             if (insert) then
  37.                 insert = checkForDupes(item["name"])
  38.             end
  39.         end
  40.     end
  41. end
  42.  
  43. -- Checks for multiple stacks of the same item
  44. function checkForDupes(itemName)
  45.     for i = 1, SLOT_COUNT, 1 do
  46.         local item = turtle.getItemDetail(i)
  47.         if(item ~= nil) then
  48.             if (itemName == item["name"]) then
  49.                 return false
  50.             else
  51.                 return true
  52.             end
  53.         end
  54.     end
  55. end
  56.  
  57. -- Waits for the machine to complete the items processing
  58. -- and extracts the results, proceeds then to drop the items
  59. -- in a storage placed above
  60. function handleResults(orb)
  61.     while true do
  62.         resultSlot = orb.getItemDetail(1)
  63.         if (resultSlot ~= nil) then
  64.             turtle.select(16)
  65.             turtle.suckDown()
  66.             turtle.dropUp()
  67.             turtle.select(1)
  68.             break
  69.         end
  70.     end
  71. end
  72.  
  73. --
  74. function getLoops(orb)
  75.     item = orb.getItemDetail(2)
  76.     maxLoops = 0
  77.     if(item == nil) then
  78.         for slot = 1, SLOT_COUNT, 1 do
  79.             local item = turtle.getItemDetail(slot)
  80.             if(item ~= nil) then
  81.                 if (item["count"]) then
  82.                     maxLoops = item["count"]
  83.                 end
  84.             end
  85.         end
  86.     end
  87.     return maxLoops
  88. end
  89.  
  90. -- CheckItems checks if all the items inside the turtle are
  91. -- legal items to be dropped inside the energizing orb
  92. function checkItems(itemNames)
  93.     for slot = 1, SLOT_COUNT, 1 do
  94.         local item = turtle.getItemDetail(slot)
  95.         if(item ~= nil) then
  96.             notFoundInList = true
  97.             for i = 1, 13, 1 do
  98.                 if (item["name"] == itemNames[i]) then
  99.                     notFoundInList = false
  100.                     break
  101.                 end
  102.             end
  103.             if (notFoundInList) then
  104.                 turtle.select(slot)
  105.                 turtle.dropUp()
  106.             end
  107.         end
  108.     end
  109. end
  110.  
  111. -- Creates the items map of legal items for the energizing orb
  112. function createMap()
  113.     tab = {}
  114.     table.insert(tab, 1, "minecraft:emerald")
  115.     table.insert(tab, 2, "minecraft:diamond")
  116.     table.insert(tab, 3, "minecraft:redstone_block")
  117.     table.insert(tab, 4, "minecraft:blaze_rod")
  118.     table.insert(tab, 5, "minecraft:iron_ingot")
  119.     table.insert(tab, 6, "minecraft:gold_ingot")
  120.     table.insert(tab, 7, "minecraft:nether_star")
  121.     table.insert(tab, 8, "minecraft:ender_eye")
  122.     table.insert(tab, 9, "powah:dielectric_casing")
  123.     table.insert(tab, 10, "powah:capacitor_basic_tiny")
  124.     table.insert(tab, 11, "powah:blazing_crystal_block")
  125.     table.insert(tab, 12, "minecraft:blue_ice")
  126.     table.insert(tab, 13, "minecraft:snowball")
  127.     return tab
  128. end
  129.  
  130.  
  131.  
  132. itemNames = createMap()
  133. while true do
  134.     table.foreach(itemNames, print)
  135.     checkItems(itemNames)
  136.     if (itemsDroppable(E_Orb)) then
  137.         sleep(0.75)
  138.         dropItems(E_Orb)
  139.         handleResults(E_Orb)
  140.     end
  141. end
Add Comment
Please, Sign In to add comment