Advertisement
RinRoxy

chunk_mining

Aug 25th, 2022 (edited)
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.56 KB | Gaming | 0 0
  1. -- Meant for clearing one chunk using one mining turtle. (Runs on both normal and advanced mining turtles)
  2. -- Turtle will mine a 16x16 Minecraft chunk, starting from the bottom left corner of the chunk.
  3. -- Recommend to feed blocks of coal/charcoal so that the turtle will not run out of fuel while digging through one chunk
  4. -- Place a chest on top of the starting position of the turtle to collect items
  5. -- Turtle should equip shovel and pickaxe to prevent inability to dig through dirts
  6.  
  7. refuelLevel = 300
  8. chunk = 16
  9.  
  10. function refuel()
  11.     -- Get fuel in slot 1
  12.     turtle.select(1)
  13.  
  14.     -- Check to make sure it is a fuel
  15.     if turtle.refuel(0) then
  16.         -- Only refuel if it is lower than a certain point
  17.         if turtle.getFuelLevel() < refuelLevel then
  18.             turtle.refuel(4)
  19.         end
  20.     else
  21.         print("Turtle cannot refuel")
  22.     end
  23. end
  24.  
  25. function dig()
  26.     -- Dig the block below it
  27.     if turtle.detectDown() then
  28.         turtle.digDown()
  29.         sleep(0.5)
  30.     end
  31. end
  32.  
  33. function row()
  34.     -- Dig one row
  35.     for count=1, chunk, 1 do
  36.         dig()
  37.  
  38.         if (count ~= chunk) then
  39.             turtle.forward()
  40.         end
  41.     end
  42. end
  43.  
  44. function layer()
  45.     -- Dig one layer
  46.     for count=1, chunk, 1 do
  47.         row()
  48.  
  49.         if (count ~= chunk) then
  50.             if (count%2 == 0) then
  51.                 turtle.turnLeft()
  52.                 turtle.forward()
  53.                 turtle.turnLeft()
  54.             else
  55.                 turtle.turnRight()
  56.                 turtle.forward()
  57.                 turtle.turnRight()
  58.             end
  59.         end
  60.     end
  61.  
  62.     -- Return to start
  63.     turtle.turnRight()
  64.     for count=1, chunk-1, 1 do
  65.         turtle.forward()
  66.     end
  67. end
  68.  
  69. -- Main
  70. print("Start the program? (y/n)")
  71. start = io.read()
  72.  
  73. if (start == "y") then
  74.     print("How far down?")
  75.     distance = tonumber(io.read())
  76.  
  77.     -- Mine according to the distance given
  78.     for i=1, distance, 1 do
  79.         refuel()
  80.         layer()
  81.  
  82.         -- Move back to the chest
  83.         for up=1, i, 1 do
  84.             if (up ~= i) then
  85.                 turtle.up()
  86.             end
  87.         end
  88.  
  89.         -- Put everything in the turtle inventory into the chest
  90.         for inv=2, 16, 1 do
  91.             turtle.select(inv)
  92.             turtle.dropUp()
  93.         end
  94.  
  95.         if (i == distance) then
  96.             break
  97.         end
  98.  
  99.         turtle.turnRight()
  100.  
  101.         -- Move back to previous position
  102.         for down=1, i+1, 1 do
  103.             if (down ~= i) then
  104.                 turtle.down()
  105.             end
  106.         end
  107.     end
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement