zPandro

stoneBricksEnderChestHandler

Jun 23rd, 2021 (edited)
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local CHEST = peripheral.wrap("front")
  2. local CHEST_SIZE = 27
  3. local MAX_SB = 1728
  4. local SLOT_COUNT = 16
  5.  
  6. function getListSize(list)
  7.     l_Size = 0
  8.     for i = 1, CHEST_SIZE, 1 do
  9.         listSlot = list[i]
  10.         if (listSlot ~= nil) then
  11.             l_Size = l_Size + 1
  12.         end
  13.     end
  14.     return l_Size
  15. end
  16.  
  17. function getChestSlots(list)
  18.     slots = {}
  19.     slotPos = 1
  20.  
  21.     for i = 1, CHEST_SIZE, 1 do
  22.         chestSlot = list[i]
  23.         if (chestSlot ~= nil) then
  24.             table.insert(slots, slotPos, i)
  25.             slotPos = slotPos + 1
  26.         end
  27.     end
  28.     return slots
  29. end
  30.  
  31. function getTotalAmount(chestList)
  32.     t_sb = 0
  33.     listSize = getListSize(chestList)
  34.  
  35.     chestSlots = getChestSlots(chestList)
  36.     chestSlotsSize = getListSize(chestSlots)
  37.  
  38.     for i = 1, chestSlotsSize, 1 do
  39.         t_sb = t_sb + chestList[chestSlots[i]].count
  40.     end
  41.     return t_sb
  42. end
  43.  
  44. -- MAIN
  45. while true do
  46.     listSize = getListSize(CHEST.list())
  47.     t_sb = getTotalAmount(CHEST.list())
  48.     --print("List size: " .. listSize)
  49.     --print("Total stone bricks: " .. t_sb)
  50.     if(t_sb < MAX_SB) then
  51.         for slot = 1, SLOT_COUNT, 1 do
  52.             turtle.select(slot)
  53.             turtle.drop()
  54.             turtle.suckUp()
  55.         end
  56.     end
  57. end
Add Comment
Please, Sign In to add comment