Animum

Digtunel

Oct 19th, 2020
1,488
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --Autor Animum
  2. --Program version beta 1
  3. --turtle excavates a tunnel of
  4. --width 1 and height 3
  5. --turtle can lay torches
  6. --turtle can put a block under the torch
  7. --Minecraft version 1.16.3
  8. --Forge version 34.1.18
  9. --CCTweaked version 1.93.0
  10. --The program can adapt
  11. --to the turtle version - normal/advanced
  12. --slot 1 - torch
  13. --slot 2 - block under the torch
  14. --example code : Digtunel [number > 1 -length tunel]
  15. -- [torch place - number 0/nill - no / number 1 - yes]
  16. -- Digtunel 15 0
  17. if term.isColor() then
  18.  term.setTextColour(colors.lime)
  19. end
  20. local tArgs = { ... }
  21. Length = tonumber( tArgs[1] )
  22. Torch = tonumber( tArgs[2] )
  23. Lpos = 1 --Lenght position
  24. Err = 0 --error
  25. TT = 0 --torch time
  26. --displays status to the screen
  27. --Mined : [Position] Fuel : [turtlefuelstatus]
  28. function Status (Lpos)
  29.  term.clear()
  30.  term.setCursorPos(1,1)
  31.  term.write("Mined : ")
  32.  term.write(Lpos)
  33.  term.write(" Fuel : ")
  34.  term.write(turtle.getFuelLevel())
  35. end
  36. --turtle excavated space in front of him,
  37. --if there is something
  38. --and moves forward
  39. function Dfr ()
  40.  while turtle.detect() do
  41.   turtle.dig()
  42.   sleep(0.1)
  43.  end
  44.  turtle.forward()
  45. end
  46. --turtle excavated space in above of him,
  47. --if there is something
  48. function Dup ()
  49.  while turtle.detectUp() do
  50.   turtle.digUp()
  51.   sleep(0.1)
  52.  end
  53. end
  54. --turtle excavated space in under of him,
  55. --if there is something
  56. function Ddo ()
  57.  while turtle.detectDown() do
  58.   turtle.digDown()
  59.   sleep(0.1)
  60.  end
  61. end
  62. --laying torches
  63. function Pltorch()
  64.  turtle.select(1)
  65.  if not turtle.placeDown()
  66.  then
  67.   turtle.down()
  68.   turtle.select(2)
  69.   sleep(0.1)
  70.   turtle.placeDown()
  71.   sleep(0.1)
  72.   turtle.up()
  73.   turtle.select(1)
  74.   sleep(0.1)
  75.   turtle.placeDown()
  76.  end
  77. end
  78. --displays status to the screen
  79. function Sterror (Err)
  80.  term.clear()
  81.  term.setCursorPos(1,1)
  82. --no error
  83.  if Err == 0
  84.  then
  85.   if term.isColor() then
  86.   term.setTextColour(colors.lime)
  87.   end
  88.   term.write("done")
  89.  elseif Err == 1
  90.  then
  91.   if term.isColor() then
  92.   term.setTextColour(colors.red)
  93.   end
  94.   term.write("No fuel")
  95.  else
  96.   if term.isColor() then
  97.   term.setTextColour(colors.orange)
  98.   end
  99.   term.write("Unknown error")
  100.  end
  101. end
  102. --main program
  103. --turtle fuel level > 10000?
  104. if turtle.getFuelLevel() > 10000
  105. then
  106. --main loop
  107.  for Lpos=1,Length,1 do
  108.   if turtle.getFuelLevel() < 100
  109.   then break end
  110.   Dfr()
  111.   sleep(0.1)
  112.   Dup()
  113.   sleep(0.1)
  114.   Ddo()
  115.   sleep(0.1)
  116. --place torch every 5 blocks
  117.   if Torch == 1
  118.   then
  119.    if TT < 4
  120.    then
  121.     TT = TT + 1
  122.    else
  123.     Pltorch()
  124.     TT = 0
  125.    end
  126.   end
  127.   sleep(0.1)
  128.   Status(Lpos)
  129.   sleep(0.1)
  130.  end
  131.  if turtle.getFuelLevel() < 100
  132.  then
  133. --error end - no fuel
  134.   Sterror(1)
  135.  else
  136. --normal end
  137.   Sterror(0)
  138.  end
  139. else
  140. --error end - no fuel
  141.  Sterror(1)
  142. end
RAW Paste Data