AlphaSheepPig

CC Turtle Lava Level Miner

Jun 27th, 2013
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.39 KB | None | 0 0
  1. --[[
  2. A sub-lava level miner
  3. by Alphanumeric Sheep Pig
  4.  
  5. A branch mining program that
  6. mines a 2 high branch mine in a roughly
  7. 100x100 block area to the front and left.
  8.  
  9. It places torches along the way, builds a
  10. floor, ceiling and walls, turns any lava
  11. to obsidian, can handle sand and gravel,
  12. and places a chest and offloads its
  13. inventory along the way when full.
  14.  
  15. Before use, give the turtle the following:
  16. Slot 1: Coal
  17. Slot 2: Cobblestone
  18. Slot 3: Chests
  19. Slot 4: Torches
  20. Slot 5: Water bucket
  21. ]]
  22.  
  23. ----------------------------------------------------------------------------------
  24.  
  25. -- Save starting coords to keep track of location
  26.  
  27. x = 0  -- positive right
  28. y = 0  -- positive forward
  29. z = 0  -- positive up
  30. f = 0  -- number of left turns required to return to original direction
  31.  
  32.  
  33. ----------------------------------------------------------------------------------
  34.  
  35. -- Functions to replace basic movement commands with shortcuts that keep track of direction
  36.  
  37. function up()
  38.     if turtle.up() then
  39.         z=z+1
  40.         return true
  41.     else
  42.         turtle.digUp()
  43.         return false
  44.     end
  45. end
  46.  
  47. function down()
  48.     if turtle.down() then
  49.         z=z-1
  50.         return true
  51.     else
  52.         return false
  53.     end
  54. end
  55.  
  56. function forward()
  57.     if turtle.forward() then
  58.         if     f==0 then y=y+1
  59.         elseif f==1 then x=x+1
  60.         elseif f==2 then y=y-1
  61.         elseif f==3 then x=x-1
  62.         end
  63.         return true
  64.     else
  65.         return false
  66.     end
  67. end
  68.  
  69. function back()
  70.     if turtle.back() then
  71.         if     f==0 then y=y-1
  72.         elseif f==1 then x=x-1
  73.         elseif f==2 then y=y+1
  74.         elseif f==3 then x=x+1
  75.         end
  76.         return true
  77.     else
  78.         return false
  79.     end
  80. end
  81.  
  82. function left()
  83.     if turtle.turnLeft() then
  84.         f = f+1
  85.         while f > 3 do
  86.             f = f-4
  87.         end
  88.         return true
  89.     else
  90.         return false
  91.     end
  92. end
  93.  
  94. function right()
  95.     if turtle.turnRight() then
  96.         f = f-1
  97.         while f < 0 do
  98.             f = f+4
  99.         end
  100.         return true
  101.     else
  102.         return false
  103.     end
  104. end
  105.  
  106.  
  107. function forwardDist()
  108.     return x+y
  109. end
  110.  
  111. ----------------------------------------------------------------------------------
  112.  
  113. -- Basic actions
  114.  
  115. function dig()
  116.     turtle.select(2)
  117.     repeat
  118.         turtle.dig()
  119.         sleep(0.7)
  120.     until forward()
  121.     back()
  122. end
  123.  
  124.  
  125. function placeTorch()
  126.     left()
  127.     left()
  128.     turtle.select(4)
  129.     turtle.place()
  130.     left()
  131.     left()
  132. end
  133.  
  134.  
  135. function placeCobble()
  136.     turtle.select(2)
  137.     turtle.place()
  138. end
  139.  
  140. function placeCobbleUp()
  141.     turtle.select(2)
  142.     turtle.placeUp()
  143. end
  144.  
  145. function placeCobbleDown()
  146.     turtle.select(2)
  147.     turtle.placeDown()
  148. end
  149.  
  150. function placeCobbleSides()
  151.     left()
  152.     placeCobble()
  153.     right()
  154.     right()
  155.     placeCobble()
  156.     left()
  157. end
  158.  
  159.  
  160. function fuel()
  161.     if turtle.getFuelLevel() < 50 then
  162.         turtle.select(1)
  163.         turtle.refuel(1)
  164.     end
  165. end
  166.  
  167. function waterAhead()
  168.     dig()
  169.     turtle.select(5)
  170.     if turtle.place() == false then
  171.         exit()
  172.     end
  173.     turtle.place()
  174. end
  175.  
  176. function waterHere()
  177.     back()
  178.     waterAhead()
  179.     forward()
  180. end
  181.  
  182. function fixheight()
  183.     while z>0 do
  184.         print("In the wrong Place")
  185.         back()
  186.         down()
  187.     end
  188. end    
  189.  
  190. function faceFront()
  191.     while f > 0 do    
  192.         left()
  193.     end
  194. end
  195.  
  196. function reset()
  197.     faceFront()
  198.     fixheight()
  199. end
  200.  
  201. function noWalls()
  202.     placeCobbleDown()
  203.     up()
  204.     placeCobbleUp()
  205.     down()
  206. end
  207.  
  208. function walls()
  209.     placeCobbleDown()
  210.     placeCobbleSides()
  211.     up()
  212.     placeCobbleUp()
  213.     placeCobbleSides()
  214.     down()
  215. end
  216.  
  217. function doubleWater()
  218.     waterAhead()
  219.     up()
  220.     waterAhead()
  221.     -- waterHere()
  222.     down()
  223. end
  224.  
  225. function tunnel()
  226.     forward()
  227.     walls()
  228.     doubleWater()
  229. end
  230.  
  231. function wallFront()
  232.     placeCobble()
  233.     up()
  234.     placeCobble()
  235.     down()
  236. end
  237.  
  238. function tunnelWithoutWalls()
  239.     forward()
  240.     noWalls()
  241.     doubleWater()
  242. end
  243.  
  244.  
  245. function offload()
  246.     up()
  247.     waterHere()
  248.     down()
  249.     back()
  250.     left()
  251.     tunnelWithoutWalls()
  252.     tunnelWithoutWalls()
  253.     wallFront()
  254.     back()
  255.     turtle.select(3)
  256.     turtle.place()
  257.     for slot = 6,16,1 do
  258.         turtle.select(slot)
  259.         turtle.drop()
  260.     end    
  261.     turtle.select(2)
  262.     right()
  263. end
  264.  
  265.  
  266. function checkInventory()
  267.     for slot = 1,5,1 do
  268.         if turtle.getItemCount(slot) == 0 then
  269.             print("Out of materials")
  270.             exit()
  271.         end
  272.     end
  273.     if turtle.getItemCount(16) > 0 then
  274.         offload()
  275.     end
  276. end
  277.    
  278. ----------------------------------------------------------------------------------
  279.  
  280. -- Advanced functions
  281.  
  282. function branch(l)
  283.     for i = 1,l,1 do
  284.         fuel()
  285.         tunnel()
  286.         fixheight()
  287.         if forwardDist()%13==0 then
  288.             placeTorch()
  289.         end
  290.         checkInventory()
  291.         print("Moved: ",x," left, ",y," forward, ",z," up.")
  292.         print()
  293.     end
  294. end
  295.  
  296.  
  297. function mine(n,m)
  298.     branch(n)
  299.     wallFront()
  300.     left()
  301.     tunnelWithoutWalls()
  302.     branch(m)
  303.     wallFront()
  304.     left()
  305.     tunnelWithoutWalls()
  306.     branch(n)
  307.     wallFront()
  308.     right()
  309.     tunnelWithoutWalls()
  310.     branch(m)
  311.     wallFront()
  312.     right()
  313.     tunnelWithoutWalls()
  314. end
  315.  
  316.  
  317. for i = 1,12,1 do
  318.     mine(100,4)
  319. end
  320.  
  321. print("Done")
Advertisement
Add Comment
Please, Sign In to add comment