Advertisement
DabDaddy6223

minetorch2.lua

Mar 6th, 2023
65
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.             print(current["name"])
  8.             if current["name"] == item then
  9.                 return i
  10.             end
  11.         end
  12.     end
  13.  
  14.     return -1
  15. end
  16.  
  17. function refuel()
  18.     if turtle.getFuelLevel() == 0 then
  19.         for i = 1, 16 do
  20.             turtle.select(i)
  21.             if turtle.refuel(0) then
  22.                 return true
  23.             end
  24.         end
  25.  
  26.         print("No fuel found!")
  27.         return false
  28.     else
  29.         return true
  30.     end
  31. end
  32.  
  33. function goBack(distance)
  34.     turtle.turnLeft()
  35.     turtle.turnLeft()
  36.  
  37.     for _ = 1, distance do
  38.         turtle.forward()
  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