Advertisement
Tomlacko

ComputerCraft Quarry perimeter (single)

May 8th, 2016
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.84 KB | None | 0 0
  1. function go(dir)
  2.   if dir=="fwd" then
  3.     while turtle.forward() == false do
  4.       turtle.dig()
  5.       turtle.attack()
  6.     end
  7.   elseif dir=="up" then
  8.     while turtle.up() == false do
  9.       turtle.digUp()
  10.       turtle.attackUp()
  11.     end
  12.   elseif dir=="down" then
  13.     while turtle.down() == false do
  14.       turtle.digDown()
  15.       turtle.attackDown()
  16.     end
  17.   elseif dir=="back" then
  18.     while turtle.back() == false do
  19.       turtle.turnLeft()
  20.       turtle.turnLeft()
  21.       turtle.dig()
  22.       turtle.attack()
  23.       turtle.turnLeft()
  24.       turtle.turnLeft()
  25.     end
  26.   end
  27. end
  28.  
  29. function refuel()
  30.   print("Fuel needed: " .. (3+comeback)*size)
  31.   print(" ")
  32.   turtle.select(16)
  33.   while turtle.getFuelLevel() < ((3+comeback)*size) do
  34.     if turtle.refuel(1) == false then
  35.       sleep(0.5)
  36.     end
  37.   end
  38. end
  39.  
  40. function items()
  41.   turtle.select(1)
  42.   if turtle.getItemCount(1) < 3 then
  43.     print("Place 3 blocks in the first slot.")
  44.     while turtle.getItemCount(1) < 3 do
  45.       sleep(1)
  46.     end
  47.   end
  48. end
  49.  
  50. function node()
  51.   turtle.digDown()
  52.   turtle.placeDown()
  53. end
  54.  
  55. function line()
  56.   for i=1, size do
  57.     turtle.digUp()
  58.     turtle.dig()
  59.     go(fwd)
  60.   end
  61.   turtle.digUp()
  62. end
  63.  
  64. function turnBack()
  65.   turtle.turnLeft()
  66.   turtle.turnLeft()
  67. end
  68.  
  69. -------------------------------------------------------
  70.  
  71. up = "up"
  72. down = "down"
  73. back = "back"
  74. fwd = "fwd"
  75.  
  76. write("Quarry size: ")
  77. size = read() + -1
  78. while size < 2 or size > 63 do
  79.   print("Invalid size! (Min = 3, Max = 64)")
  80.   size = read() + -1
  81. end
  82. write("Return back? (1=Yes, 0=No): ")
  83. comeback = read() + 0
  84. if comeback ~= 1 then
  85.   comeback = 0
  86. end
  87.  
  88. refuel()
  89. items()
  90.  
  91. --------------------------------------------------------
  92.  
  93. node()
  94. line()
  95. node()
  96. turnBack()
  97. line()
  98. turtle.turnLeft()
  99. line()
  100. node()
  101. if comeback == 1 then
  102.   turnBack()
  103.   line()
  104. end
  105.  
  106. print("done!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement