gridcaster

Milker

Jul 2nd, 2021 (edited)
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. local cSleepTime=1
  2. local data1, data2
  3.  
  4.  
  5. ---------------------------------------
  6. -- basic functions for turtle control -
  7. ---------------------------------------
  8. local function gf()  while not turtle.forward()   do end end
  9. local function gb()  while not turtle.back()      do end end
  10. local function gu()  while not turtle.up()        do end end
  11. local function gd()  while not turtle.down()      do end end
  12. local function gl()  while not turtle.turnLeft()  do end end
  13. local function gr()  while not turtle.turnRight() do end end
  14. local function df()  turtle.dig()       end
  15. local function du()  turtle.digUp()     end
  16. local function dd()  turtle.digDown()   end
  17. local function pf()  turtle.place()     end
  18. local function pu()  turtle.placeUp()   end
  19. local function pd()  turtle.placeDown() end
  20. local function sf()  return turtle.suck()      end
  21. local function su()  return turtle.suckUp()    end
  22. local function sd()  return turtle.suckDown()  end
  23. local function Df(n) return turtle.drop(n)     end
  24. local function Du()  return turtle.dropUp()    end
  25. local function Dd()  return turtle.dropDown()  end
  26. local function ss(s) turtle.select(s) slotSelected=s  end
  27.  
  28. ---------------------------------------
  29. -- Main
  30. ---------------------------------------
  31. while true do
  32.   ss(1)
  33.   data1 = turtle.getItemDetail()
  34.   print("  slot 1: "..data1.name)
  35.   waitCounter=0
  36.   while true do
  37.     pu()
  38.     data2 = turtle.getItemDetail()
  39.     print("  slot 1: "..data2.name)
  40.     if data1.name~=data2.name then
  41.       -- the bucket should be filled now
  42.       break
  43.     else
  44.       waitCounter=waitCounter+1
  45.       print("No milk today, my love has gone away... I'll retry it after "..(cSleepTime+1)*waitCounter.." seconds.")
  46.       sleep((cSleepTime+1)*waitCounter)
  47.       if waitCounter > 30 then
  48.         print("Error: I retried milking the cow 30 times and had no luck! Please, check set-up (cow,yogurt,bucket...).")
  49.         return
  50.       end
  51.     end
  52.   end
  53.   print("  crafting fresh milk")
  54.   turtle.craft()  -- state 3: 1,4
  55.   ss(2)
  56.   waitCounter=0
  57.   while true do
  58.       if Dd() then
  59.           break
  60.       else
  61.         waitCounter=waitCounter+1
  62.         print("Waiting for inventory space... Waiting for ".. (cSleepTime+1)*waitCounter .. " seconds.")
  63.         sleep((cSleepTime+1)*waitCounter)
  64.       end
  65.   end
  66.   sleep(1)
  67.  
  68. end
  69.  
Add Comment
Please, Sign In to add comment