exa-byte

TurtleScript - CharmingHouse

Aug 30th, 2015
943
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 9.55 KB | None | 0 0
  1. -- Original House Builder
  2.  
  3. -- item numbers in inventory
  4.  
  5. item_floor1 = 1
  6. item_floor2 = 2
  7. item_wall1 = 3
  8. item_wall2 = 4
  9. item_wall3 = 5
  10. item_fence = 6
  11. item_roof1 = 7
  12. item_roof2 = 8
  13. item_roofEdge = 9
  14. item_window = 10
  15. item_torch = 11
  16. item_door = 12
  17. item_plate = 13
  18. item_corner1 = 14
  19. item_corner2 = 15
  20. item_ladder = 16
  21.  
  22. -- functions
  23.  
  24. function f()
  25.     turtle.forward()
  26. end
  27. function b()
  28.     turtle.back()
  29. end
  30. function l()
  31.     turtle.turnLeft()
  32. end
  33. function ll()
  34.     turtle.turnLeft()
  35.     turtle.turnLeft()
  36. end
  37. function r()
  38.     turtle.turnRight()
  39. end
  40. function u()
  41.     turtle.up()
  42. end
  43. function d()
  44.     turtle.down()
  45. end
  46. function PlaceDown(slot)
  47.     if (turtle.getSelectedSlot() ~= slot) then
  48.         turtle.select(slot)
  49.     end
  50.     turtle.placeDown()
  51. end
  52. function Place(slot)
  53.     if (turtle.getSelectedSlot() ~= slot) then
  54.         turtle.select(slot)
  55.     end
  56.     turtle.place()
  57. end
  58. function PlaceUp(slot)
  59.     if (turtle.getSelectedSlot() ~= slot) then
  60.         turtle.select(slot)
  61.     end
  62.     turtle.placeUp()
  63. end
  64. function PlaceDownCorner()
  65.         if (corner_count < 64) then
  66.             if (turtle.getSelectedSlot() ~= item_corner1) then turtle.select(item_corner1) end
  67.         elseif (corner_count < 128) then
  68.             if (turtle.getSelectedSlot() ~= item_corner2) then turtle.select(item_corner2) end
  69.         end
  70.         corner_count = corner_count+1
  71.         turtle.placeDown()
  72.     end
  73. function PlaceCorner()
  74.     if (corner_count < 64) then
  75.         if (turtle.getSelectedSlot() ~= item_corner1) then turtle.select(item_corner1) end
  76.     elseif (corner_count < 128) then
  77.         if (turtle.getSelectedSlot() ~= item_corner2) then turtle.select(item_corner2) end
  78.     end
  79.     corner_count = corner_count+1
  80.     turtle.place()
  81. end
  82. function PlaceDownWall()
  83.     if (wall_count < 64) then
  84.         if (turtle.getSelectedSlot() ~= item_wall1) then turtle.select(item_wall1) end
  85.     elseif (wall_count < 128) then
  86.         if (turtle.getSelectedSlot() ~= item_wall2) then turtle.select(item_wall2) end
  87.     elseif (wall_count < 192) then
  88.         if (turtle.getSelectedSlot() ~= item_wall3) then turtle.select(item_wall3) end
  89.     end
  90.     wall_count = wall_count+1
  91.     turtle.placeDown()
  92. end
  93. function PlaceDownFloor()
  94.         if (floor_count < 64) then
  95.             if (turtle.getSelectedSlot() ~= item_floor1) then turtle.select(item_floor1) end
  96.         elseif (floor_count < 128) then
  97.             if (turtle.getSelectedSlot() ~= item_floor2) then turtle.select(item_floor2) end
  98.         end
  99.         floor_count = floor_count+1
  100.         turtle.placeDown()
  101. end
  102. function PlaceDownRoof()
  103.         if (roof_count < 64) then
  104.             if (turtle.getSelectedSlot() ~= item_roof1) then turtle.select(item_roof1) end
  105.         elseif (roof_count < 128) then
  106.             if (turtle.getSelectedSlot() ~= item_roof2) then turtle.select(item_roof2) end
  107.         end
  108.         roof_count = roof_count+1
  109.         turtle.placeDown()
  110. end
  111. function PlaceUpRoof()
  112.         if (roof_count < 64) then
  113.             if (turtle.getSelectedSlot() ~= item_roof1) then turtle.select(item_roof1) end
  114.         elseif (roof_count < 128) then
  115.             if (turtle.getSelectedSlot() ~= item_roof2) then turtle.select(item_roof2) end
  116.         end
  117.         roof_count = roof_count+1
  118.         turtle.placeUp()
  119. end
  120. function PlaceRoof()
  121.         if (roof_count < 64) then
  122.             if (turtle.getSelectedSlot() ~= item_roof1) then turtle.select(item_roof1) end
  123.         elseif (roof_count < 128) then
  124.             if (turtle.getSelectedSlot() ~= item_roof2) then turtle.select(item_roof2) end
  125.         end
  126.         roof_count = roof_count+1
  127.         turtle.place()
  128. end
  129.  
  130. -- pick up items from chest to the left
  131. function part1()
  132.     l()
  133.     turtle.select(1)
  134.     for i = 1,16 do
  135.         turtle.suck()
  136.         turtle.select(i%16+1)
  137.     end
  138.     r()
  139.     u()
  140. end
  141.  
  142. -- build fence
  143. function part2()
  144.     turtle.select(item_fence)
  145.     for j = 1,3 do
  146.         for i = 1,15 do
  147.             turtle.placeDown()
  148.             f()
  149.         end
  150.         r()
  151.     end
  152.     for i = 1,7 do
  153.         turtle.placeDown()
  154.         f()
  155.     end
  156.     f()f()
  157.     for i = 1,6 do
  158.         turtle.placeDown()
  159.         f()
  160.     end
  161.     r()
  162.        
  163.  
  164.     -- goto basement
  165.  
  166.     f()f()f()r()f()d()f()f()l()
  167.  
  168.  
  169.     -- build basement
  170.  
  171.     floor_count = 0
  172.    
  173.     for j=1,5 do
  174.         turtle.digDown()
  175.         PlaceDownFloor()
  176.         for i = 1,9 do
  177.             f()
  178.             turtle.digDown()
  179.             PlaceDownFloor()
  180.         end
  181.         r()
  182.         f()
  183.         r()
  184.         turtle.digDown()
  185.         PlaceDownFloor()
  186.         for i = 1,9 do
  187.             f()
  188.             turtle.digDown()
  189.             PlaceDownFloor()
  190.         end
  191.         if (j ~= 5) then
  192.             l()
  193.             f()
  194.             l()
  195.         end
  196.     end
  197.  
  198.     -- goto and build path to door
  199.  
  200.     r()f()f()f()f()l()f()
  201.     turtle.digDown()
  202.     PlaceDownFloor()f()
  203.     turtle.digDown()
  204.     PlaceDownFloor()f()
  205.     turtle.digDown()
  206.     PlaceDownFloor()r()f()
  207.     turtle.digDown()
  208.     PlaceDownFloor()r()f()
  209.     turtle.digDown()
  210.     PlaceDownFloor()f()
  211.     turtle.digDown()
  212.     PlaceDownFloor()f()l()
  213.  
  214.     -- goto left front column
  215.  
  216.     f()f()f()f()r()
  217.  
  218.     -- build walls and windows and stuff...
  219.     -- level 1
  220.  
  221.     corner_count = 0
  222.     wall_count = 0
  223.  
  224.     turtle.select(item_corner1)
  225.     u()
  226.  
  227.     for i = 1,3 do
  228.         PlaceDownCorner()
  229.         f()
  230.         for k = 1,8 do
  231.             PlaceDownWall()
  232.             f()
  233.         end
  234.         r()
  235.     end
  236.     -- now comes the door wall
  237.     PlaceDownCorner()
  238.     f()
  239.     for k = 1,3 do
  240.         PlaceDownWall()
  241.         f()
  242.     end
  243.     f()f()
  244.     for k = 1,3 do
  245.         PlaceDownWall()
  246.         f()
  247.     end
  248.     r()
  249.     u()
  250.        
  251.     -- level 2
  252.  
  253.     for i = 1,3 do
  254.         PlaceDownCorner()f()
  255.         PlaceDownWall()f()
  256.         PlaceDown(item_window)f()
  257.         PlaceDown(item_window)f()
  258.         PlaceDownWall()f()
  259.         PlaceDownWall()f()
  260.         PlaceDown(item_window)f()
  261.         PlaceDown(item_window)f()
  262.         PlaceDownWall()f()
  263.         r()
  264.     end
  265.     -- now comes the door wall
  266.     PlaceDownCorner()f()
  267.     PlaceDownWall()f()
  268.     PlaceDown(item_window)f()
  269.     PlaceDownWall()f()
  270.     f()f()
  271.     PlaceDownWall()f()
  272.     PlaceDown(item_window)f()
  273.     PlaceDownWall()f()
  274.     r()
  275.     u()
  276.  
  277.     -- level 3
  278.  
  279.     for i = 1,4 do
  280.         PlaceDownCorner()
  281.         f()
  282.         for k = 1,8 do
  283.             PlaceDownWall()
  284.             f()
  285.         end
  286.         if i == 4 then l() else r() end
  287.     end
  288.  
  289.     --level 4
  290.  
  291.     for i = 1,9 do
  292.         b()
  293.         PlaceCorner()
  294.     end
  295.     for i = 1,2 do
  296.         u()
  297.         PlaceDownCorner()
  298.         r()b()d()
  299.         for i = 1,8 do
  300.             b()
  301.             PlaceCorner()
  302.         end
  303.     end
  304.     u()
  305.     PlaceDownCorner()
  306.     r()b()d()
  307.     for i = 1,7 do
  308.             b()
  309.             PlaceCorner()
  310.     end
  311.     ll()
  312.     turtle.select(item_corner1)
  313.     turtle.dig()
  314.     corner_count = corner_count-1
  315.     f()
  316.     ll()
  317.     PlaceCorner()
  318.     u()
  319.     PlaceDownCorner()
  320.  
  321.     -- 2nd floor, level4
  322.  
  323.     f()l()f()
  324.     for j=1,4 do
  325.         PlaceDownWall()
  326.         for i = 1,7 do
  327.             f()
  328.             PlaceDownWall()
  329.         end
  330.         r()
  331.         f()
  332.         r()
  333.         if not (j == 2) then PlaceDownWall() end -- leave hole for ladder
  334.         for i = 1,7 do
  335.             f()
  336.             if not (j == 2 and i == 1) then PlaceDownWall() end
  337.         end
  338.         if (j ~= 4) then
  339.             l()
  340.             f()
  341.             l()
  342.         end
  343.     end
  344.     PlaceDownWall()
  345. end
  346.  
  347. function part3()
  348.     -- build vertical roof wall and windows
  349.     f()r()u()
  350.     for i = 1,7 do
  351.         PlaceDownCorner()f()
  352.     end
  353.     PlaceDownCorner()ll()u()f()
  354.     PlaceDownCorner()f()
  355.     for i = 1,4 do
  356.         PlaceDown(item_window)f()
  357.     end
  358.     PlaceDownCorner()ll()u()f()
  359.     PlaceDownCorner()f()
  360.     PlaceDown(item_window)f()
  361.     PlaceDown(item_window)f()
  362.     PlaceDownCorner()ll()u()f()
  363.     PlaceDownCorner()f()
  364.     PlaceDownCorner()
  365.     -- get to other side
  366.     d()f()d()f()d()f()d()l()
  367.     for i = 1,9 do f() end
  368.     l()
  369.     for i = 1,7 do
  370.         PlaceDownCorner()f()
  371.     end
  372.     PlaceDownCorner()ll()u()f()
  373.     PlaceDownCorner()f()
  374.     for i = 1,4 do
  375.         PlaceDown(item_window)f()
  376.     end
  377.     PlaceDownCorner()ll()u()f()
  378.     PlaceDownCorner()f()
  379.     PlaceDown(item_window)f()
  380.     PlaceDown(item_window)f()
  381.     PlaceDownCorner()ll()u()f()
  382.     PlaceDownCorner()f()
  383.     PlaceDownCorner()f()
  384.     d()f()d()f()d()f()d()f()d()d()l()f()l()
  385. end
  386.  
  387. -- build roof
  388. function part4()
  389.     roofEdge_count = 0
  390.     roof_count = 0
  391.    
  392.     function roofEdge()
  393.         for i = 1,5 do
  394.             PlaceUp(item_roofEdge)f()u()
  395.         end
  396.         PlaceUp(item_roofEdge)ll()b()
  397.         for i = 1,5 do
  398.             PlaceUp(item_roofEdge)d()b()
  399.         end
  400.         PlaceUp(item_roofEdge)
  401.     end
  402.     function easyRoofPart()
  403.         PlaceRoof()u()f()u()f()
  404.         for i = 1,4 do
  405.             PlaceDownRoof()f()u()
  406.         end
  407.         PlaceDownRoof()f()ll()
  408.         PlaceDownRoof()
  409.         for i = 1,4 do
  410.             b()d()PlaceDownRoof()
  411.         end
  412.         b()d()b()d()
  413.         PlaceRoof()
  414.     end
  415.     function badRoofPart()
  416.         PlaceRoof()u()f()
  417.         PlaceRoof()u()f()f()d()
  418.         for i = 1,3 do PlaceUpRoof()f()u() end
  419.         PlaceUpRoof()f()ll()
  420.         for i = 1,3 do PlaceUpRoof()b()d() end
  421.         PlaceUpRoof()b()b()
  422.         PlaceRoof()b()d()
  423.         PlaceRoof()
  424.     end
  425.    
  426.     -- flow code
  427.     roofEdge()
  428.     b()u()r()f()l()
  429.     easyRoofPart()
  430.     for i = 1,8 do
  431.         if (i % 2 == 1) then l()f()r() else r()f()l() end
  432.         badRoofPart()
  433.     end
  434.     l()f()r()
  435.     easyRoofPart()
  436.     d()f()r()f()l()
  437.     roofEdge()
  438. end
  439.  
  440. -- ladders, torches, doors and stuff...
  441. function part5()
  442.     for i = 1,6 do f() end
  443.     r()d()
  444.     for i = 1,9 do f() end
  445.     for i = 1,4 do u() end
  446.     b()l()f()f()r()
  447.     Place(item_torch)ll()
  448.     for i = 1,5 do f() end
  449.     Place(item_torch)l()
  450.     for i = 1,5 do f() end
  451.     r()
  452.     Place(item_torch)ll()
  453.     for i = 1,5 do f() end
  454.     Place(item_torch)l()f()f()f()r()d()
  455.     turtle.digDown()d()
  456.     Place(item_ladder)d()
  457.     PlaceUp(item_wall3)
  458.     Place(item_ladder)
  459.     for i = 1,2 do
  460.         d()
  461.         Place(item_ladder)
  462.     end
  463.     b()b()b()l()f()f()u()
  464.     Place(item_torch)ll()f()f()f()f()f()
  465.     Place(item_torch)b()r()f()f()
  466.     Place(item_torch)r()d()f()l()f()
  467.     Place(item_door)l()b()
  468.     Place(item_plate)r()
  469.     Place(item_door)u()
  470.     PlaceDown(item_plate)r()f()d()l()
  471.     PlaceUp(item_torch)
  472.     -- look for empty slot
  473.     local slot = -1
  474.     for i = 1,16 do
  475.         if turtle.getItemCount(i) == 0 then
  476.             slot = i
  477.             turtle.select(i)
  478.             break
  479.         end
  480.     end
  481.     turtle.dig()f()f()ll()
  482.     Place(slot)b()u()
  483.     Place(item_torch)ll()
  484.     Place(item_torch)l()f()f()f()l()
  485.     Place(item_torch)ll()
  486.     Place(item_torch)d()
  487. end
  488.  
  489. -- debug
  490.  
  491. function initPart3()
  492.     floor_count = 106
  493.     corner_count = 48
  494.     wall_count = 140
  495. end
  496. function initPart4()
  497.     floor_count = 106
  498.     corner_count = 80
  499.     wall_count = 140
  500. end
  501. function initPart5()
  502.     floor_count = 106
  503.     corner_count = 80
  504.     wall_count = 140
  505.     roof_count = 120
  506. end
  507.  
  508. --------------------
  509. -- use parts here --
  510. --------------------
  511.  
  512. part1()
  513. part2()
  514. part3()
  515. part4()
  516. part5()
Advertisement
Add Comment
Please, Sign In to add comment