Advertisement
Guest User

Miner.lua

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