Advertisement
LDDestroier

Turtle House Builder

Jan 16th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.31 KB | None | 0 0
  1. turnTurn = "right"
  2. hasBlocks = true
  3. function turnOpposite()
  4.     if turnTurn == "right" then
  5.         turtle.turnLeft()
  6.     else
  7.         turtle.turnRight()
  8.     end
  9. end
  10. function autoRefuel()
  11.     if turtle.getFuelLevel() < 40 then
  12.         for a = 1, 16, 1 do
  13.             turtle.select(a)
  14.             if turtle.refuel(2) == true then
  15.                 break
  16.             end
  17.         end
  18.     end
  19.     turtle.select(1)
  20. end
  21.  
  22. local function checkForBlocks()
  23.     hasBlocks = false
  24.     for a = 1, 16, 1 do
  25.         if turtle.getItemSpace(a) ~= 0 then
  26.             itemDetail = turtle.getItemDetail(a)
  27.             if itemDetail[1] ~= 263 then
  28.                 hasBlocks = true
  29.             end
  30.         end
  31.     end
  32.     if hasBlocks == false then
  33.         print("Ran out of blocks. Insert blocks and press a key.")
  34.         sleep(0)
  35.         local event, keystroke = os.pullEvent("char")
  36.     end
  37. end
  38.  
  39. function checkIfHasBlocks()
  40.         checkForBlocks()
  41.     while hasBlocks == false do
  42.         checkForBlocks()
  43.     end
  44. end
  45.  
  46. function makeFloor()
  47.     for a = 1, width, 1 do
  48.         for b = 1, length, 1 do
  49.             checkIfHasBlocks()
  50.             turtle.placeDown()
  51.             if b ~= length then
  52.                 turtle.forward()
  53.             end
  54.         end
  55.         if a ~= width then
  56.             if turnTurn == "right" then
  57.                 turnTurn = "left"
  58.                 turtle.turnRight()
  59.                 turtle.forward()
  60.                 turtle.turnRight()
  61.             else
  62.                 turnTurn = "right"
  63.                 turtle.turnLeft()
  64.                 turtle.forward()
  65.                 turtle.turnLeft()
  66.             end
  67.         else
  68.             turnOpposite() 
  69.         end
  70.     end
  71.     turtle.up()
  72. end
  73.  
  74. function makeWall()
  75.     for a = 1, 2, 1 do
  76.         for b = 1, length, 1 do
  77.             checkIfHasBlocks()
  78.             turtle.placeDown()
  79.             if b ~= length then
  80.                 turtle.forward()
  81.             end
  82.         end
  83.         turnOpposite()
  84.         for b = 1, width, 1 do
  85.             checkIfHasBlocks()
  86.             turtle.placeDown()
  87.             if b ~= width then
  88.                 turtle.forward()
  89.             end
  90.         end
  91.         turnOpposite()
  92.     end
  93.     turtle.up()
  94. end
  95.  
  96. function makeHouse()
  97.     if botfloor then
  98.         makeFloor()
  99.     end
  100.     for a = 1, floors, 1 do
  101.         for b = 1, height, 1 do
  102.             makeWall()
  103.         end
  104.         makeFloor()
  105.     end
  106. end        
  107.  
  108. print("Place turtle to far left of house.")
  109. print("Enter forward length:")
  110. length = tonumber(read())
  111. print("Enter right width:")
  112. width = tonumber(read())
  113. print("Enter height of each floor:")
  114. height = tonumber(read())
  115. print("Enter amount of floors:")
  116. floors = tonumber(read())
  117. print("Make bottom floor? (y/n)")
  118. botfloor = read()
  119. if botfloor == "y" then
  120.     botfloor = true
  121. else
  122.     botfloor = false
  123. end
  124. print("Constructing...")
  125. makeHouse()
  126. print("Complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement