Advertisement
Guest User

Demosthenex's Turtle HP Turbine Builder

a guest
Jul 21st, 2014
803
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.70 KB | None | 0 0
  1. -- Zero origin dead reckoning movement in 20 lines
  2. -- Always face forward, x & y & z are relative to our initial position
  3. -- Positive X is right of front, positive Y is forward, positive Z is up
  4.  
  5. current = { x=0, y=0, z=0 }
  6.  
  7. move = { x = { forward = turtle.forward, back = turtle.back },
  8.          y = { forward = turtle.forward, back = turtle.back },
  9.          z = { forward = turtle.up,      back = turtle.down }}
  10.  
  11. function walkAxis(axis, destinationCoord)
  12.    delta = destinationCoord - current[axis]
  13.    if delta == 0 then return nil end
  14.    (destinationCoord > current[axis] and move[axis]['forward'] or move[axis]['back'])()
  15.    current[axis] = (delta / math.abs(delta)) + current[axis]
  16.    walkAxis(axis, destinationCoord)
  17. end
  18.  
  19. function walkTo(x,y,z)
  20.    if x ~= current['x'] then
  21.       turtle.turnRight()
  22.       walkAxis('x', x)
  23.       turtle.turnLeft()
  24.    end
  25.    walkAxis('y', y)
  26.    walkAxis('z', z)
  27. end
  28.  
  29. -- Inventory requirements by slot
  30. -- Slot    Qty    Item
  31.  
  32. items = {
  33.    { qty =     1, desc = "Steam line"},
  34.    { qty =     8, desc = "Steam Injector"},
  35.    { qty =    64, desc = "Turbine Housing"},
  36.    { qty =    64, desc = "Turbine Housing"},
  37.    { qty =    64, desc = "Turbine Housing"},
  38.    { qty =    20, desc = "Turbine Housing"},
  39.    { qty =    64, desc = "Turbine Blades"},
  40.    { qty =    64, desc = "Turbine Blades"},
  41.    { qty =     8, desc = "Turbine Blades"},
  42.    { qty =     7, desc = "HP turbine block"}}
  43.  
  44.  
  45. for slot, item in ipairs(items) do
  46.    count = turtle.getItemCount(slot)
  47.    if count < item.qty then
  48.       print ("Have " .. count .. "in slot " .. slot .. ", expected " .. item.qty .. " of " .. item.desc)
  49.    end
  50. end
  51.  
  52. -- Pattern is in x, z, y format.
  53.  
  54. pattern = {
  55.     {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  56.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  57.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  58.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  59.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  60.      {  0,  0,  0,  0,  0,  2,  2,  2,  0,  0,  0,  0,  0 },
  61.      {  0,  0,  0,  0,  0,  2,  1,  2,  0,  0,  0,  0,  0 },
  62.      {  0,  0,  0,  0,  0,  2,  2,  2,  0,  0,  0,  0,  0 },
  63.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  64.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  65.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  66.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  67.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }},
  68.  
  69.     {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  70.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  71.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  72.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  73.      {  0,  0,  0,  0,  0,  3,  3,  3,  0,  0,  0,  0,  0 },
  74.      {  0,  0,  0,  0,  3,  3,  3,  3,  3,  0,  0,  0,  0 },
  75.      {  0,  0,  0,  0,  3,  3, 10,  3,  3,  0,  0,  0,  0 },
  76.      {  0,  0,  0,  0,  3,  3,  3,  3,  3,  0,  0,  0,  0 },
  77.      {  0,  0,  0,  0,  0,  3,  3,  3,  0,  0,  0,  0,  0 },
  78.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  79.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  80.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  81.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }},
  82.  
  83.     {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  84.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  85.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  86.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  87.      {  0,  0,  0,  0,  3,  3,  3,  3,  3,  0,  0,  0,  0 },
  88.      {  0,  0,  0,  0,  3,  3,  7,  3,  3,  0,  0,  0,  0 },
  89.      {  0,  0,  0,  0,  3,  7, 10,  7,  3,  0,  0,  0,  0 },
  90.      {  0,  0,  0,  0,  3,  3,  7,  3,  3,  0,  0,  0,  0 },
  91.      {  0,  0,  0,  0,  3,  3,  3,  3,  3,  0,  0,  0,  0 },
  92.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  93.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  94.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  95.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }},
  96.  
  97.     {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  98.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  99.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  100.      {  0,  0,  0,  0,  0,  3,  3,  3,  0,  0,  0,  0,  0 },
  101.      {  0,  0,  0,  0,  3,  3,  3,  3,  3,  0,  0,  0,  0 },
  102.      {  0,  0,  0,  3,  3,  7,  7,  7,  3,  3,  0,  0,  0 },
  103.      {  0,  0,  0,  3,  3,  7, 10,  7,  3,  3,  0,  0,  0 },
  104.      {  0,  0,  0,  3,  3,  7,  7,  7,  3,  3,  0,  0,  0 },
  105.      {  0,  0,  0,  0,  3,  3,  3,  3,  4,  0,  0,  0,  0 },
  106.      {  0,  0,  0,  0,  0,  4,  4,  4,  0,  0,  0,  0,  0 },
  107.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  108.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  109.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }},
  110.  
  111.     {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  112.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  113.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  114.      {  0,  0,  0,  0,  4,  4,  4,  4,  4,  0,  0,  0,  0 },
  115.      {  0,  0,  0,  4,  4,  7,  7,  7,  4,  4,  0,  0,  0 },
  116.      {  0,  0,  0,  4,  7,  7,  7,  7,  7,  4,  0,  0,  0 },
  117.      {  0,  0,  0,  4,  7,  7, 10,  7,  7,  4,  0,  0,  0 },
  118.      {  0,  0,  0,  4,  7,  7,  7,  7,  7,  4,  0,  0,  0 },
  119.      {  0,  0,  0,  4,  4,  7,  7,  7,  4,  4,  0,  0,  0 },
  120.      {  0,  0,  0,  0,  4,  4,  4,  4,  4,  0,  0,  0,  0 },
  121.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  122.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  123.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }},
  124.  
  125.     {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  126.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  127.      {  0,  0,  0,  0,  0,  4,  4,  4,  0,  0,  0,  0,  0 },
  128.      {  0,  0,  0,  4,  4,  4,  4,  4,  4,  4,  0,  0,  0 },
  129.      {  0,  0,  0,  4,  4,  7,  7,  7,  4,  4,  0,  0,  0 },
  130.      {  0,  0,  4,  4,  7,  7,  7,  7,  7,  4,  4,  0,  0 },
  131.      {  0,  0,  4,  4,  7,  7, 10,  7,  7,  4,  4,  0,  0 },
  132.      {  0,  0,  4,  4,  7,  7,  7,  7,  7,  4,  4,  0,  0 },
  133.      {  0,  0,  0,  4,  4,  7,  7,  7,  4,  4,  0,  0,  0 },
  134.      {  0,  0,  0,  4,  4,  4,  4,  4,  4,  5,  0,  0,  0 },
  135.      {  0,  0,  0,  0,  0,  5,  5,  5,  0,  0,  0,  0,  0 },
  136.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  137.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }},
  138.  
  139.     {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  140.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  141.      {  0,  0,  0,  0,  5,  5,  5,  5,  5,  0,  0,  0,  0 },
  142.      {  0,  0,  0,  5,  5,  7,  7,  7,  5,  5,  0,  0,  0 },
  143.      {  0,  0,  5,  5,  7,  7,  7,  7,  7,  5,  5,  0,  0 },
  144.      {  0,  0,  5,  7,  7,  7,  7,  8,  8,  8,  5,  0,  0 },
  145.      {  0,  0,  5,  8,  8,  8, 10,  8,  8,  8,  5,  0,  0 },
  146.      {  0,  0,  5,  8,  8,  8,  8,  8,  8,  8,  5,  0,  0 },
  147.      {  0,  0,  5,  5,  8,  8,  8,  8,  8,  5,  5,  0,  0 },
  148.      {  0,  0,  0,  5,  5,  8,  8,  8,  5,  5,  0,  0,  0 },
  149.      {  0,  0,  0,  0,  5,  5,  5,  5,  5,  0,  0,  0,  0 },
  150.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  151.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }},
  152.  
  153.     {{  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 },
  154.      {  0,  0,  0,  0,  5,  5,  5,  5,  5,  0,  0,  0,  0 },
  155.      {  0,  0,  0,  5,  5,  5,  8,  5,  5,  5,  0,  0,  0 },
  156.      {  0,  0,  5,  5,  8,  8,  8,  8,  8,  5,  5,  0,  0 },
  157.      {  0,  5,  5,  8,  8,  8,  8,  8,  8,  8,  5,  5,  0 },
  158.      {  0,  5,  5,  8,  8,  8,  8,  8,  8,  8,  5,  5,  0 },
  159.      {  0,  5,  8,  8,  8,  8, 10,  8,  8,  8,  8,  5,  0 },
  160.      {  0,  5,  5,  8,  8,  8,  8,  8,  8,  8,  5,  6,  0 },
  161.      {  0,  6,  6,  8,  8,  8,  8,  8,  9,  9,  6,  6,  0 },
  162.      {  0,  0,  6,  6,  9,  9,  9,  9,  9,  6,  6,  0,  0 },
  163.      {  0,  0,  0,  6,  6,  6,  9,  6,  6,  6,  0,  0,  0 },
  164.      {  0,  0,  0,  0,  6,  6,  6,  6,  6,  0,  0,  0,  0 },
  165.      {  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0,  0 }}}
  166.  
  167. -- MAIN --
  168.  
  169. -- CUSTOM: I start the turtle on the ground, I need to refuel from slot 16 and gain height before beginning
  170. turtle.select(16)
  171. turtle.refuel(64)
  172.  
  173. for height = 1, 25 do
  174.    turtle.up()
  175. end
  176. -- END CUSTOM
  177.  
  178. -- Build the pattern
  179. for y = 1, #pattern do
  180.    for z = 1, #pattern[y] do
  181.       for x = z % 2 == 0 and 1 or #pattern[y][z],  z % 2 == 0 and #pattern[y][z] or 1, z % 2 == 0 and 1 or -1 do
  182.          item = pattern[y][z][x]
  183.          if item ~= 0 then
  184.             walkTo(x, -y, -z)
  185.             turtle.select(item)
  186.             turtle.place()
  187.          end
  188.       end
  189.    end
  190. end
  191.  
  192. -- CUSTOM: Step back on completion
  193. for step = 1, 5 do
  194.    turtle.back()
  195. end
  196. -- END CUSTOM
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement