Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- length = 5
- width = 5
- depth = 5
- --put unwanted item (eg. cobblestone) in slot 16
- -----------
- facing = 0 --relative, 0=north, 1=east, etc
- x, y, z = 0, 0, 0
- moveState = 0
- width = width - 1
- function output(x, y, z, facing)
- term.clear()
- term.setCursorPos(1,1)
- print("X Position: "..x)
- print("Y Position: "..y)
- print("Z Position: "..z)
- print("Facing: "..facing)
- end
- function left(amount, facing)
- for i=1, amount do
- turtle.turnLeft()
- facing = facing - 1
- if (facing == -1) then
- facing = 3
- end
- end
- return facing
- end
- function right(amount, facing)
- for i=1, amount do
- turtle.turnRight()
- facing = facing + 1
- if (facing == 4) then
- facing = 0
- end
- end
- return facing
- end
- function dig(direction, distance, dig, attack, drop, x, y, z, facing)
- --direction 0 = forward, 1 up, -1 down
- output(x, y, z, facing)
- x = x or false
- y = y or false
- z = z or false
- dig = dig or false
- attack = attack or false
- drop = drop or false
- for i=1, distance do
- if (direction == 0) then
- while (turtle.forward() == false) do
- if (dig == true) then
- turtle.dig()
- end
- if (attack == true) then
- turtle.attack()
- end
- end
- if (facing == 0) then
- z = z + 1
- elseif (facing == 1) then
- x = x + 1
- elseif (facing == 2) then
- z = z - 1
- elseif (facing == 3) then
- x = x - 1
- end
- output(x, y, z, facing)
- end
- if (direction == -1) then
- while (turtle.down() == false) do
- if (dig == true) then
- turtle.digDown()
- end
- if (attack == true) then
- turtle.attackDown()
- end
- end
- y = y - 1
- output(x, y, z, facing)
- end
- if (direction == 1) then
- while (turtle.up() == false) do
- if (dig == true) then
- turtle.digUp()
- end
- if (attack == true) then
- turtle.attackUp()
- end
- end
- y = y + 1
- output(x, y, z, facing)
- end
- if (turtle.getItemCount(15) > 0 and drop == true) then
- for i=1, 15 do
- turtle.select(i)
- if (turtle.compareTo(16) == true) then
- turtle.drop()
- turtle.select(15)
- turtle.transferTo(i)
- end
- end
- turtle.select(1)
- if (turtle.getItemCount(15) > 0) then
- deposit(x, y, z, facing)
- end
- end
- end
- return x, y, z
- end
- function deposit(x, y, z, facing, finished)
- finished = finished or false
- oldDir = facing
- output(x, y, z, facing)
- for i=1, -y do
- while (turtle.up() == false) do
- turtle.attackUp()
- end
- end
- while (facing ~= 1) do
- facing = right(1, facing)
- end
- for i=1, -x do
- while (turtle.forward() == false) do
- turtle.attack()
- end
- end
- facing = right(1, facing)
- for i=1, z do
- while (turtle.forward() == false) do
- turtle.attack()
- end
- end
- for i=1, 15 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- if (finished == false) then
- facing = right(2, facing)
- for i=1, z do
- while (turtle.forward() == false) do
- turtle.attack()
- end
- end
- facing = left(1, facing)
- for i=1, -x do
- while (turtle.forward() == false) do
- turtle.attack()
- end
- end
- for i=1, -y do
- while (turtle.down() == false) do
- turtle.attackDown()
- end
- end
- while (facing ~= oldDir) do
- facing = right(1, facing)
- end
- end
- end
- for d=1, depth do
- for l=1, length do
- if (moveState % 2 == 0) then
- facing = left(1, facing)
- x, y, z = dig(0, width, true, true, true, x, y, z, facing)
- facing = right(1, facing)
- if (l ~= length) then
- x, y, z = dig(0, 1, true, true, true, x, y, z, facing)
- end
- end
- if (moveState % 2 == 1) then
- facing = right(1, facing)
- x, y, z = dig(0, width, true, true, true, x, y, z, facing)
- facing = left(1, facing)
- if (l ~= length) then
- x, y, z = dig(0, 1, true, true, true, x, y, z, facing)
- end
- end
- moveState = moveState + 1
- end
- facing = right(2, facing)
- if (d ~= depth) then
- x, y, z = dig(-1, 1, true, true, true, x, y, z, facing)
- end
- moveState = moveState + 1
- end
- deposit(x, y, z, facing, true)
- term.clear()
- term.setCursorPos(1,1)
- print("Done!")
Advertisement
Add Comment
Please, Sign In to add comment