Advertisement
Houshalter

Construction Script

Feb 28th, 2013
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.39 KB | None | 0 0
  1. function estimatefuel(width, length, height)
  2. return (((width * height * 2) + ((length - 2) * height * 2) + ((length - 1) * (width - 1))) - turtle.getFuelLevel()) / 80
  3. end
  4.  
  5. function digforward(n)
  6. for i = 1, n do
  7. repeat
  8. if turtle.detect() then turtle.dig() end
  9. until turtle.forward()
  10. end
  11. end
  12.  
  13. function refuel(n)
  14. print("Refueling turtle.")
  15. for i = n, 16 do
  16. turtle.select(i)
  17. turtle.refuel()
  18. end
  19.  
  20. turtle.select(1)
  21. print("Turtle has " .. turtle.getFuelLevel() .. " fuel left.")
  22. end
  23.  
  24.  
  25. function inventory()
  26. if turtle.getItemCount(1) < 2 then
  27. for i = 1, 16 do
  28. turtle.select(i)
  29. turtle.transferTo(1, 64)
  30. end
  31. turtle.select(1)
  32. if turtle.getItemCount(1) < 2 then
  33. print("Turtle has run out of blocks to place. Please refill turtle and press Enter to continue construction.")
  34. io.read()
  35. end
  36. end
  37. end
  38.  
  39. function placeforward(n)
  40. inventory()
  41. turtle.placeDown()
  42. if n > 1 then digforward(1) placeforward((n - 1)) end
  43. end
  44.  
  45.  
  46. --I got this to work. I don't even know how it works, just don't touch it.
  47. function buildceiling(width, length)
  48. placeforward(length - 2)
  49. turtle.turnRight()
  50. digforward(1)
  51. if ((length - 2) * (width - 2)) > 0 then buildceiling(length , (width - 1)) end
  52. end
  53.  
  54. function buildwalls(width, length, height)
  55. for i = 1, 2 do
  56. placeforward(length)
  57. turtle.turnRight()
  58. digforward(1)
  59. placeforward(width - 2)
  60. digforward(1)
  61. turtle.turnRight()
  62. end
  63. if height > 1 then digup(1) buildwalls(width, length, (height - 1)) end
  64. end
  65.  
  66. function digup(n)
  67. for i = 1, n do
  68. repeat
  69. if turtle.detectUp() then turtle.digUp() end
  70. until turtle.up()
  71. end
  72. end
  73.  
  74. function build(width, length, height)
  75. digup(1)
  76. buildwalls(width, length, height)
  77. digforward(1)
  78. turtle.turnRight()
  79. digforward(1)
  80. turtle.turnLeft()
  81. buildceiling(width, length)
  82. end
  83.  
  84. print("Enter the Length (forward):")
  85. length = tonumber(io.read())
  86. print("Enter the Width (across):")
  87. width = tonumber(io.read())
  88. print("Enter the Height:")
  89. height = tonumber(io.read())
  90. estimate = estimatefuel(width, length, height)
  91. if estimate > 0 then print("Estimating the turtle will require "..estimate.." peices of coal.\nPlace them into the turtle and press Enter to continue.") io.read() refuel(1) end
  92. print("Please fill the turtle's inventory with required building materials.")
  93. io.read()
  94. print("Turtle will now begin construction.")
  95. build(width, length, height)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement