Vanhal

ComputerCraft Ender Quarry Construction Turtle

Apr 5th, 2014
3,550
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.98 KB | None | 0 0
  1. --Computer Craft script to set up a fence boundary for an ender quarry
  2. --Just run the program and give it the size of the quarry you want
  3. --Author: Vanhal
  4. --http://www.youtube.com/VanhalMinecraft
  5.  
  6. local currentSlot = -1
  7.  
  8. function refuel()
  9.   if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 10 then
  10.     for i = 1, 16 do
  11.       turtle.select(i)
  12.       if turtle.refuel(0) then
  13.         turtle.refuel(1)
  14.       end
  15.     end
  16.   end
  17. end
  18.  
  19.  
  20. function moveForward()
  21.   refuel()
  22.   if turtle.detect() then
  23.     turtle.dig()
  24.   end
  25.   turtle.forward()
  26. end
  27.  
  28. function placeFence()
  29.   if turtle.detectUp() then
  30.     turtle.digUp()
  31.   end
  32.   turtle.select(2)
  33.   if turtle.getItemCount(2) > 0 then
  34.     if currentSlot > 0 and turtle.compareTo(currentSlot) and turtle.getItemCount(currentSlot) > 0 then
  35.       turtle.select(currentSlot)
  36.     else
  37.       currentSlot = 2
  38.       for i=3, 16 do
  39.         if turtle.compareTo(i) then
  40.           currentSlot = i
  41.           turtle.select(i)
  42.         end
  43.       end
  44.     end
  45.     turtle.placeUp()
  46.   else
  47.     error("No fences found in slot 2")
  48.   end
  49. end
  50.  
  51. --start script and prompt for size
  52. shell.run('clear')
  53. print("Please put some fuel in the first slot and put loads stacks of fences in at least the second slot")
  54.  
  55. --just do some error checking
  56. if turtle.getItemCount(1) == 0 then
  57.   error("No fuel in slot 1")
  58. end
  59. if turtle.getItemCount(2) == 0 then
  60.   error("No Fences in slot 2")
  61. end
  62. turtle.select(1)
  63. if turtle.refuel(0) == false then
  64.   error("No fuel in slot 1")
  65. end
  66.  
  67. print("How big you want each side of your quarry to be, max 240?")
  68. local size = io.read()
  69.  
  70. size = tonumber(size)
  71.  
  72. function buildRow(rowSize)
  73.   for i=1, rowSize do
  74.     moveForward()
  75.     placeFence()
  76.   end
  77. end
  78.  
  79. if size > 2 then
  80.   size = size - 1
  81.   buildRow(size)
  82.  
  83.   turtle.turnLeft()
  84.   buildRow(size)
  85.  
  86.   turtle.turnLeft()
  87.   buildRow(size)
  88.  
  89.   turtle.turnLeft()
  90.   buildRow(size - 1)
  91.   moveForward()
  92. else
  93.   error("Can't make a square of size 1")
  94. end
Advertisement
Add Comment
Please, Sign In to add comment