Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local startpos = vector.new(0, 0, 0)
- local toDig = 66
- local width = 31
- local length = 31
- local refuelLevel = 5000
- local sleepTime = 0.5
- local currentpos = vector.new(0, 0, 0)
- local fuelName = "minecraft:coal"
- local direction = 0
- local success = false
- local startDepth = 35
- local resume_x = 0
- local resume_z = 0
- local resume_y = 0
- local resume_direction = 0
- local turn = 0
- local breakTime = false
- function debugPos()
- print("x: "..currentpos.x);
- print("y: "..currentpos.y);
- print("z: "..currentpos.z);
- end
- function face(fDir)
- while(direction ~= fDir) do
- turtle.turnRight()
- sleep(sleepTime)
- direction = direction + 1
- if(direction > 3) then
- direction = direction - 4
- elseif(direction < 0) then
- direction = direction + 4
- end
- end
- end
- function isEmpty()
- local i = 1
- i = 1
- while(i <= 16) do
- if(turtle.getItemCount(i) == 0) then
- return true
- end
- end
- if(i >= 16) then
- return false
- end
- end
- function mRefuel(f_x)
- local i = 1
- while(turtle.getFuelLevel() < f_x) do
- face(3)
- turtle.suck(64)
- while(i < 17) do
- turtle.select(i)
- turtle.refuel()
- i = i + 1
- end
- turtle.select(1)
- i = 1
- print("Refuel Loop End")
- end
- face(0)
- print("Refueled")
- end
- function checkCoal()
- if(turtle.getItemDetail(1).name == fuelName) then
- return turtle.getItemDetail(1).count
- else
- return 0
- end
- end
- function updatePos()
- if(direction == 0) then
- currentpos.z = currentpos.z + 1
- elseif(direction == 1) then
- currentpos.x = currentpos.x + 1
- elseif(direction == 2) then
- currentpos.z = currentpos.z - 1
- elseif(direction == 3) then
- currentpos.x = currentpos.x - 1
- end
- end
- function goHome()
- local home = false
- resume_x = currentpos.x
- resume_z = currentpos.z
- resume_direction = direction
- while(not home) do
- if(currentpos.x == 0 and currentpos.y == 0 and currentpos.z == 0) then
- home = true
- break
- end
- while(currentpos.x ~= 0) do
- if(currentpos.x > 0) then
- if(direction ~= 3) then
- turtle.turnLeft()
- direction = direction - 1
- sleep(sleepTime)
- if(direction > 3) then
- direction = direction - 4
- elseif(direction < 0) then
- direction = direction + 4
- end
- end
- if(direction == 3) then
- while(success == false) do
- success = turtle.forward()
- end
- success = false
- updatePos()
- sleep(sleepTime)
- end
- elseif(currentpos.x < 0) then
- if(direction ~= 1) then
- turtle.turnLeft()
- direction = direction - 1
- sleep(sleepTime)
- if(direction > 3) then
- direction = direction - 4
- elseif(direction < 0) then
- direction = direction + 4
- end
- end
- if(direction == 1) then
- while(success == false) do
- success = turtle.forward()
- end
- success = false
- updatePos()
- sleep(sleepTime)
- end
- end
- end
- print("x is 0")
- while(currentpos.z ~= 0) do
- if(currentpos.z > 0) then
- if(direction ~= 2) then
- turtle.turnLeft()
- direction = direction - 1
- sleep(sleepTime)
- if(direction > 3) then
- direction = direction - 4
- elseif(direction < 0) then
- direction = direction + 4
- end
- end
- if(direction == 2) then
- while(success == false) do
- success = turtle.forward()
- end
- success = false
- updatePos()
- sleep(sleepTime)
- end
- elseif(currentpos.z < 0) then
- if(direction ~= 0) then
- turtle.turnLeft()
- direction = direction - 1
- sleep(sleepTime)
- if(direction > 3) then
- direction = direction - 4
- elseif(direction < 0) then
- direction = direction + 4
- end
- end
- if(direction == 0) then
- while(success == false) do
- success = turtle.forward()
- end
- success = false
- updatePos()
- sleep(sleepTime)
- end
- end
- end
- print("z is 0")
- home = true
- while(direction ~= 0) do
- turtle.turnLeft()
- sleep(sleepTime)
- direction = direction - 1
- if(direction > 3) then
- direction = direction - 4
- elseif(direction < 0) then
- direction = direction + 4
- end
- end
- end
- face(0)
- end
- function yHome()
- resume_y = currentpos.y
- while(currentpos.y ~= 0) do
- if(currentpos.y > 0) then
- while(success == false) do
- success = turtle.up()
- sleep(sleepTime)
- end
- success = false
- currentpos.y = currentpos.y - 1
- end
- if(currentpos.y < 0) then
- while(success == false) do
- success = turtle.down()
- sleep(sleepTime)
- end
- success = false
- currentpos.y = currentpos.y + 1
- end
- end
- print("I am home")
- end
- function resume()
- while(currentpos.y < resume_y) do
- success = turtle.down()
- if(success) then
- currentpos.y = currentpos.y + 1
- end
- success = false
- sleep(sleepTime)
- if(currentpos.y >= resume_y) then
- currentpos.y = resume_y
- end
- end
- while(currentpos.x < resume_x) do
- face(1)
- success = turtle.forward()
- if(success) then
- currentpos.x = currentpos.x + 1
- end
- success = false
- sleep(sleepTime)
- if(currentpos.x >= resume_x) then
- currentpos.x = resume_x
- end
- end
- while(currentpos.z < resume_z) do
- face(0)
- success = turtle.forward()
- if(success) then
- currentpos.z = currentpos.z + 1
- end
- success = false
- sleep(sleepTime)
- if(currentpos.z >= resume_z) then
- currentpos.z = resume_z
- end
- end
- face(resume_direction)
- end
- function Forward()
- success = turtle.forward()
- sleep(sleepTime)
- while(not success) do
- turtle.dig()
- sleep(sleepTime)
- success = turtle.forward()
- sleep(sleepTime)
- end
- success = false
- end
- function Down()
- success = turtle.down()
- sleep(sleepTime)
- while(not success) do
- turtle.digDown()
- sleep(sleepTime)
- success = turtle.down()
- sleep(sleepTime)
- end
- success = false
- end
- function TurnRight()
- turtle.turnRight()
- sleep(sleepTime)
- direction = direction + 1
- if(direction > 3) then
- direction = direction - 4
- elseif(direction < 0) then
- direction = direction + 4
- end
- end
- function TurnLeft()
- turtle.turnLeft()
- sleep(sleepTime)
- direction = direction - 1
- if(direction > 3) then
- direction = direction - 4
- elseif(direction < 0) then
- direction = direction + 4
- end
- end
- function MineCurrentLayer()
- breakTime = false
- turn = 0
- while(currentpos.x < width) do
- if(turn == 0) then
- while(currentpos.z < length - 1) do
- turtle.digDown()
- Forward()
- updatePos()
- end
- elseif(turn == 1)then
- while(currentpos.z > 0) do
- turtle.digDown()
- Forward()
- updatePos()
- end
- end
- turtle.digDown()
- sleep(sleepTime)
- --Break Time
- dropCobble()
- breakTime = isEmpty()
- if(turtle.getFuelLevel() < (refuelLevel/2) or (not breakTime))then
- goHome()
- yHome()
- face(2)
- dropAll()
- face(0)
- mRefuel(refuelLevel)
- resume()
- end
- --Break Time End
- --Turn Corner to next strip
- if(turn == 0) then
- TurnRight()
- elseif(turn == 1) then
- TurnLeft()
- end
- if(currentpos.x == width - 1) then
- break
- end
- if(currentpos.x < width - 1) then
- Forward()
- updatePos()
- end
- turtle.digDown()
- sleep(sleepTime)
- if(turn == 0) then
- TurnRight()
- elseif(turn == 1) then
- TurnLeft()
- end
- if(turn == 0) then
- turn = 1
- elseif(turn == 1) then
- turn = 0
- end
- --End of turning corner
- end
- end
- function dropCobble()
- local i = 1
- while(i < 17) do
- turtle.select(i)
- if(turtle.getItemCount() > 0)then
- if(turtle.getItemDetail().name == "minecraft:cobblestone") then
- turtle.drop()
- end
- end
- if(turtle.getItemCount() > 0)then
- if(turtle.getItemDetail().name == "minecraft:dirt") then
- turtle.drop()
- end
- end
- if(turtle.getItemCount() > 0)then
- if(turtle.getItemDetail().name == "minecraft:gravel") then
- turtle.drop()
- end
- end
- i = i + 1
- end
- turtle.select(1)
- end
- function dropAll()
- local i = 1
- while(i < 17) do
- turtle.select(i)
- turtle.drop()
- i = i + 1
- end
- end
- function GoDepth()
- while(currentpos.y < startDepth) do
- Down()
- currentpos.y = currentpos.y + 1
- print("Down")
- end
- print("I am there")
- end
- function startMine()
- print("Start mining operation")
- while(currentpos.y < toDig) do
- MineCurrentLayer()
- goHome()
- Down()
- currentpos.y = currentpos.y + 1
- sleep(sleepTime)
- end
- end
- mRefuel(refuelLevel)
- GoDepth(startDepth)
- startMine()
- goHome()
- yHome()
- face(2)
- dropAll()
- debugPos()
- sleep(5)
- goHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement