QarthO

CC Turtle: Botania Petals

May 7th, 2022 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.00 KB | None | 0 0
  1. local tool = peripheral.wrap("left")
  2. local Slots = {
  3.     SHEARS = 1,
  4.     BONE_MEAL = 4,
  5.     PETALS= 13,
  6.     FLOWERS = 16
  7. }
  8.  
  9. -- places petal
  10. local function placePetal()
  11.     turtle.select(Slots.PETALS)
  12.     turtle.place()
  13. end
  14.  
  15. -- bone meals 1 time
  16. local function boneMeal()
  17.     turtle.select(Slots.BONE_MEAL)
  18.     if tool.lookAtBlock() ~= nil then
  19.         turtle.place()
  20.     end
  21. end
  22.  
  23. -- shears using automata
  24. local function shearFlower()
  25.     turtle.select(Slots.SHEARS)
  26.     tool.digBlock()
  27.     turtle.suck()
  28. end
  29.  
  30. -- dumps flowers
  31. local function dumpFlower()
  32.     turtle.select(Slots.FLOWERS)
  33.     turtle.dropUp()
  34. end
  35.  
  36. -- main function
  37. local function main()
  38.     placePetal()
  39.     boneMeal()
  40.     shearFlower()
  41.     dumpFlower()
  42. end
  43.  
  44. -- checks turtle supplies, returns false if out of any resource
  45. counter = 0
  46. local function checkSupplies()
  47.     ready = true
  48.  
  49.     -- clears screen
  50.     term.clear()
  51.     term.setCursorPos(1,1)
  52.    
  53.     turtle.select(Slots.SHEARS)
  54.     if turtle.getItemCount() == 0 then
  55.         print("Shears Broke! Put new Shears in slot '" .. Slots.SHEARS .. "'")
  56.         ready = false
  57.     end
  58.  
  59.     turtle.select(Slots.BONE_MEAL)
  60.     if turtle.getItemCount() <= 1 then
  61.         -- request bonemeal
  62.         print("Refill bonemeal in slot '" .. Slots.BONE_MEAL .. "'")
  63.         ready = false
  64.     end
  65.  
  66.     turtle.select(Slots.PETALS)
  67.     if turtle.getItemCount() <= 0 then
  68.         counter = counter+1
  69.         print("Put petals to harvest in slot '" .. Slots.PETALS .. "'")
  70.         if counter > 10 then
  71.             ready = false
  72.         end
  73.     else
  74.         counter = 0
  75.         item = turtle.getItemDetail()
  76.         for k,v in pairs(item) do
  77.             if string.find(v, "double_flower") then
  78.                 turtle.dropUp()
  79.                 os.sleep(.2)
  80.             end
  81.         end
  82.     end
  83.     return ready
  84.  
  85. end
  86.  
  87. -- while loop
  88. while true do
  89.     if checkSupplies() then
  90.         main()
  91.     else
  92.         print("Waiting...")
  93.         os.sleep(5)
  94.     end
  95. end
Add Comment
Please, Sign In to add comment