Advertisement
DabDaddy6223

minetorch3.lua

Mar 6th, 2023
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | None | 0 0
  1. MaxTorchDistance = 14
  2.  
  3. function getIndexOf(item)
  4.     for i = 1, 16 do
  5.         local current = turtle.getItemDetail(i, false)
  6.         if current ~= nil then
  7.             if current["name"] == item then
  8.                 return i
  9.             end
  10.         end
  11.     end
  12.  
  13.     return -1
  14. end
  15.  
  16. function refuel()
  17.     if turtle.getFuelLevel() == 0 then
  18.         for i = 1, 16 do
  19.             turtle.select(i)
  20.             if turtle.refuel(0) then
  21.                 return true
  22.             end
  23.         end
  24.  
  25.         print("No fuel found!")
  26.         return false
  27.     else
  28.         return true
  29.     end
  30. end
  31.  
  32. function goBack(distance)
  33.     turtle.turnLeft()
  34.     turtle.turnLeft()
  35.  
  36.     while distance > 0 do
  37.         turtle.forward()
  38.         distance = distance - 1
  39.     end
  40. end
  41.  
  42. function mineVerticalStrip()
  43.     turtle.dig()
  44.     turtle.forward()
  45.     turtle.digDown()
  46.     turtle.digUp()
  47. end
  48.    
  49. function main()
  50.     local distance = 0
  51.     local torchDistance = 0
  52.     local indexOfTorches = getIndexOf("minecraft:torch")
  53.  
  54.     if indexOfTorches == -1 then
  55.         print("No torches found!")
  56.         return
  57.     end
  58.  
  59.     if indexOfTorches ~= 1 then
  60.         turtle.select(indexOfTorches)
  61.         turtle.transferTo(1)
  62.     end
  63.  
  64.     while true do
  65.         if refuel() then
  66.             indexOfTorches = getIndexOf("minecraft:torch")
  67.             if indexOfTorches == -1 then
  68.                 print("Ran out of torches!")
  69.                 break
  70.             end
  71.  
  72.             mineVerticalStrip()
  73.             distance = distance + 1
  74.  
  75.             torchDistance = torchDistance + 1
  76.             if torchDistance == MaxTorchDistance then
  77.                 turtle.placeDown()
  78.                 torchDistance = 0
  79.             end
  80.  
  81.             turtle.turnRight()
  82.             mineVerticalStrip()
  83.  
  84.             turtle.turnLeft()
  85.             turtle.turnLeft()
  86.             turtle.forward()
  87.  
  88.             mineVerticalStrip()
  89.             turtle.turnRight()
  90.             turtle.turnRight()
  91.             turtle.forward()
  92.             turtle.turnLeft()
  93.         else
  94.             print("Ran out of fuel!")
  95.             break
  96.         end
  97.     end
  98.  
  99.     if distance ~= 0 then
  100.         goBack()
  101.     end
  102. end
  103.  
  104. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement