SHARE
TWEET

Untitled

a guest Mar 24th, 2019 62 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. level = {{{4, 3, 1, 1, 1, 1}, {4, 1, 2, 1, 1, 1}, {4, 4, 2, 1, 1, 1}, {4, 1, 2, 2, 3, 1}, {4, 1, 1, 1, 1, 4}}, {{0, 9, 5, 8, 6, 9}, {0, 5, 17, 15, 16, 6}, {0, 10, 0, 0, 11, 6}, {0, 8, 13, 14, 12, 5}, {0, 5, 5, 6, 8, 7}}, {{0, 23, 9, 25, 9, 24}, {26, 9, 25, 0, 26, 8}, {0, 22, 0, 0, 11, 5}, {21, 9, 20, 19, 0, 9}, {0, 9, 6, 5, 9, 18}}, {{0, 0, 8, 5, 24, 0}, {0, 24, 9, 27, 27, 24}, {0, 24, 9, 31, 11, 9}, {0, 5, 27, 19, 29, 28}, {0, 30, 9, 9, 24, 0}}, {{0, 0, 0, 0, 0, 0}, {0, 0, 25, 0, 28, 0}, {0, 0, 9, 9, 32, 0}, {0, 0, 8, 5, 24, 0}, {0, 0, 30, 33, 0, 0}}, {{0, 0, 0, 0, 0, 0}, {0, 0, 25, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 19, 0, 0}, {0, 0, 0, 0, 0, 0}}, {{0, 0, 34, 0, 0, 0}, {0, 0, 24, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 0, 0}}}
  2. backbag = {{4, 4, 4, 4, 4, 4, 4}, {3, 3}, {1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, {2, 2, 2, 2}, {9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9}, {5, 5, 5, 5, 5, 5, 5, 5, 5, 5}, {8, 8, 8, 8, 8, 8}, {6, 6, 6, 6, 6}, {17}, {15}, {16}, {10}, {11, 11, 11}, {13}, {14}}
  3. chest = {{12}, {7}, {23}, {25, 25, 25, 25}, {24, 24, 24, 24, 24, 24, 24, 24}, {26, 26}, {22}, {21}, {20}, {19, 19, 19}, {18}, {27, 27, 27}, {31}, {29}, {28, 28}, {30, 30}, {32}, {33}, {34}}
  4. tempchest = {}
  5. local x = 1
  6. local y = 0
  7. local z = 1
  8. local selectedItem = 1
  9. function forward(dy)
  10.     while dy > y do
  11.         turtle.forward()
  12.         y = y + 1
  13.     end
  14. end
  15. function back(dy)
  16.     while dy < y do
  17.         turtle.back()
  18.         y = y - 1
  19.     end
  20. end
  21. function left(dx)
  22.     turtle.turnLeft()
  23.     while x > dx do
  24.         turtle.forward()
  25.         x = x - 1
  26.     end
  27.     turtle.turnRight()
  28. end
  29. function right(dx)
  30.     turtle.turnRight()
  31.     while x < dx do
  32.         turtle.forward()
  33.         x = x + 1
  34.     end
  35.     turtle.turnLeft()
  36. end
  37. function up(dz)
  38.     while dz > z do
  39.         turtle.up()
  40.         z = z + 1
  41.     end
  42. end
  43. function down(dz)
  44.     while dz < z do
  45.         turtle.down()
  46.         z = z - 1
  47.     end
  48. end
  49.  
  50. function moveto(dx, dy, dz)
  51.     if z < dz then
  52.         up(dz)
  53.     elseif z > dz then
  54.         down(dz)
  55.     end
  56.     if x < dx then
  57.         right(dx)
  58.     elseif x > dx then
  59.         left(dx)
  60.     end
  61.     if y < dy then
  62.         forward(dy)
  63.     elseif y > dy then
  64.         back(dy)
  65.     end
  66. end
  67. function place()
  68.     turtle.placeDown()
  69.     table.remove(backbag[selectedItem])
  70. end
  71. function printchest()
  72.     for a = 1, #backbag do
  73.         if backbag[a] == nil then
  74.             print(nil)
  75.         else
  76.             print(backbag[a][1] ..", len: " ..#backbag[a])
  77.         end
  78.     end
  79. end
  80. function getItemFromChest(id)
  81.     turtle.select(16)
  82.     turtle.placeUp()
  83.     if backbag[1] ~= {} then
  84.         turtle.select(1)
  85.         turtle.dropUp()
  86.         turtle.select(16)
  87.         table.insert(tempchest, backbag[1])
  88.         backbag[1] = nil
  89.     end
  90.     for i = 1, #chest do
  91.         turtle.suckDown()
  92.         items = table.remove(chest,1)
  93.         if items[1] == id then
  94.             turtle.dropDown()
  95.             table.insert(chest,1,items)
  96.             break
  97.         else
  98.             turtle.dropUp()
  99.             table.insert(tempchest, items)
  100.         end
  101.     end
  102.     for i = 1, #tempchest do
  103.         turtle.suckUp()
  104.         turtle.dropDown()
  105.         items = table.remove(tempchest,1)
  106.         table.insert(chest, 1 + i, items)
  107.     end
  108.     turtle.digUp()
  109.     turtle.suckUp()
  110.     turtle.select(1)
  111.     turtle.suckDown()
  112.     items = table.remove(chest,1)
  113.     backbag[1] = items
  114. end
  115. function select(id)
  116.     for dz = 1, #backbag do
  117.         if backbag[dz][1] == id then
  118.             selectedItem = dz
  119.             turtle.select(dz)
  120.             print("SelectedItem: "..selectedItem)
  121.             return true
  122.         end
  123.     end
  124.     moveto(0, -1, 0)
  125.     getItemFromChest(id)
  126.     turtle.select(1)
  127. end
  128.            
  129.    
  130. function buildLoop()
  131.     for dz = 1, #level do
  132.         for dx = 1, #level[1] do
  133.             for dy = 1, #level[1][1] do
  134.                 if level[dz][dx][dy] ~= 0 then
  135.                    select(level[dz][dx][dy])
  136.                    moveto(dx, dy + 1, dz)
  137.                    place()
  138.                 end
  139.             end
  140.         end
  141.     end
  142. end
  143. buildLoop()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top