Demos_

MinecraftLua_BotaniaTurtle

Jan 24th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.06 KB | None | 0 0
  1. -- TurtleBotania
  2.  
  3. -- DEBUG
  4. DEBUG = true
  5.  
  6. if DEBUG then
  7.     print("[[DEBUG] Start of turtleBotania")
  8. end
  9.  
  10. -- setup - path the turtle follow hovering living stone/livingwood
  11. -- [.] = glass: [x] = chest / interface; [p] = pure daisy;
  12. -- > < \/ /\ = path of the turtle
  13. --
  14. -- Top view
  15. --
  16. --       [.][.][.][.][.]
  17. --       [.]    >    [.]
  18. -- [.][.][.] /\[P]\/ [.]
  19. -- [x]    <     <    [.]
  20. -- [.] \/[P] /\[.][.][.]
  21. -- [.]    >    [.]
  22. -- [.][.][.][.][.]
  23. --
  24.  
  25.  
  26. -- slot 1 coal to fuel
  27. -- slot 2 living stone
  28. -- slot 3 living wood
  29. -- slot 4 glass
  30.  
  31. -- make sure coal is available on the chest
  32. -- and to extract livingwood/stone
  33.  
  34. function isItStoneOrWood()
  35.     if DEBUG then
  36.         print("[[DEBUG] Start of isItStoneOrWood")
  37.     end
  38.     res = false
  39.     turtle.select(2)
  40.     res = turtle.compareDown()
  41.     if res then
  42.         return res
  43.     end
  44.     turtle.select(3)
  45.     res = turtle.compareDown()
  46.     return res
  47. end
  48.  
  49. function routine()
  50.     if DEBUG then
  51.         print("[[DEBUG] Start of routine")
  52.     end
  53.     mvt = true
  54.     while mvt do
  55.         mvt = turtle.forward()
  56.         if isItStoneOrWood() then
  57.             turtle.digDown()
  58.         end
  59.     end
  60. end
  61.  
  62. function refuelAndUnload()
  63.     if DEBUG then
  64.         print("[[DEBUG] Start of refuelAndUnload")
  65.     end
  66.     turtle.select(1)
  67.     turtle.suck()
  68.     if (turtle.getItemCount(1) > 7) then
  69.         turtle.refuel(7)
  70.     end
  71.    
  72.     turtle.select(2)
  73.     turtle.drop(turtle.getItemCount(2)-1)
  74.     turtle.select(3)
  75.     turtle.drop(turtle.getItemCount(3)-1)
  76. end
  77.  
  78. function findDaWay()
  79.     if DEBUG then
  80.         print("[[DEBUG] Start of findDaWay")
  81.     end
  82.     -- 1st case the block in front is glass
  83.     --   if the right block is glass path if left
  84.     --   else the path is right
  85.    
  86.     -- 2nd case can't go forward and block in front isn't glass
  87.     -- refuel and unload and path is in the left
  88.     turtle.select(4)
  89.     if turtle.compare() then
  90.         -- check right block
  91.         turtle.turnRight()
  92.         if DEBUG then
  93.             print("[DEBUG] did i bugged here ?")
  94.         end
  95.         if turtle.compare() then
  96.             turtle.turnLeft()
  97.             turtle.turnLeft()
  98.         end
  99.     else
  100.         refuelAndUnload()
  101.         turtle.turnLeft()
  102.     end
  103. end
  104.  
  105. while true do
  106.     routine()
  107.     findDaWay()
  108. end
Advertisement
Add Comment
Please, Sign In to add comment