Advertisement
Guest User

Miner.lua

a guest
Dec 5th, 2019
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.95 KB | None | 0 0
  1. function digUpDown()
  2.     -- Dig up
  3.     if turtle.detectUp() then
  4.         turtle.digUp()
  5.     end
  6.     -- Dig down
  7.     if turtle.detectDown() then
  8.         turtle.digDown()
  9.     end
  10. end
  11. function digAndMove()
  12.     if turtle.detect() then
  13.         turtle.dig()
  14.     end
  15.     digUpDown()
  16.     turtle.forward()
  17. end
  18. function placeTorch(forward)
  19.     turtle.select(2)
  20.     if forward == true then
  21.         if turtle.detect() then
  22.             turtle.dig()
  23.         end
  24.         turtle.place()
  25.     else
  26.         if turtle.detectDown() then
  27.             turtle.digDown()
  28.         end
  29.         turtle.placeDown()
  30.     end
  31. end
  32. function mineAdjacent(torch, torchSide)
  33.     digAndMove()
  34.    
  35.     turtle.turnLeft()
  36.     digAndMove()
  37.     if torch == true and torchSide == 3 then
  38.         placeTorch(false)
  39.     end
  40.     digAndMove()
  41.     if torch == true and torchSide == 1 then
  42.         placeTorch(true)
  43.     end
  44.     turtle.turnRight()
  45.     digAndMove()
  46.     turtle.turnRight()
  47.     digAndMove()
  48.     digAndMove()
  49.     digUpDown()
  50.     if torch == true and torchSide == 0 then
  51.         placeTorch(true)
  52.     end
  53.     turtle.turnLeft()
  54. end
  55. -- Command Line Arguments
  56. tArg = {...}
  57. local len = 0
  58. local torchSide = 0 -- 0=left 1=right 3=under 4=nothing
  59. if #tArg == 0 then
  60.     print("Slot #1 Coal, Slot #2 Torch")
  61.     print("Torches on right side default")
  62.     print("Input Mining Dimension")
  63.     len = io.read()
  64. else
  65.     if #tArg >= 1 then
  66.         len = tonumber(tArg[1])
  67.     end
  68.     if #tArg >= 2 then
  69.         torchSide = tonumber(tArg[2])
  70.     end
  71. end
  72. local coalUsed = 1;
  73. turtle.select(1)
  74. turtle.refuel(1)
  75. for i=1, len do
  76.     print("Mining adjacent!")
  77.     if i % 2 == 0 then
  78.         mineAdjacent(true, torchSide)
  79.     else
  80.         mineAdjacent(false, 0)
  81.     end
  82.     if turtle.getFuelLevel() == 1 then
  83.         print("Refueling")
  84.         turtle.select(1)
  85.         turtle.refuel(4)
  86.         coalUsed = coalUsed + 1
  87.     end
  88. end
  89. print("Total coal spent: ", coalUsed)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement