dealingwith

Roadbuilder

Jun 17th, 2017
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function fuel()
  2.   if turtle.getFuelLevel() < 30 then
  3.     turtle.select(1)
  4.     if turtle.refuel(1) then
  5.       return true
  6.     end
  7.     print("Refuelling failed.")
  8.     return false
  9.   end
  10. end
  11.  
  12. function right()
  13.   turtle.turnRight()
  14. end
  15.  
  16. function left()
  17.   turtle.turnLeft()
  18. end
  19.  
  20. function forward()
  21.   while not turtle.forward() do
  22.     if not turtle.dig() then
  23.       turtle.attack()
  24.     end
  25.   end
  26. end
  27.  
  28. function shiftRight()
  29.   right()
  30.   forward()
  31.   left()
  32. end
  33.  
  34. function shiftLeft()
  35.   left()
  36.   forward()
  37.   right()
  38. end
  39.  
  40. function shiftNRight(n)
  41.   right()
  42.   for i=1,n,1 do
  43.     forward()
  44.   end
  45.   left()
  46. end
  47.  
  48. function shiftNLeft(n)
  49.   left()
  50.   for i=1,n,1 do
  51.     forward()
  52.   end
  53.   right()
  54. end
  55.  
  56. function dig()
  57.   if turtle.detect() then
  58.     turtle.dig()
  59.   end
  60. end
  61.  
  62. function dump(start_point,end_point)
  63.   for i=start_point,end_point,1 do
  64.     turtle.select(i)
  65.     turtle.drop()
  66.   end
  67. end
  68.  
  69. function find(id)
  70.   for i=1,16,1 do
  71.     local data = turtle.getItemDetail(i)
  72.     if data and  data.name == id then
  73.       return i
  74.     end
  75.   end
  76.   return 0
  77. end
  78.  
  79. function turnAround()
  80.   right()
  81.   right()
  82. end
  83.  
  84. function fif(val, a, b)
  85.   if val then a() else b() end
  86. end
  87.  
  88. function fifFlip(val, a, b)
  89.   if val then a() else b() end
  90.   return not val
  91. end
  92.  
  93. function move(len)
  94.   for i=1,len,1 do
  95.     fuel()
  96.     forward()
  97.   end
  98. end
  99.  
  100. function digFrontandRight()
  101.   turtle.dig()  
  102.   right()
  103.   turtle.dig()
  104.   left()
  105. end
  106.  
  107. local blocktype
  108. local torchstand
  109. local args = {...}
  110. local lengthcount = 0
  111.  
  112. if #args < 1 then
  113.   blocktype = "minecraft:stonebrick"
  114. else
  115.   blocktype = "minecraft:" .. args[1]
  116. end
  117.  
  118. if #args < 2 then
  119.   torchstand = "minecraft:cobblestone"
  120. else
  121.   torchstand = "minecraft:" .. args[2]
  122. end
  123.  
  124.  
  125. while(find(blocktype) > 0) do
  126.   lengthcount = lengthcount + 1
  127.   fuel()
  128.   -- clear two blocks above for walkability
  129.   digFrontandRight()
  130.   turtle.up()
  131.   digFrontandRight()
  132.   turtle.up()
  133.   digFrontandRight()
  134.  
  135.   -- return
  136.   turtle.down()
  137.   turtle.down()
  138.  
  139.   -- put torch
  140.   if (lengthcount % 8 == 0) then
  141.     if (find("minecraft:torch") > 0) then
  142.       right()
  143.       forward()
  144.       forward()
  145.       if (find(torchstand)) then
  146.         turtle.select(find(torchstand))
  147.         -- else use selected floor block
  148.       end
  149.       turtle.dig()
  150.       turtle.place()
  151.       turtle.digUp()
  152.       turtle.up()
  153.       turtle.dig()
  154.       turtle.select(find("minecraft:torch"))
  155.       turtle.place()
  156.       turnAround()
  157.       forward()
  158.       forward()
  159.       turtle.down()
  160.       right()
  161.     end
  162.   end
  163.  
  164.   -- build road
  165.   turtle.select(find(blocktype))
  166.   turtle.digDown()
  167.   right()
  168.   turtle.dig()
  169.   turtle.digDown()
  170.   turtle.down()
  171.   turtle.dig()
  172.   turtle.place()
  173.   turtle.up()
  174.   turtle.placeDown()
  175.   left()
  176.   forward()
  177.  
  178. end
Add Comment
Please, Sign In to add comment