Advertisement
anansii

berrypicker

Jan 24th, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.55 KB | None | 0 0
  1. -- Berrypicker
  2. -- 2015-01-24
  3.  
  4. ------------------------------------------------------
  5.  
  6. -- Farm Setup
  7. -- top
  8. --  BB..BB
  9. -- CEE..ETC
  10. --  DD..DI
  11.  
  12. -- front
  13. --CBB..BBC
  14. --CBB..BBC
  15. --CDD..DIC
  16.  
  17. -- C Cobblestone
  18. -- D dirt
  19. -- B Bush
  20. -- I chest
  21.  
  22. -- ID string constants
  23. WOOD = "minecraft:log"
  24. DIRT = "minecraft:dirt"
  25. GRASS = "minecraft:grass"
  26. COBBLE = "minecraft:cobblestone"
  27. SAPLING = "minecraft:sapling"
  28. LEAVES = "minecraft:leaves"
  29. APPLE = "minecraft:sapling"
  30. BONEMEAL = "minecraft:dye" -- with damage/meta 15
  31. CHEST = "minecraft:chest"
  32.  
  33. function contains(where, what)
  34.         return string.find(string.lower(where), what)
  35. end
  36.  
  37. function safeForward()
  38.         turtle.suck()
  39.         while not turtle.forward() do
  40.                 if not turtle.inspect() then
  41.                         turtle.dig()
  42.         else
  43.             return false
  44.                 end
  45.         end
  46.         turtle.suck()
  47.     return true
  48. end
  49.  
  50. function getInPosition()
  51.         print("Getting in position, looking for chest")
  52.         -- assuming we are not positioned correctly
  53.         local onGround = false
  54.         local atChest = false
  55.  
  56.         -- get down first
  57.         while not onGround do
  58.                 local success, data = turtle.inspectDown()
  59.                 if success then
  60.                         print("Found: ", data.name)            
  61.                         if data.name == DIRT or data.name == GRASS then
  62.                                 print("Must be on on the ground")              
  63.                                 onGround = true
  64.                         else
  65.                                 turtle.digDown()
  66.                                 turtle.down()
  67.                         end            
  68.                 else
  69.                         print("Must be in the air")                            
  70.                         turtle.down()
  71.                 end
  72.         end
  73.  
  74.         -- now find the chest
  75.         while not atChest do
  76.                 local success, data = turtle.inspect()
  77.                 if success then
  78.                         if data.name == COBBLE then
  79.                                 print("Seeing the stone, turning right")
  80.                                 turtle.turnRight()
  81.                         elseif data.name == DIRT then
  82.                                 print("Seeing dirt, turning left")
  83.                                 turtle.turnRight()
  84.                         elseif contains(data.name, "bush") then
  85.                                 print("Seeing the bush, turning right")
  86.                                 turtle.turnRight()
  87.                         elseif contains(data.name, "chest") then
  88.                                 print("Seeing the chest..")
  89.                                 print("Position reached")
  90.                                 atChest = true
  91.                         end
  92.                 else
  93.                         print("Nothing in front, moving")
  94.                         safeForward()
  95.                 end
  96.         end
  97.  
  98. end
  99.  
  100. function dropOff()
  101.         for i = 1, 16, 1 do
  102.                 turtle.select(i)
  103.                 turtle.drop()
  104.     end
  105. end
  106.  
  107. function pickBush()
  108.     turtle.suck()
  109.     turtle.up()
  110.     turtle.suck()
  111.     turtle.up()
  112.     turtle.suck()
  113.     turtle.down()
  114.     turtle.down()
  115. end
  116.  
  117. getInPosition()
  118. dropOff()
  119.  
  120. while true do
  121.     turtle.turnRight()
  122.    
  123.     while not turtle.inspect() do
  124.         safeForward()
  125.     end
  126.  
  127.     turtle.turnRight()
  128.    
  129.     local canMoveRight = true
  130.     while canMoveRight do
  131.         pickBush()
  132.         turtle.turnRight()
  133.         canMoveRight = safeForward()
  134.         turtle.turnLeft()
  135.     end
  136.     turtle.turnRight()
  137.     turtle.turnRight()
  138.     dropOff()
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement