psychedelixx

Minecraft Turtle: Simple House

Dec 13th, 2013
182
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.30 KB | None | 0 0
  1. --[[
  2. Auflistung Materialien:
  3. 01 Fußboden innen:   40
  4. 02 Fußboden Veranda:  6
  5. 03 Treppen Veranda:   9
  6. 04 Sockel:           26
  7. 05 Wände Typ 1:      63
  8. 06 Wände Typ 2:      46
  9. 07 Fenster:          15
  10. 08 Türen:             1
  11. 09 Trittplatte:       1
  12. 10 Craftingtable:     1
  13. 11 Truhen:            2
  14. 12 Fackeln:           4
  15. 13 Öfen:              5
  16. 14 Dach:             64
  17. 15 Dach:             48
  18. 16 Giebel:           10
  19.  
  20. http://pastebin.com/J4bcwtGy
  21.  
  22.  
  23.  
  24.         Minecraft Turtle: Simple House
  25.         2013-12-13 (c) psychedelixx / thebiglebowski33
  26.  
  27.         Builds a simple house
  28.  
  29.         Usage:
  30.         - use turtle and type "label set <name>"
  31.           (to give your turtle an unique name so it remembers its programs)
  32.         - type "pastebin get J4bcwtGy house"
  33. --]]
  34.  
  35. --[[ --- Konstanten --- ]]--
  36. dirCounter = 1
  37.  
  38. countList={}
  39. keyFloorIn    = "1"
  40. keyFloorOut   = "2"
  41. keyStairsOut  = "3"
  42. keySocket     = "4"
  43. keyWalls1     = "5"
  44. keyWalls2     = "6"
  45. keyWindows    = "7"
  46. keyDoors      = "8"
  47. keyPressPlate = "9"
  48. keyCraftTable = "10"
  49. keyChests     = "11"
  50. keyTorches    = "12"
  51. keyFurnaces   = "13"
  52. keyRoof1      = "14"
  53. keyRoof2      = "15"
  54. keyGable      = "16"
  55.  
  56. countList[keyFloorIn]    = 40
  57. countList[keyFloorOut]   = 6
  58. countList[keyStairsOut]  = 9
  59. countList[keySocket]     = 26
  60. countList[keyWalls1]     = 63
  61. countList[keyWalls2]     = 46
  62. countList[keyWindows]    = 15
  63. countList[keyDoors]      = 1
  64. countList[keyPressPlate] = 1
  65. countList[keyCraftTable] = 1
  66. countList[keyChests]     = 2
  67. countList[keyTorches]    = 4
  68. countList[keyFurnaces]   = 5
  69. countList[keyRoof1]      = 64
  70. countList[keyRoof2]      = 48
  71. countList[keyGable]      = 10
  72.  
  73. --[[
  74. for key, value in pairs(countList) do
  75.     print (key, " = " , value)
  76. end
  77. ]]--
  78.  
  79. --[[ --- Parameter ---- ]]--
  80. local args = { ... }
  81. if #args < 1 then
  82.         print("")
  83. end
  84. --[[arg1 = tonumber(args[1])]]--
  85.  
  86. --[[ --- Item Check --- ]]--
  87. function enoughResources()
  88.     for key, value in pairs(countList) do
  89.         if turtle.getItemCount(tonumber(key)) < value then
  90.             return false
  91.         end
  92.     end
  93.     return true
  94. end  
  95.  
  96. function calcFuel(blueprint)
  97.     return #blueprint*#blueprint[1]*#blueprint[1][1]
  98. end
  99.  
  100. function turn()
  101.     if dirCounter%2 == 1 then
  102.         t.right()
  103.         t.forward()
  104.         t.right()
  105.     else
  106.         t.left()
  107.         t.forward()
  108.         t.left()
  109.     end
  110.  
  111.     dirCounter = dirCounter + 1
  112. end
  113.  
  114. function buildHouse(blueprint)
  115.    
  116.     t.up()
  117.  
  118.     yMax = #blueprint
  119.     y = 1
  120.  
  121.     while y <= #blueprint do
  122.         zMax = #blueprint[y]
  123.         z = 1
  124.    
  125.         while z <= zMax do
  126.             xMax = #blueprint[y][z]
  127.            
  128.             if dirCounter%2 == 1 then
  129.                 x = 1
  130.             else
  131.                 x = xMax
  132.             end
  133.    
  134.             while (x <= xMax and dirCounter%2 == 1)
  135.                or (x >= 1 and dirCounter%2 == 0) do
  136.                 slot = blueprint[y][z][x]
  137.                
  138.                 print("x: ", x, "/", xMax, " - ",
  139.                       "z: ", z, "/", zMax, " - ",
  140.                       "y: ", y, "/", yMax, " - ",
  141.                       "slot: ", slot)
  142.                      
  143.                 if slot > 0 then
  144.                    
  145.                     if turtle.getItemCount(slot) == 0 and
  146.                        slot == 14 then
  147.                         slot = 15
  148.                     end
  149.                     t.placeDown(slot)
  150.                 end
  151.                 if (x < xMax and dirCounter%2 == 1)
  152.                  or(x > 1 and dirCounter%2 == 0) then
  153.                     t.forward()
  154.                 end
  155.                
  156.                 if dirCounter%2 == 1 then
  157.                     x = x+1
  158.                 else
  159.                     x = x-1
  160.                 end
  161.             end
  162.            
  163.             if z < zMax then
  164.                 turn()
  165.             end
  166.             z = z+1
  167.         end
  168.  
  169.         if y < yMax then
  170.             driveToStartPos(blueprint, y)
  171.         else
  172.             t.forward()
  173.             for y = 1, yMax, 1 do
  174.                 t.down()
  175.             end
  176.             print("Finished!")
  177.             print("All your base are belong to us")  
  178.         end
  179.         y = y+1
  180.     end
  181. end
  182.  
  183. --[[ Funktion Rückfahrt: ]]--
  184. function driveToStartPos(array, y)    
  185.     print("Driving to start position")  
  186.     if dirCounter%2 == 0 then
  187.         t.right()
  188.     else
  189.         t.right()
  190.         t.right()
  191.         for x = 1, #array[y][#array[y]]-1, 1 do
  192.             t.forward()
  193.         end
  194.         t.right()
  195.     end
  196.      
  197.     for z = 1, #array[y]-1, 1 do
  198.         t.forward()
  199.     end
  200.      
  201.     t.right()
  202.     t.up()
  203.     dirCounter = 1
  204. end
  205.  
  206. function start()
  207.     if enoughResources() or 1 == 1 then
  208.         print("forwards, to the moon, alice")
  209.  
  210.         layer    = {}
  211. --[[        
  212.         layer[1] = {{1, 1, 1,1},
  213.                     {1, 2, 2,1},
  214.                     {1, 2, 2,1},
  215.                     {1, 1, 1,1}}
  216.         layer[2] = {{2, 2, 2, 2},
  217.                     {2, 1, 1, 2},
  218.                     {2, 1, 1, 2},
  219.                     {2, 2, 2, 2}}
  220. ]]--                    
  221.          
  222.  
  223.         layer[1] = {{ 0, 6, 4, 4, 4, 4, 4, 6, 0},
  224.                     { 0, 4, 1, 1, 1, 1, 1, 4, 0},
  225.                     { 0, 4, 1, 1, 1, 1, 1, 4, 0},
  226.                     { 0, 4, 1, 1, 1, 1, 1, 4, 0},
  227.                     { 0, 4, 1, 1, 1, 1, 1, 4, 0},
  228.                     { 0, 4, 1, 1, 1, 1, 1, 4, 0},
  229.                     { 0, 4, 1, 1, 1, 1, 1, 4, 0},
  230.                     { 0, 4, 1, 1, 1, 1, 1, 4, 0},
  231.                     { 0, 4, 1, 1, 1, 1, 1, 4, 0},
  232.                     { 0, 6, 4, 2, 4, 4, 4, 6, 0},
  233.                     { 0, 3, 2, 2, 2, 2, 2, 3, 0},
  234.                     { 0, 3, 3, 3, 3, 3, 3, 3, 0}}
  235.  
  236.         layer[2] = {{ 0, 6, 5, 5, 5, 5, 5, 6, 0},
  237.                     { 0, 5,13,13,13,13, 1, 5, 0},
  238.                     { 0, 5, 0, 0, 0, 0, 1, 5, 0},
  239.                     { 0, 5, 0, 0, 0, 0, 1, 5, 0},
  240.                     { 0, 5, 0, 0, 0, 0, 0, 5, 0},
  241.                     { 0, 5, 0, 0, 0, 0, 0, 5, 0},
  242.                     { 0, 5, 0, 0, 0, 0, 0, 5, 0},
  243.                     { 0, 5, 0, 0, 0, 0, 0, 5, 0},
  244.                     { 0, 5, 0, 9,11,11,10, 5, 0},
  245.                     { 0, 6, 5, 8, 5, 5, 5, 6, 0}}
  246.  
  247.         layer[3] = {{ 0, 6, 5, 7, 7, 7, 5, 6, 0},
  248.                     { 0, 5, 0, 0, 0,12, 1, 5, 0},
  249.                     { 0, 5,12, 0, 0, 0, 1, 5, 0},
  250.                     { 0, 7, 0, 0, 0, 0, 0, 7, 0},
  251.                     { 0, 7, 0, 0, 0, 0, 0, 7, 0},
  252.                     { 0, 7, 0, 0, 0, 0, 0, 7, 0},
  253.                     { 0, 7, 0, 0, 0, 0, 0, 7, 0},
  254.                     { 0, 5, 0, 0, 0, 0,12, 5, 0},
  255.                     { 0, 5,12, 0, 0, 0, 0, 5, 0},
  256.                     { 0, 6, 5, 0, 7, 7, 5, 6, 0},
  257.                     { 0, 0,12, 0, 0, 0, 0, 0, 0}}
  258.  
  259.         layer[4] = {{ 0, 6, 5, 5, 5, 5, 5, 6, 0},
  260.                     { 0, 5, 3, 3, 3, 3, 1, 5, 0},
  261.                     { 0, 5, 3, 3, 3, 3, 0, 5, 0},
  262.                     { 0, 5, 3, 3, 3, 3, 0, 5, 0},
  263.                     { 0, 5, 3, 3, 3, 3, 0, 5, 0},
  264.                     { 0, 5, 3, 3, 3, 3, 0, 5, 0},
  265.                     { 0, 5, 3, 3, 3, 3, 3, 5, 0},
  266.                     { 0, 5, 3, 3, 3, 3, 3, 5, 0},
  267.                     { 0, 5, 3, 3, 3, 3, 3, 5, 0},
  268.                     { 0, 6, 5, 5, 5, 5, 5, 6, 0}}
  269.  
  270.         layer[5] = {{14, 6, 6, 6, 6, 6, 6, 6,14},
  271.                     {14, 0, 0, 0, 0, 0, 0, 0,14},
  272.                     {14, 0, 0, 0, 0, 0, 0, 0,14},
  273.                     {14, 0, 0, 0, 0, 0, 0, 0,14},
  274.                     {14, 0, 0, 0, 0, 0, 0, 0,14},
  275.                     {14, 0, 0, 0, 0, 0, 0, 0,14},
  276.                     {14, 0, 0, 0, 0, 0, 0, 0,14},
  277.                     {14, 0, 0, 0, 0, 0, 0, 0,14},
  278.                     {14, 0, 0, 0, 0, 0, 0, 0,14},
  279.                     {14, 6, 6, 6, 6, 6, 6, 6,14}}
  280.  
  281.         layer[6] = {{ 0,14, 6, 6, 6, 6, 6,14, 0},
  282.                     { 0,14, 0, 0, 0, 0, 0,14, 0},
  283.                     { 0,14, 0, 0, 0, 0, 0,14, 0},
  284.                     { 0,14, 0, 0, 0, 0, 0,14, 0},
  285.                     { 0,14, 0, 0, 0, 0, 0,14, 0},
  286.                     { 0,14, 0, 0, 0, 0, 0,14, 0},
  287.                     { 0,14, 0, 0, 0, 0, 0,14, 0},
  288.                     { 0,14, 0, 0, 0, 0, 0,14, 0},
  289.                     { 0,14, 0, 0, 0, 0, 0,14, 0},
  290.                     { 0,14, 6, 6, 6, 6, 6,14, 0}}
  291.  
  292.         layer[7] = {{ 0, 0,14, 6, 7, 6,14, 0, 0},
  293.                     { 0, 0,14, 0, 0, 0,14, 0, 0},
  294.                     { 0, 0,14, 0, 0, 0,14, 0, 0},
  295.                     { 0, 0,14, 0, 0, 0,14, 0, 0},
  296.                     { 0, 0,14, 0, 0, 0,14, 0, 0},
  297.                     { 0, 0,14, 0, 0, 0,14, 0, 0},
  298.                     { 0, 0,14, 0, 0, 0,14, 0, 0},
  299.                     { 0, 0,14, 0, 0, 0,14, 0, 0},
  300.                     { 0, 0,14, 0, 0, 0,14, 0, 0},
  301.                     { 0, 0,14, 6, 7, 6,14, 0, 0}}
  302.  
  303.         layer[8] = {{ 0, 0, 0,14, 6,14, 0, 0, 0},
  304.                     { 0, 0, 0,14, 0,14, 0, 0, 0},
  305.                     { 0, 0, 0,14, 0,14, 0, 0, 0},
  306.                     { 0, 0, 0,14, 0,14, 0, 0, 0},
  307.                     { 0, 0, 0,14, 0,14, 0, 0, 0},
  308.                     { 0, 0, 0,14, 0,14, 0, 0, 0},
  309.                     { 0, 0, 0,14, 0,14, 0, 0, 0},
  310.                     { 0, 0, 0,14, 0,14, 0, 0, 0},
  311.                     { 0, 0, 0,14, 0,14, 0, 0, 0},
  312.                     { 0, 0, 0,14, 6,14, 0, 0, 0}}
  313.  
  314.         layer[9] = {{ 0, 0, 0, 0,16, 0, 0, 0, 0},
  315.                     { 0, 0, 0, 0,16, 0, 0, 0, 0},
  316.                     { 0, 0, 0, 0,16, 0, 0, 0, 0},
  317.                     { 0, 0, 0, 0,16, 0, 0, 0, 0},
  318.                     { 0, 0, 0, 0,16, 0, 0, 0, 0},
  319.                     { 0, 0, 0, 0,16, 0, 0, 0, 0},
  320.                     { 0, 0, 0, 0,16, 0, 0, 0, 0},
  321.                     { 0, 0, 0, 0,16, 0, 0, 0, 0},
  322.                     { 0, 0, 0, 0,16, 0, 0, 0, 0},
  323.                     { 0, 0, 0, 0,16, 0, 0, 0, 0}}
  324.                    
  325.         if turtle.getFuelLevel() < calcFuel(layer) then
  326.             print("Amount of missing fuel: ", calcFuel(layer)-turtle.getFuelLevel())
  327.             print("Missing fuel in coal: ", calcFuel(layer)-turtle.getFuelLevel()/80+1)
  328.             print("Fill fuel in slot 1, type 'refuel <amount>' and try again")
  329.         end
  330.        
  331.         buildHouse(layer)
  332.     else
  333.         print("Not enough Resources")
  334.     end
  335. end
  336.  
  337.  
  338. print("======== 2013 (c) psy & lebo ==========")
  339. print("======== Simple House Builder =========")
  340.  
  341. start()
Advertisement
Add Comment
Please, Sign In to add comment