Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w = 10
- local l = 15
- local h = 8
- local cur_x = 5
- local cur_y = 0
- local cur_z = 5
- local storage_x = 5
- local storage_y = 1
- local storage_z = 6
- function Refuel()
- if(turtle.getFuelLevel() <= 400) then
- turtle.select(1)
- local fuel = turtle.getItemCount(1) - 1
- print("Refueling " .. fuel .. " units")
- turtle.refuel(fuel)
- end
- end
- function Mine(blocks)
- --print("Mining " .. blocks .. " blocks")
- for y = 1,blocks,1 do
- while(turtle.detect()) do
- turtle.dig()
- sleep(0.5)
- end
- turtle.forward()
- cur_y = cur_y + 1
- while(turtle.detectUp()) do
- turtle.digUp()
- sleep(0.5)
- end
- turtle.digDown()
- end
- end
- function checkLevelFinished()
- if(cur_x == w) then
- print("Finished level, heading home")
- if(cur_x % 2 == 0) then
- turtle.turnRight()
- turtle.turnRight()
- Dump()
- else
- turtle.turnRight()
- turtle.turnRight()
- for i = 1,l-1,1 do
- turtle.forward()
- cur_y = cur_y - 1
- end
- turtle.turnLeft()
- turtle.turnLeft()
- Dump()
- end
- return true
- else
- return false
- end
- end
- function TryDumping()
- if(turtle.getItemCount(15) > 0) then
- Dump()
- GoTo(cur_x - storage_x, cur_z - storage_z)
- return true
- else
- return false
- end
- end
- function GoTo(x, z)
- if(z > 0) then
- while(z > 0) do
- if(turtle.detectDown()) then
- turtle.digDown()
- end
- turtle.down()
- z = z - 1
- end
- else
- while(z < 0) do
- if(turtle.detectUp()) then
- turtle.digUp()
- end
- turtle.up()
- z = z + 1
- end
- end
- if(x > 0) then
- turtle.turnRight()
- while(x > 0) do
- if(turtle.detect()) then
- turtle.dig()
- end
- turtle.forward()
- x = x - 1
- end
- else
- turtle.turnLeft()
- while(x < 0) do
- if(turtle.detect()) then
- turtle.dig()
- end
- turtle.forward()
- x = x + 1
- end
- end
- end
- function Dump()
- print("Going home to dump items into storage")
- local offset_x = cur_x - storage_x
- if(offset_x < 0) then
- offset_x = offset_x * (-1)
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- for i = offset_x,2,-1 do
- turtle.forward()
- end
- local offset_z = cur_z - storage_z
- if(offset_z < 0) then
- offset_z = offset_z * (-1)
- for i = offset_z,1,-1 do
- turtle.down()
- end
- else
- for i = offset_z,0,-1 do
- turtle.up()
- end
- end
- if(cur_x - storage_x < 0) then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- print("Dumping items into storage")
- local turned = false
- local i = 16
- while(i >= 2) do
- turtle.select(i)
- while(turtle.getItemCount(i) <= 0) do
- i = i - 1
- turtle.select(i)
- end
- local item = string.sub(turtle.getItemDetail(i).name, 11)
- if(item == "coal") then
- turtle.transferTo(1, turtle.getItemCount(i))
- else
- turtle.drop()
- end
- i = i - 1
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- function RotateRight()
- --print("Rotating right")
- turtle.turnRight()
- Mine(1)
- turtle.turnRight()
- end
- function RotateLeft()
- --print("Rotating left")
- turtle.turnLeft()
- Mine(1)
- turtle.turnLeft()
- end
- function Run()
- while(cur_z > 2) do
- if(turtle.detectUp()) then
- turtle.digUp()
- end
- turtle.up()
- cur_z = cur_z - 1
- end
- if(turtle.detect()) then
- turtle.dig()
- end
- turtle.forward()
- turtle.turnLeft()
- while(cur_x > 1) do
- if(turtle.detect()) then
- turtle.dig()
- end
- turtle.forward()
- cur_x = cur_x - 1
- end
- turtle.turnRight()
- while(cur_z <= h - 1) do
- print("Starting to mine levels " .. cur_z - 1 .. ", " .. cur_z .. ", " .. cur_z + 1 .. " of " .. h)
- while(cur_x <= w) do
- Refuel()
- Mine(l - 1)
- if(checkLevelFinished()) then break end
- RotateRight()
- cur_x = cur_x + 1
- Refuel()
- Mine(l - 1)
- if(checkLevelFinished()) then break end
- RotateLeft()
- TryDumping()
- end
- if(cur_z == h - 1) then
- print("Finished work, heading home")
- Dump()
- turtle.up()
- turtle.forward()
- turtle.turnRight(2)
- break
- end
- GoTo(1, cur_z + 2)
- if(h % 2 == 0) then
- turtle.down()
- turtle.digDown()
- cur_z = cur_z + 1
- end
- cur_x = 1
- end
- print("Finished mining a " .. w .. "x" .. l .. "x" .. h .. " area")
- end
- Run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement