Advertisement
TechManDylan

Castle

Mar 28th, 2013
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.54 KB | None | 0 0
  1. Curslot = 1
  2.  
  3. if turtle.getFuelLevel() < 1000 then
  4.         turtle.select(16)
  5.         turtle.refuel(64)
  6. end
  7.  
  8. --Movement functions
  9.  
  10. function moveForward(forward)
  11.     for fw = 1, forward do
  12.         turtle.forward()
  13.     end
  14. end
  15.  
  16. function moveUp(up)
  17.     for up = 1, up do
  18.         turtle.up()
  19.     end
  20. end
  21.  
  22. function moveDown(down)
  23.     for dw = 1, down do
  24.         turtle.down()
  25.     end
  26. end
  27.  
  28. --Movement functions
  29.  
  30. function gotoGround()
  31.     repeat
  32.             turtle.down()
  33.     until
  34.         turtle.detectDown() == true
  35.         turtle.up()
  36. end
  37.  
  38. function refillMaterials()
  39.     local getItem = turtle.getItemCount(Curslot)
  40.         if getItem < 1 then
  41.             print("No items in current slot.")
  42.             print("Calculating.")
  43.                 if Curslot == 16 then
  44.                     turtle.select(1)
  45.                     noMaterials()
  46.                 else
  47.                     Curslot = Curslot + 1
  48.                     print("Switching to slot ", Curslot)
  49.                     turtle.select(Curslot)
  50.                 end
  51.         end
  52. end
  53.  
  54. function noMaterials() 
  55.     term.clear()
  56.     term.setCursorPos(1,1)
  57.     print("[Error].")
  58.     print("Out of materials please bring me more :(")
  59.     print("press any key to continue...")
  60.     event1, param1 = os.pullEvent()
  61.     refillMaterials()
  62. end
  63.  
  64. function placeBlock(times)
  65.     for blocks = 1, times do
  66.         refillMaterials()
  67.         turtle.placeDown()
  68.         turtle.forward()
  69.     end
  70. end
  71.  
  72. -- Build cylinder code
  73. function corner()
  74.     turtle.turnRight()
  75.     turtle.forward()
  76.     turtle.turnLeft()
  77.     placeBlock(1)
  78.     turtle.turnRight()
  79.     turtle.forward()
  80.     turtle.turnLeft()
  81.     placeBlock(1)
  82.     turtle.turnRight()
  83.     turtle.forward()
  84.     turtle.turnLeft()
  85.     placeBlock(1)  
  86.     turtle.turnRight()
  87.     turtle.forward()
  88. end
  89.  
  90.  
  91. function buildCylinderLayer()
  92.     placeBlock(6)
  93.     corner()
  94.     placeBlock(6)
  95.     corner()
  96.     placeBlock(6)
  97.     corner()
  98.     placeBlock(6)
  99.     corner()
  100. end
  101.  
  102. function buildCylinder(cylinderHeight)
  103.     for cylheight = 1, cylinderHeight do
  104.         buildCylinderLayer()
  105.         turtle.up()
  106.     end
  107. end
  108. -- Build cylinder code
  109.  
  110. -- Build wall code
  111.  
  112. function wallLayer(wlength)
  113.     for Wlen = 1, wlength do
  114.         placeBlock(19)
  115.         turtle.placeDown()
  116.         wallCorner()
  117.         placeBlock(19)
  118.         turtle.forward()
  119.         turtle.placeDown()
  120.         wallCorner()
  121.         turtle.up()
  122.     end
  123. end
  124.  
  125. function wallCorner()
  126.  
  127.     turtle.turnRight()
  128.     turtle.forward()
  129.     turtle.forward()
  130.     turtle.forward()
  131.     turtle.forward()
  132.     turtle.forward()
  133.     turtle.turnRight()
  134. end
  135.  
  136. function wallDirection( direction )
  137.         if direction == 1 then
  138.             print("going left")
  139.             turtle.turnLeft()
  140.             moveForward(1)
  141.             gotoGround()
  142.         else
  143.             if direction == 2 then
  144.                 print("going forward")
  145.                 moveForward(9)
  146.                 turtle.turnRight()
  147.                 moveForward(4)
  148.                 turtle.turnLeft()
  149.                 turtle.forward()
  150.                 gotoGround()
  151.             else
  152.                 if direction == 3 then
  153.                     print("going right")
  154.                     moveForward(5)
  155.                     turtle.turnRight()
  156.                     moveForward(14)
  157.                     gotoGround()
  158.                 else
  159.                     if direction == 4 then
  160.                     print("going back")
  161.                         turtle.turnRight(2)
  162.                         moveForward(4)
  163.                         turtle.turnLeft()
  164.                         moveForward(9)
  165.                         turtle.turnRight()
  166.                         turtle.forward()
  167.                         turtle.turnLeft()
  168.                         moveForward(1)
  169.                         gotoGround()
  170.                     end
  171.                 end
  172.             end
  173.         end
  174. end
  175.  
  176. function buildWall( wallHeight )
  177.        for wallH = 1, wallHeight do
  178.             wallLayer()
  179.        end
  180. end
  181.  
  182. -- Build wall code
  183.  
  184. function nextCylinder(size)
  185.  
  186. function generateCastle(size)
  187.    
  188.     term.clear()
  189.     term.setCursorPos(1,1)
  190.     print("How tall should the Castle be?")
  191.     local height = tonumber(read())
  192.     turtle.select(1)
  193.    
  194.     -- Start building!
  195.     gotoGround()
  196.     buildCylinder(height)
  197.     wallDirection( math.random (1,4) )
  198.     wallLayer(height)
  199.    
  200.     end
  201. end
  202.    
  203.    
  204.    
  205.    
  206.    
  207.    
  208.    
  209.    
  210.     -- Done Building
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement