Advertisement
TechManDylan

Builder

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