Advertisement
Guest User

Minecraft Turtle - 3 Field Stripmining

a guest
Feb 14th, 2016
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 KB | None | 0 0
  1. -- MC Turtle Stripmining Program
  2. ----------------------------------------------------------
  3.  
  4. -- Variables
  5. ----------------------------------------------------------
  6. glength = 0
  7. gwidth = 0
  8. cnt = 0
  9. scnt = 1
  10.  
  11. -- Dialoge
  12. ----------------------------------------------------------
  13. write("Length: ")
  14. glength = tonumber(read())
  15.  
  16. write("Width: ")
  17. gwidth = tonumber(read())
  18.  
  19. -- Function: refill
  20. ----------------------------------------------------------
  21. function refill()
  22.   for idx = 1,16 do
  23.     turtle.select(idx)
  24.     turtle.refuel()
  25.   end
  26.     turtle.select(1)
  27. end
  28.  
  29. -- Function: torch (Places a Torch)
  30. ----------------------------------------------------------
  31. function torch(mode)
  32.   turtle.select(16)
  33.  
  34.   if mode == 2 then
  35.     turtle.place()
  36.   else
  37.     turtle.placeDown()
  38.   end
  39.  
  40.   turtle.select(1)
  41. end
  42.  
  43. -- Function: turn180 (Turn 180 Deg)
  44. ----------------------------------------------------------
  45. function turn180()
  46.   turtle.turnRight()
  47.   turtle.turnRight()
  48. end
  49.  
  50. -- Function: step (Makes one digging step forward)
  51. ----------------------------------------------------------
  52. function step(mode)
  53.  
  54.   if mode == 2 then
  55.  
  56.     while turtle.detectUp() do
  57.       turtle.digUp()
  58.       sleep(0.5)
  59.     end
  60.  
  61.     while turtle.detectDown() do
  62.       turtle.digDown()
  63.     end
  64.  
  65.   end
  66.  
  67.   while (not turtle.forward()) do
  68.     turtle.dig()
  69.   end
  70.  
  71.   while turtle.detectDown() do
  72.     turtle.digDown()
  73.   end
  74.  
  75.   while turtle.detectUp() do
  76.     turtle.digUp()
  77.     sleep(0.5)
  78.   end
  79.  
  80.  
  81. end
  82.  
  83. -- Function: halfstrip (Digs one Strip side)
  84. ----------------------------------------------------------
  85. function halfstrip(lwidth)
  86.   flag = false
  87.  
  88.   lcnt = 1
  89.   while (lcnt < lwidth) do
  90.     step(2)
  91.     lcnt = lcnt + 1
  92.   end
  93.   lcnt = 1
  94.   while (lcnt < lwidth) do
  95.     while (not turtle.back()) do
  96.       sleep(0.5)
  97.     end
  98.     if (not flag) then
  99.       torch(2)
  100.       flag = true
  101.     end
  102.     lcnt = lcnt + 1
  103.   end
  104. end
  105.  
  106. -- Function: strip (Digs the complete Strip)
  107. ----------------------------------------------------------
  108. function strip(gwidth)
  109.     turtle.turnRight()
  110.       halfstrip(gwidth)
  111.     turtle.turnLeft()
  112.  
  113.     turtle.turnLeft()
  114.       halfstrip(gwidth)
  115.     turtle.turnRight()
  116. end
  117.  
  118.  
  119. -- MAIN FUNCTION
  120. ----------------------------------------------------------
  121. while (cnt<glength) do
  122.  
  123.   if turtle.getFuelLevel() < 1 then
  124.     refill()
  125.   end
  126.   if turtle.getFuelLevel() < 1 then
  127.     write ("Not enough fuel!")
  128.     return
  129.   end
  130.  
  131.   step(1)
  132.  
  133.   if (scnt >= 3) then
  134.     strip(gwidth)
  135.     torch(1)
  136.     scnt = 0
  137.   else
  138.     scnt = scnt + 1
  139.   end
  140.  
  141.   cnt = cnt + 1
  142.  
  143. end
  144.  
  145. write ("Mission completed.")
  146. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement