Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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}}}
- 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}}
- 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}}
- tempchest = {}
- local x = 1
- local y = 0
- local z = 1
- local selectedItem = 1
- function forward(dy)
- while dy > y do
- turtle.forward()
- y = y + 1
- end
- end
- function back(dy)
- while dy < y do
- turtle.back()
- y = y - 1
- end
- end
- function left(dx)
- turtle.turnLeft()
- while x > dx do
- turtle.forward()
- x = x - 1
- end
- turtle.turnRight()
- end
- function right(dx)
- turtle.turnRight()
- while x < dx do
- turtle.forward()
- x = x + 1
- end
- turtle.turnLeft()
- end
- function up(dz)
- while dz > z do
- turtle.up()
- z = z + 1
- end
- end
- function down(dz)
- while dz < z do
- turtle.down()
- z = z - 1
- end
- end
- function moveto(dx, dy, dz)
- if z < dz then
- up(dz)
- elseif z > dz then
- down(dz)
- end
- if x < dx then
- right(dx)
- elseif x > dx then
- left(dx)
- end
- if y < dy then
- forward(dy)
- elseif y > dy then
- back(dy)
- end
- end
- function place()
- turtle.placeDown()
- table.remove(backbag[selectedItem])
- end
- function printchest()
- for a = 1, #backbag do
- if backbag[a] == nil then
- print(nil)
- else
- print(backbag[a][1] ..", len: " ..#backbag[a])
- end
- end
- end
- function getItemFromChest(id)
- turtle.select(16)
- turtle.placeUp()
- if backbag[1] ~= {} then
- turtle.select(1)
- turtle.dropUp()
- turtle.select(16)
- table.insert(tempchest, backbag[1])
- backbag[1] = nil
- end
- for i = 1, #chest do
- turtle.suckDown()
- items = table.remove(chest,1)
- if items[1] == id then
- turtle.dropDown()
- table.insert(chest,1,items)
- break
- else
- turtle.dropUp()
- table.insert(tempchest, items)
- end
- end
- for i = 1, #tempchest do
- turtle.suckUp()
- turtle.dropDown()
- items = table.remove(tempchest,1)
- table.insert(chest, 1 + i, items)
- end
- turtle.digUp()
- turtle.suckUp()
- turtle.select(1)
- turtle.suckDown()
- items = table.remove(chest,1)
- backbag[1] = items
- end
- function select(id)
- for dz = 1, #backbag do
- if backbag[dz][1] == id then
- selectedItem = dz
- turtle.select(dz)
- print("SelectedItem: "..selectedItem)
- return true
- end
- end
- moveto(0, -1, 0)
- getItemFromChest(id)
- turtle.select(1)
- end
- function buildLoop()
- for dz = 1, #level do
- for dx = 1, #level[1] do
- for dy = 1, #level[1][1] do
- if level[dz][dx][dy] ~= 0 then
- select(level[dz][dx][dy])
- moveto(dx, dy + 1, dz)
- place()
- end
- end
- end
- end
- end
- buildLoop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement