Advertisement
MatthewJ217

Vertical Strip Mine (CC Turtle)

Nov 18th, 2022 (edited)
1,280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.49 KB | None | 0 0
  1. local distanceLimit = 500;
  2. if arg[2] then distanceLimit = tonumber(arg[2]) end
  3.  
  4. function isFiller(block)
  5.     return block.name == "minecraft:diorite" or block.name == "minecraft:deepslate" or block.name == "minecraft:stone" or block.name == "minecraft:granite" or block.name == "minecraft:cobblestone" or block.name == "minecraft:cobbled_deepslate" or block.name == "minecraft:netherrack"
  6. end
  7.  
  8. function digahole()
  9.     local distance = 0
  10.     local blockLevel = 0
  11.  
  12.     while true do
  13.  
  14.         while turtle.digDown() do
  15.             if blockLevel == 0 then
  16.                 blockLevel = distance
  17.             end
  18.         end
  19.        
  20.         if turtle.getItemCount(16) > 0 then
  21.             for i=1,distance do
  22.                 while turtle.digUp() do end
  23.                 turtle.up()
  24.             end
  25.  
  26.             print("Waiting for items to be unloaded (Press Enter to continue)")
  27.             local eventData = {"key", 0}
  28.             while eventData[2] ~= 257 do eventData = {os.pullEvent("key")} end         
  29.  
  30.             for i=1,distance do
  31.                 while turtle.digDown() do end
  32.                 turtle.down()
  33.             end        
  34.         end
  35.  
  36.         if turtle.getFuelLevel() - 2 < distance then
  37.             for i=1,distance do
  38.                 while turtle.digUp() do end
  39.                 turtle.up()
  40.             end
  41.             while turtle.getFuelLevel() - 2 < distance*2 do
  42.  
  43.             print("Waiting for more fuel (press Enter to continue)")
  44.             local eventData = {"key", 0}
  45.             while eventData[2] ~= 257 do eventData = {os.pullEvent("key")} end         
  46.  
  47.                 for i=1,16 do
  48.                     turtle.select(i)
  49.                     turtle.refuel(64)
  50.                 end
  51.                 turtle.select(1)
  52.             end
  53.             for i=1,distance do
  54.                 while turtle.digDown() do end
  55.                 turtle.down()
  56.             end        
  57.         end
  58.  
  59.         if not turtle.down() then break end
  60.         distance = distance + 1
  61.  
  62.         for i=1,4 do
  63.             turtle.turnLeft()
  64.             local isBlock, block = turtle.inspect();
  65.             if isBlock and not isFiller(block) then
  66.                 turtle.dig()
  67.             end
  68.         end
  69.  
  70.         if distance == distanceLimit then break end
  71.     end
  72.    
  73.     for i=1,distance do
  74.         while turtle.digUp() do end
  75.         turtle.up()
  76.         if distance-i-1 == blockLevel then turtle.placeDown() end
  77.     end
  78. end
  79.  
  80. local step = 0
  81.  
  82. turtle.select(1);
  83.  
  84. for i=1,tonumber(arg[1]) do
  85.     if i>1 then
  86.         step = (step + 1) % 3
  87.         print(tostring(step))
  88.         if step == 0 then
  89.             turtle.forward()
  90.             turtle.turnLeft()
  91.             turtle.forward()
  92.             turtle.forward()
  93.             turtle.turnRight()
  94.         else
  95.             turtle.forward()
  96.             turtle.forward()
  97.             turtle.turnRight()
  98.             turtle.forward()
  99.             turtle.turnLeft()
  100.         end
  101.     end
  102.     digahole()
  103. end
  104. turtle.turnLeft()
  105. for i=1,step do
  106.     turtle.forward()
  107. end
  108. turtle.turnRight()
  109. for i=2,arg[1] do
  110.     turtle.back()
  111.     turtle.back()
  112. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement