Advertisement
BlakeDarwinXE

CC - Turtle API

Oct 14th, 2013
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. --Turtle configuration
  2. refuel_level = 600
  3.  
  4. --Turtle slot configuration
  5. fuel_slot = 16
  6. fuel_ender_chest_slot = 15
  7. sorting_ender_chest_slot = 14
  8. max_mining_slot = 13
  9.  
  10. --Varables setup for funcition use later. do not change.
  11. oporation_type = 0 --(0 = dig, 1 = place)
  12. slot = 1 --(Default is set to 1, slot to use placing blocks)
  13. length = 0 --(Default is set to 0 for testing to know if user need to enter a valid length)
  14. width = 0  --(Default is set to 0 for testing to know if user need to enter a valid width)
  15.  
  16.  
  17. function sand_test()
  18.     --Test is there is anything in the way of moving forward
  19.     --Loop to test for blocks that fall like sand or gravel
  20.     while turtle.detect() do
  21.         turtle.dig()
  22.     end
  23. end
  24.  
  25.  
  26. function go_forward()
  27. --Moving the turtle forward
  28.     refuel_turtle()
  29.     sand_test()
  30.     turtle.forward()
  31. end
  32.  
  33. function go_down()
  34.     refuel_turtle()
  35.     turtle.digDown()
  36.     turtle.down()
  37. end
  38.  
  39. function full_inventory_test()
  40. --Test for full inventory
  41.     turtle.select(max_mining_slot) --Last slot for placing items while digging
  42.     full = turtle.getItemCount(max_mining_slot) > 0
  43.     turtle.select(1)
  44.     return full
  45. end
  46.  
  47.  
  48. function refuel_turtle()
  49. --Test fuel level.
  50. --If it is low check for fuel in fuel slot.
  51. --If there is no fuel in fuel slot it places the ender chest and get more fuel
  52.     --Test the current fuel level
  53.     while turtle.getFuelLevel() < refuel_level do
  54.         --Test if there is more then one fuel in
  55.         if turtle.getItemCount(fuel_slot) > 0 then
  56.             turtle.select(fuel_slot)
  57.             turtle.refuel(1)
  58.             else
  59.                 while turtle.detectUp() do
  60.                     turtle.digUp()
  61.                 end
  62.                 turtle.select(fuel_ender_chest_slot)
  63.                 turtle.placeUp()
  64.                 turtle.select(fuel_slot)
  65.                 turtle.suckUp()
  66.                 turtle.select(fuel_ender_chest_slot)
  67.                 turtle.digUp()
  68.         end
  69.     end
  70. end
  71.  
  72.  
  73. function dig_line(length)
  74. -- body
  75. --Even number vs uneven number - based on the number the code with start going left or right.
  76.     for i=1,length do
  77.         go_forward()
  78.     end
  79. end
  80.  
  81. function dig_level(length, width)
  82.     next_turn = 0
  83.     for i=1,width do
  84.         api_turtle.dig_line(length)
  85.         if i == width then
  86.         else
  87.             if next_turn == 0 then
  88.                 turtle.turnLeft()
  89.                 api_turtle.go_forward()
  90.                 turtle.turnLeft()
  91.                 next_turn = 1
  92.             else
  93.                 turtle.turnRight()
  94.                 api_turtle.go_forward()
  95.                 turtle.turnRight()
  96.                 next_turn = 0
  97.             end
  98.         end
  99.     end
  100. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement