MatthiGamer

Turtle Pure Crystal Harvest

Jun 3rd, 2021 (edited)
390
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.11 KB | None | 0 0
  1. local crystalSlot = 16
  2. local fullSlots = 0
  3.  
  4. -- Functions
  5. local function wait()
  6.     os.sleep(290)
  7. end
  8.  
  9. local function getItems()
  10.     for i = 1, 15 - fullSlots do
  11.         turtle.select(i)
  12.         turtle.suck()
  13.     end
  14. end
  15.  
  16. local function transferCrystals(amount)
  17.     -- crystalSlot has Crystals or is empty
  18.     local currentSlot = turtle.getSelectedSlot()
  19.     if (turtle.getItemDetail(crystalSlot) == nil or turtle.getItemDetail(crystalSlot).name == "appliedenergistics2:item.ItemMultiMaterial") then
  20.         print("Slot clear.")
  21.     else
  22.         print("Crystal Slot is used. Dropping items...")
  23.         turtle.select(crystalSlot)
  24.         drop()
  25.         turtle.select(currentSlot)
  26.         print("Items dropped.")
  27.     end
  28.     turtle.transferTo(crystalSlot, amount)
  29. end
  30.  
  31. local function moveCrystalSlot()
  32.     fullSlots = fullSlots + 1
  33.     crystalSlot = crystalSlot - 1
  34. end
  35.  
  36. local function compareSlots()
  37.     local haveSeeds = false
  38.     for i = 1, 15 - fullSlots do
  39.         turtle.select(i)
  40.         if (turtle.getItemDetail() and turtle.getItemDetail().name == "appliedenergistics2:item.ItemMultiMaterial") then
  41.             print("Finished some Crystals.")
  42.             if (turtle.getItemSpace(crystalSlot) == 0) then
  43.                 moveCrystalSlot()
  44.                 turtle.transferCrystals(turtle.getItemCount())
  45.             elseif (turtle.getItemCount() > turtle.getItemSpace(crystalSlot)) then
  46.                 transferCrystals(turtle.getItemSpace())
  47.                 moveCrystalSlot()
  48.                 transferCrystals(turtle.getItemCount())
  49.             else
  50.                 transferCrystals(turtle.getItemCount())
  51.             end
  52.         elseif (turtle.getItemDetail() and turtle.getItemDetail().name == "appliedenergistics2:item.ItemCrystalSeed") then
  53.             turtle.drop()
  54.             print("Still have seeds.")
  55.             haveSeeds = true
  56.         else
  57.             turtle.drop()
  58.         end
  59.     end
  60.    
  61.     if (haveSeeds == true) then
  62.         print("Restart process...")
  63.         return false
  64.     end
  65.    
  66.     return true
  67. end
  68.  
  69. while(compareSlots() == false) do
  70.     wait()
  71.     getItems()
  72. end
Add Comment
Please, Sign In to add comment