Slord6

Turtle house builder

Jun 25th, 2018
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.10 KB | None | 0 0
  1. --block in front of turtle at beginning is bottom left corner
  2. --when viewed from above
  3. -- 1 = Wall
  4. -- 2 = Roof
  5. -- 3 = Door
  6. -- 4 = Chest
  7. -- 5 = Crafting table
  8. -- 6 = Bed
  9.  
  10. -- 16 = Fuel
  11.  
  12. local wallIndex = 1
  13. local roofIndex = 2
  14. local doorIndex = 3
  15. local chestIndex = 4
  16. local craftIndex = 5
  17. local bedIndex = 6
  18. local fuelIndex = 16
  19.  
  20. function forceMoveLeft()
  21.     turtle.turnLeft()
  22.     forceMoveForward()
  23.     turtle.turnRight()
  24. end
  25.  
  26. function forceTurnLeft()
  27.     turtle.turnLeft()
  28.     forceMoveForward()
  29. end
  30.  
  31. function forceMoveRight()
  32.     turtle.turnRight()
  33.     forceMoveForward()
  34.     turtle.turnLeft()
  35. end
  36.  
  37. function forceMoveUp()
  38.     while not turtle.up() do
  39.         turtle.digUp()
  40.     end
  41. end
  42.  
  43. function forceMoveDown()
  44.     while not turtle.down() do
  45.         turtle.digDown()
  46.     end
  47. end
  48.  
  49. function forceMoveBack()
  50.     turtle.turnLeft()
  51.     turtle.turnLeft()
  52.     forceMoveForward()
  53.     turtle.turnLeft()
  54.     turtle.turnLeft()
  55. end
  56.  
  57. function forceMoveForward()
  58.     refuel()
  59.     while not turtle.forward() do
  60.         turtle.dig()
  61.     end
  62. end
  63.  
  64. function refuel()
  65.     if turtle.getFuelLevel() ~= "unlimited" and turtle.getFuelLevel() < 10 then
  66.         print("Refuelling")
  67.         turtle.select(fuelIndex)
  68.         turtle.refuel(1)
  69.     end
  70. end
  71.  
  72. function fillInDirection(length, height, blockIndex)
  73.    
  74.     for h = 1, height do
  75.         --move to just before the end
  76.         for i = 1, length do
  77.             forceMoveForward()
  78.         end
  79.        
  80.         --now move backwards, placing blocks
  81.         print("Placing row")
  82.         for l = 1, length do
  83.                 turtle.back()
  84.                 placeByIndex(blockIndex)
  85.         end
  86.        
  87.         forceMoveUp()
  88.     end
  89.     print("Resetting height")
  90.     --reset to original position
  91.     for h = 1, height do
  92.         turtle.down()
  93.     end
  94. end
  95.  
  96. function placeByIndex(index)
  97.     turtle.select(index)
  98.     turtle.place()
  99. end
  100.  
  101. function buildRoom()
  102.     print("Building left wall")
  103.     fillInDirection(3,2,wallIndex) --left wall
  104.    
  105.     turtle.turnRight()
  106.     print("Building front wall")
  107.     fillInDirection(3,2,wallIndex) -- front wall
  108.    
  109.    
  110.     print("Adding door space to front wall")
  111.     --clear the door part of the wall and place door
  112.     forceMoveRight()
  113.     forceMoveForward()
  114.     forceMoveForward()
  115.     forceTurnLeft() -- clear bottom half of door
  116.     forceMoveUp() -- clear top half of door
  117.     turtle.down()
  118.     turtle.back()
  119.    
  120.     --move to the end of the front wall on the right
  121.     turtle.turnRight()
  122.     forceMoveForward()
  123.     forceMoveForward()
  124.     forceTurnLeft()
  125.    
  126.     print("Building right wall")
  127.     fillInDirection(3,2,wallIndex) --right wall
  128.    
  129.     --move to place back wall
  130.     forceMoveRight()
  131.     forceMoveForward()
  132.     forceMoveForward()
  133.     forceMoveForward()
  134.     forceMoveForward()
  135.     forceTurnLeft()
  136.    
  137.     print("Building back wall")
  138.     fillInDirection(3,2,wallIndex) --back wall
  139.    
  140.     print("Building the roof")
  141.     forceMoveUp()
  142.     forceMoveUp()
  143.     forceMoveForward()
  144.     turtle.turnLeft()
  145.     fillInDirection(3,1,roofIndex)
  146.     forceMoveRight()
  147.     fillInDirection(4,1,roofIndex) --extra to cover door
  148.     forceMoveRight()
  149.     fillInDirection(3,1,roofIndex)
  150.     forceMoveRight()
  151.    
  152.     print("Moving inside")
  153.     for i = 1, 4 do
  154.         forceMoveForward()
  155.     end
  156.     forceMoveDown()
  157.     forceMoveDown()
  158.     forceMoveForward()
  159.     forceTurnLeft()
  160.     forceMoveForward()
  161.     turtle.turnLeft()
  162.    
  163.     forceMoveForward() -- on the threshold
  164.     print("Clearing interior")
  165.     forceMoveForward()
  166.    
  167.     --clear front inside
  168.     forceMoveRight()
  169.     turtle.digUp()
  170.     forceMoveLeft()
  171.     turtle.digUp()
  172.     forceMoveLeft()
  173.     turtle.digUp()
  174.    
  175.     --clear middle inside
  176.     forceMoveForward()
  177.     turtle.digUp()
  178.     forceMoveRight()
  179.     turtle.digUp()
  180.     forceMoveRight()
  181.     turtle.digUp()
  182.    
  183.     --clear back inside
  184.     forceMoveForward()
  185.     turtle.digUp()
  186.     forceMoveLeft()
  187.     turtle.digUp()
  188.     forceMoveLeft()
  189.     turtle.digUp()
  190.    
  191.     print("Placing interior items")
  192.     --place interior items
  193.     turtle.back()
  194.     turtle.back()
  195.     placeByIndex(bedIndex)
  196.     forceMoveRight()
  197.     turtle.forward()
  198.     placeByIndex(chestIndex)
  199.     forceMoveRight()
  200.     placeByIndex(craftIndex)
  201.    
  202.     print("Placing door")
  203.     --Lastly, place the door
  204.     forceMoveLeft()
  205.     turtle.back()
  206.     turtle.back()
  207.     turtle.back()
  208.     placeByIndex(doorIndex)
  209.    
  210.     --move to next start point
  211.     forceMoveRight()
  212.     forceMoveRight()
  213.     forceMoveForward()
  214.    
  215.     print("House complete!")
  216.     print("Press enter to close")
  217.     read()
  218. end
  219.  
  220. --Do the things
  221. buildRoom()
Advertisement
Add Comment
Please, Sign In to add comment