Advertisement
Guest User

mine

a guest
Aug 21st, 2019
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.05 KB | None | 0 0
  1. local realDepth = 0
  2. local rightTurn = true --If turning right will face the turtle in the right direction
  3. local oneHigh = false
  4.  
  5. local xDistance = 0
  6. local yDistance = 0
  7. local zDistance = 0
  8.  
  9.  
  10. function initialColumn(depth) --Dig the initial column. Digs down either until it reaches depth, or it can't go down
  11.     for i = 1,depth do
  12.         turtle.digDown()
  13.         if turtle.down() then
  14.             realDepth = i
  15.             zDistance = zDistance + 1
  16.         else --If it cant go down, it adjusts what realDepth is (How deep the turtle can go)
  17.             print("Hit the end! i:")
  18.             print(i)
  19.                     realDepth = i - 1
  20.             break
  21.         end
  22.     end
  23.     for i = 1,realDepth do --Return to surface
  24.         turtle.up()
  25.         zDistance = zDistance - 1
  26.     end
  27. end
  28.  
  29. function turnaround()
  30.     turtle.turnLeft()
  31.     turtle.turnLeft()
  32. end
  33.  
  34. function empty() --Empties inventory starting at slot 16
  35.     turnaround()
  36.     for i = 16,1,-1 do
  37.         turtle.select(i)
  38.         turtle.drop()
  39.     end
  40.  turnaround()
  41. end
  42.  
  43. function digSlab(twoHigh, size)
  44.     for x = 1,size do --Dimensions of the slab
  45.         for y = 1,size do  
  46.            
  47.             if (y == size) and not (x == size) then --When we hit the end
  48.                 if rightTurn then
  49.                     turtle.turnRight()
  50.                 else
  51.                     turtle.turnLeft()
  52.                 end
  53.                 digBlock()
  54.                 turtle.forward()
  55.                 if twoHigh then --If we need to dig two high
  56.                     digUp()
  57.                 end
  58.                 if rightTurn then
  59.                     turtle.turnRight()
  60.                 else
  61.                     turtle.turnLeft()
  62.                 end
  63.                 rightTurn = not rightTurn --Change which direction to turn next time. This way the turtle will snake around
  64.             else if not x == size then
  65.                 digBlock()
  66.                 turtle.forward() --Goes forward  
  67.                 if twoHigh then --If we have to dig two high, also dig upwards
  68.                     digUp()
  69.                 end            
  70.             end
  71.            
  72.             --Now we decide if we want to dig out whats above us or below us
  73.            
  74.             if not twoHigh then --If we wont be digging up anyways
  75.                 local success,data = turtle.inspectUp()
  76.                 if (not data.name == "minecraft:stone") and (not data.name == "minecraft:dirt") then --If its not dirt or stone above,
  77.                     digUp() --Do the normal digup routine
  78.                 end
  79.             end
  80.             --Do a similar thing, but below
  81.             local success,data = turtle.inspectDown()
  82.             if (not data.name == "minecraft:stone") and (not data.name == "minecraft:dirt") then
  83.                 turtle.digDown()
  84.             end
  85.            
  86.         end
  87.         if x == size then
  88.             print("Done slab! Now figure out returning to origin")
  89.             --Returning to origin
  90.             if not rightTurn then --Face the correct direction
  91.                 turtle.turnRight()
  92.             else
  93.                 turtle.turnLeft()
  94.             end
  95.            
  96.             --March on back
  97.             for x = 1, size do
  98.                 turtle.forward()
  99.             end
  100.            
  101.             if not rightTurn then --Face back towards the front
  102.                 turtle.turnRight()
  103.             else
  104.                 turtle.turnLeft()
  105.             end
  106.            
  107.         end
  108.     end
  109. end
  110.  
  111. function digBlock()
  112.     local success,data = turtle.inspect()
  113.     if (data.name == "minecraft:sand") or (data.name == "minecraft:gravel") then --If theres sand or gravel in front of the turtle
  114.         while turtle.dig() do --Dig as long as you can
  115.         end
  116.     end
  117.     turtle.dig() --Try to dig, even if nothing can fall in front of it
  118. end
  119.  
  120. function digUp()
  121.     turtle.digUp() --Dig at first
  122.     local success,data = turtle.inspectUp()
  123.     if (data.name == "minecraft:sand") or (data.name == "minecraft:gravel") then --If theres sand or gravel above the turtle now
  124.         while turtle.digUp() do --Dig as long as you can
  125.         end
  126.     end
  127. end
  128.  
  129. initialColumn(4)
  130. empty()
  131. turtle.down()
  132. digSlab(not oneHigh, 6)
  133. empty()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement