Advertisement
AyrA

Computercraft Turtle Builder

Jun 30th, 2012
546
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.55 KB | None | 0 0
  1. --Copyright (c) 2012 by AyrA
  2. --You may use this script for free with your Turtle from Computercraft.
  3.  
  4. --MAP
  5. --A Map contains one or multiple Levels
  6. --Each Level is a 2D Representation of its Layer separated in Rows
  7. --Each Row contains a specific amount of Blocks in its list.
  8. --A Block is represented by a single char specifying the slot (A-I) or _ for nothing
  9.  
  10. --You do not need to set or change anything except the Map
  11. --The Script automatically finds out all it needs.
  12. --The map can have "virtually" any size but you can have maximum 9 Stacks of Items in a Turtle
  13.  
  14. --The Map is processed from the First specified Layer to the Last specified.
  15. --Specify the bottom Layer first and the top Layer last.
  16. --Each Layer is processed from top to bottom in script (this is left to right in Minecraft).
  17. -- -> so the Turtle starts from the bottom left and ends at the top right.
  18.  
  19.  
  20. local _=0 --Do nothing
  21. local A=1 --Place Block in specified slot
  22. local B=2 --Place Block in specified slot
  23. local C=3 --Place Block in specified slot
  24. local D=4 --Place Block in specified slot
  25. local E=5 --Place Block in specified slot
  26. local F=6 --Place Block in specified slot
  27. local G=7 --Place Block in specified slot
  28. local H=8 --Place Block in specified slot
  29. local I=9 --Place Block in specified slot
  30.  
  31.  
  32. local MAP=
  33. {
  34.     --Layer 1 start
  35.     {
  36.         {_,_,_,_,_,_,_,_,_}, --Row 1 (the bottom left)
  37.         {_,_,_,_,_,_,_,_,_}, --Row 2
  38.         {_,_,_,_,_,_,_,_,_}, --...
  39.         {_,_,_,_,_,_,_,_,_},
  40.         {_,_,_,_,_,_,_,_,_},
  41.         {_,_,_,_,_,_,_,_,_},
  42.         {_,_,_,_,_,_,_,_,_},
  43.         {_,_,_,_,_,_,_,_,_}
  44.     },
  45.     --Layer 1 end
  46.     {
  47.         {_,_,_,_,_,_,_,_,_},
  48.         {_,_,_,_,_,_,_,_,_},
  49.         {_,_,_,_,_,_,_,_,_},
  50.         {_,_,_,_,_,_,_,_,_},
  51.         {_,_,_,_,_,_,_,_,_},
  52.         {_,_,_,_,_,_,_,_,_},
  53.         {_,_,_,_,_,_,_,_,_},
  54.         {_,_,_,_,_,_,_,_,_}
  55.     },
  56.     {
  57.         {_,_,_,_,_,_,_,_,_},
  58.         {_,_,_,_,_,_,_,_,_},
  59.         {_,_,_,_,_,A,A,A,_},
  60.         {_,_,_,_,_,_,_,_,_},
  61.         {_,_,_,A,A,A,_,_,_},
  62.         {_,_,_,_,_,_,_,_,_},
  63.         {_,A,A,A,_,_,_,_,_},
  64.         {_,_,_,_,_,_,_,_,_}
  65.     },
  66.     {
  67.         {_,_,_,_,_,_,_,_,_},
  68.         {_,_,_,_,_,_,_,_,_},
  69.         {_,_,_,_,_,A,_,_,_},
  70.         {_,_,_,_,_,_,_,_,_},
  71.         {_,_,_,A,_,A,_,_,_},
  72.         {_,_,_,_,_,_,_,_,_},
  73.         {_,A,_,_,_,_,_,_,_},
  74.         {_,_,_,_,_,_,_,_,_}
  75.     },
  76.     {
  77.         {_,_,_,_,_,_,_,_,_},
  78.         {_,_,_,_,_,_,_,_,_},
  79.         {_,_,_,_,_,A,_,_,_},
  80.         {_,_,_,_,_,_,_,_,_},
  81.         {_,_,_,A,_,A,_,_,_},
  82.         {_,_,_,_,_,_,_,_,_},
  83.         {_,A,_,_,_,_,_,_,_},
  84.         {_,_,_,_,_,_,_,_,_}
  85.     },
  86.     {
  87.         {_,_,_,_,_,_,_,_,_},
  88.         {_,_,_,_,_,_,_,_,_},
  89.         {_,_,_,_,_,A,_,_,_},
  90.         {_,_,_,_,_,_,_,_,_},
  91.         {_,_,_,A,A,A,_,_,_},
  92.         {_,_,_,_,_,_,_,_,_},
  93.         {_,A,_,_,_,_,_,_,_},
  94.         {_,_,_,_,_,_,_,_,_}
  95.     }
  96. }
  97.  
  98. function u()
  99.     if turtle.detectUp() then
  100.         turtle.digUp()
  101.     end
  102.     turtle.up()
  103. end
  104. function r()
  105.     turtle.turnRight()
  106. end
  107. function l()
  108.     turtle.turnLeft()
  109. end
  110. function f(num)
  111.     local QQ
  112.     for Q=1,num,1 do
  113.         if turtle.detect() then
  114.             turtle.dig()
  115.         end
  116.         turtle.forward()
  117.     end
  118. end
  119. function p(ID)
  120.     if turtle.detectDown() then
  121.         turtle.digDown()
  122.     end
  123.     if ID>0 and ID<10 then
  124.         turtle.select(ID)
  125.         turtle.placeDown()
  126.     end
  127. end
  128.  
  129. function build()
  130.     local LAYER,ROW,BLOCK
  131.  
  132.     for LAYER=1,#MAP,1 do
  133.         for ROW=1,#MAP[LAYER],1 do
  134.             for BLOCK=1,#MAP[LAYER][ROW],1 do
  135.                 if MAP[LAYER][ROW][BLOCK]==_ then
  136.                     --Remove existing block (if any)
  137.                     p(0)
  138.                 else
  139.                     --place specified Block
  140.                     p(MAP[LAYER][ROW][BLOCK])
  141.                 end
  142.                 if BLOCK<#MAP[LAYER][ROW] then
  143.                     --Next Block
  144.                     f(1)
  145.                 else
  146.                     --Next Row
  147.                     r()
  148.                     f(1)
  149.                     r()
  150.                     f(BLOCK-1)
  151.                     r()
  152.                     r()
  153.                 end
  154.             end
  155.             if ROW==#MAP[LAYER] then
  156.                 u()
  157.                 l()
  158.                 f(#MAP[LAYER])
  159.                 r()
  160.             end
  161.         end
  162.     end
  163. end
  164.  
  165. build()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement