Advertisement
IceMonkee

HomeMaker

May 27th, 2015
337
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.90 KB | None | 0 0
  1. --[[
  2.         Title: HomeMaker
  3.         Author: IceMonkee
  4.         Description: Night is falling and you don't have shelter!
  5.                     But you do have a turtle and a bunch of blocks you
  6.                     picked up... It's time to use your turtle to
  7.                     build a shelter!
  8.  
  9.                     Place any placable block materials in the turtle's
  10.                     inventory and make sure there is enough fuel.
  11.                     Then run the program supplying the length, width, and height
  12.                     of your shelter. For the time being, shelters do not have doors,
  13.                     windows and will have a roof if you have enough materials.
  14. --]]
  15.  
  16. function message( msg )
  17.     print(msg)
  18. end
  19.  
  20. function checkFuelLevel()
  21.     if turtle.getFuelLevel() < 100 then
  22.         turtle.select(16)
  23.         while turtle.getItemCount() == 0 do
  24.             message("Please place fuel in slot 16!")
  25.             sleep(5)
  26.         end
  27.         turtle.select(1)
  28.     end
  29. end
  30.  
  31. function selectMaterials()
  32.     if turtle.getItemCount() == 0 then
  33.         foundItems = false
  34.         while foundItems == false do
  35.             for i=1,16 do
  36.                 turtle.select(i)
  37.                 if turtle.getItemCount() > 0 then
  38.                     turtle.select(i)
  39.                     foundItems = true
  40.                     break
  41.                 end
  42.             end
  43.             if foundItems == false then
  44.                 print("Please insert building materials!")
  45.             end
  46.             sleep(1)
  47.         end
  48.     end
  49. end
  50.  
  51. args = { ... }
  52.  
  53. args[1]=tonumber(args[1])
  54. args[2]=tonumber(args[2])
  55. args[3]=tonumber(args[3])
  56.  
  57. depth = args[1]
  58. width = args[2]
  59. height = args[3]
  60.  
  61. turtle.up()
  62. for i=1,height do
  63.     for j=1,depth do
  64.         selectMaterials()
  65.         turtle.placeDown()
  66.         while turtle.forward() == false do
  67.             turtle.dig()
  68.             turtle.attack()
  69.         end
  70.     end
  71.     turtle.turnRight()
  72.     for j=1,width do
  73.         selectMaterials()
  74.         turtle.placeDown()
  75.         while turtle.forward() == false do
  76.             turtle.dig()
  77.             turtle.attack()
  78.         end
  79.     end
  80.     turtle.turnRight()
  81.     for j=1,depth do
  82.         selectMaterials()
  83.         turtle.placeDown()
  84.         while turtle.forward() == false do
  85.             turtle.dig()
  86.             turtle.attack()
  87.         end
  88.     end
  89.     turtle.turnRight()
  90.     for j=1,width do
  91.         selectMaterials()
  92.         turtle.placeDown()
  93.         while turtle.forward() == false do
  94.             turtle.dig()
  95.             turtle.attack()
  96.         end
  97.     end
  98.     turtle.turnRight()
  99.     while turtle.up() == false do
  100.         turtle.attackUp()
  101.         turtle.digUp()
  102.     end
  103. end
  104.  
  105. --Now add the roof
  106. for i=1,width+1 do
  107.     for j=1,depth do
  108.         selectMaterials()
  109.         turtle.placeDown()
  110.         while turtle.forward() == false do
  111.             turtle.attack()
  112.             turtle.dig()
  113.         end
  114.     end
  115.     if (i % 2) == 1 then
  116.         turtle.turnRight()
  117.         selectMaterials()
  118.         turtle.placeDown()
  119.         while turtle.forward() == false do
  120.             turtle.dig()
  121.             turtle.attack()
  122.         end
  123.         selectMaterials()
  124.         turtle.placeDown()
  125.         turtle.turnRight()
  126.     else
  127.         turtle.turnLeft()
  128.         selectMaterials()
  129.         turtle.placeDown()
  130.         while turtle.forward() == false do
  131.             turtle.dig()
  132.             turtle.attack()
  133.         end
  134.         selectMaterials()
  135.         turtle.placeDown()
  136.         turtle.turnLeft()
  137.     end
  138. end
  139.  
  140. for i=1,height do
  141.     while turtle.down() == false do
  142.         turtle.digDown()
  143.         turtle.attackDown()
  144.     end
  145. end
  146.  
  147. message("Shelter Complete!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement