Advertisement
EastmanLG

Building Builder

May 19th, 2019
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.26 KB | None | 0 0
  1. --House builder
  2. --Logan Eastman
  3.  
  4. local length = 5; --Internal length of building
  5. local width = 7; --Internal width of building
  6. local height = 1; --Internal height; does not include ceiling
  7.  
  8.  
  9. local itemSlot = 1;
  10. local fuelSlot = 16;
  11.  
  12. function checkResources()
  13.     --Check fuel
  14.     local fuelThreshold = 2
  15.     if(turtle.getFuelLevel() < fuelThreshold) then
  16.         if(turtle.getItemCount(fuelSlot)>0) then
  17.             turtle.select(fuelSlot)
  18.             turtle.refuel(1)
  19.             turtle.select(itemSlot)
  20.         end
  21.     end
  22.  
  23.     --Check Items
  24.     if(turtle.getItemCount(itemSlot) == 0) then
  25.         if((itemSlot+1) ~= fuelSlot) then
  26.             itemSlot = itemSlot+1
  27.             if(itemSlot >= 16) then
  28.                 if(fuelSlot ~= 1) then
  29.                     itemSlot = 1
  30.                 else
  31.                     itemSlot = 2
  32.                 end
  33.             end
  34.             turtle.select(itemSlot)
  35.         else
  36.             if(fuelSlot == 16) then
  37.                 itemSlot = 1
  38.             else
  39.                 itemSlot = itemSlot + 2
  40.             end
  41.             turtle.select(itemSlot)
  42.         end
  43.        
  44.  
  45.         if(turtle.getItemCount(itemSlot) == 0) then
  46.             print "All out of items"
  47.         end
  48.     end
  49. end
  50.  
  51. function buildWalls()
  52.     for floor = 1,height,1 do --Loop for every block height of building
  53.         checkResources()
  54.         turtle.up() --Move up
  55.  
  56.         for i = 1,2,1 do --repeat twice per block height
  57.             for side = 0,length,1 do --Forward for length
  58.                 checkResources()
  59.                 turtle.placeDown() --Place blocks
  60.                 turtle.forward() --Move forward
  61.             end
  62.  
  63.             turtle.turnLeft()
  64.  
  65.  
  66.             for side = 0,width,1 do --forward for width
  67.                 checkResources()
  68.                 turtle.placeDown() --place blocks
  69.                 turtle.forward() --Move forward
  70.             end
  71.            
  72.             turtle.turnLeft()
  73.  
  74.         end
  75.     end
  76. end
  77.  
  78. function buildCeiling()
  79.     local rightTurn = true
  80.     checkResources()
  81.     turtle.up()
  82.     for w = 0,width+1,1 do --Loop for every block height of building
  83.  
  84.         if(rightTurn) then --switch rightTurn toggle
  85.             rightTurn = false
  86.         else
  87.             rightTurn = true
  88.         end
  89.  
  90.         for side = 0,length,1 do --Forward for length
  91.             checkResources()
  92.             turtle.placeDown() --Place blocks
  93.             turtle.forward() --Move forward
  94.         end
  95.        
  96.         if(rightTurn) then
  97.             turtle.turnRight()
  98.         else
  99.             turtle.turnLeft()
  100.         end
  101.  
  102.         turtle.placeDown() --Place block before moving
  103.         checkResources()
  104.         turtle.forward() --Move forward
  105.        
  106.         if(rightTurn) then
  107.             turtle.turnRight()
  108.         else
  109.             turtle.turnLeft()
  110.         end
  111.     end
  112. end
  113.  
  114. buildWalls()
  115. buildCeiling()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement