Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("enter the size (NxN):")
- n = tonumber(read())
- per_layer = n*n
- x = 0
- y = 0
- z = 0
- depth = 0
- dir = 0
- function updatePos()
- if dir == 0 then
- y = y + 1
- elseif dir == 1 then
- x = x + 1
- elseif dir == 2 then
- y = y - 1
- elseif dir == 3 then
- x = x - 1
- end
- end
- function dig()
- turtle.digUp()
- turtle.digDown()
- end
- function refuel()
- local fuel = turtle.getFuelLevel()
- if fuel == 0 then
- turtle.refuel(1)
- end
- end
- function forward()
- refuel()
- turtle.dig()
- while turtle.attack() do
- turtle.attack()
- end
- turtle.forward()
- updatePos()
- end
- function right()
- turtle.turnRight()
- if dir == 3 then
- dir = 0
- else
- dir = dir + 1
- end
- end
- function left()
- turtle.turnLeft()
- if dir == 0 then
- dir = 3
- else
- dir = dir - 1
- end
- end
- function down()
- local success, data = turtle.inspectDown()
- if success then
- if data.name == "minecraft:bedrock" then
- return false
- end
- end
- refuel()
- turtle.digDown()
- while turtle.attackDown() do
- turtle.attackDown()
- end
- turtle.down()
- z = z - 1
- return true
- end
- function up()
- refuel()
- turtle.digUp()
- while turtle.attackDown() do
- turtle.attackDown()
- end
- turtle.up()
- z = z + 1
- end
- function deposit()
- for i=2,16 do
- turtle.select(i)
- turtle.drop()
- end
- end
- function getFuel()
- turtle.select(1)
- count = turtle.getItemCount()
- if count ~= 64 then
- turtle.suck(64 - count)
- end
- end
- function returnToChest()
- if dir == 0 then
- left()
- elseif dir == 1 then
- right()
- right()
- elseif dir == 2 then
- right()
- end
- for i=1,x do
- forward()
- end
- left()
- for i=1,y do
- forward()
- end
- right()
- right()
- for i=z,-1 do
- up()
- end
- right()
- right()
- deposit()
- right()
- getFuel()
- right()
- end
- function returnToDepth()
- for i=1,depth do
- down()
- end
- end
- function shouldReturn()
- if (turtle.getItemCount(1)-1) * 80 < per_layer + x + y + z + 1 then
- return true
- end
- stacks_needed = math.floor(per_layer / 64)
- if turtle.getItemCount(16 - stacks_needed) ~= 0 then
- return true
- end
- return false
- end
- while true do
- for x=1,n do
- for y=1,n do
- dig()
- if y ~= n then
- forward()
- end
- end
- if x ~= n then
- if x % 2 == 1 then
- right()
- forward()
- right()
- else
- left()
- forward()
- left()
- end
- end
- end
- if shouldReturn() then
- returnToChest()
- returnToDepth()
- else
- if dir == 0 then
- left()
- elseif dir == 1 then
- right()
- right()
- elseif dir == 2 then
- right()
- end
- for i=1,x do
- forward()
- end
- left()
- for i=1,y do
- forward()
- end
- right()
- right()
- end
- if not down() then
- returnToChest()
- break
- end
- depth = depth + 1
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement