Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Advaced Turtle Moviment
- -- and
- -- Adv Mining System
- -- by leo1553
- posX = 0
- posY = 0
- posZ = 0
- rot = 0
- local rotNames = {"Front", "Left", "Back", "Right"}
- --local args = {...}
- -- Move Functions
- function forward()
- if(turtle.forward() == true) then
- if(rot == 0) then
- posX = posX + 1
- elseif(rot == 1) then
- posZ = posZ + 1
- elseif(rot == 2) then
- posX = posX - 1
- elseif(rot == 3) then
- posZ = posZ - 1
- end
- return true
- end
- return false
- end
- function back()
- if(turtle.back() == true) then
- if(rot == 0) then
- posX = posX - 1
- elseif(rot == 1) then
- posZ = posZ - 1
- elseif(rot == 2) then
- posX = posX + 1
- elseif(rot == 3) then
- posZ = posZ + 1
- end
- return true
- end
- return false
- end
- function up()
- if(turtle.up() == true) then
- posY = posY + 1
- return true
- end
- return false
- end
- function down()
- if(turtle.down() == true) then
- posY = posY - 1
- return true
- end
- return false
- end
- function turnLeft()
- turtle.turnLeft()
- rot = rot - 1
- if(rot < 0) then
- rot = 3
- end
- end
- function turnRight()
- turtle.turnRight()
- rot = rot + 1
- if(rot > 3) then
- rot = 0
- end
- end
- -- Adv Move Functions
- function lookAt(finalRot)
- if(rot == finalRot) then
- return
- end
- local finalValue = rot - finalRot
- if(finalValue < 0) then
- while(rot ~= finalRot) do
- turnRight()
- end
- else
- while(rot ~= finalRot) do
- turnLeft()
- end
- end
- end
- function moveToX(x)
- if(x > posX) then
- lookAt(0)
- else
- lookAt(2)
- end
- while(posX ~= x) do
- forward()
- printPos()
- end
- end
- function moveToY(y)
- if(y < posY) then
- while(posY ~= y) do
- down()
- printPos()
- end
- else
- while(posY ~= y) do
- up()
- printPos()
- end
- end
- end
- function moveToZ(z)
- if(z < posZ) then
- lookAt(3)
- else
- lookAt(1)
- end
- while(posZ ~= z) do
- forward()
- printPos()
- end
- end
- function moveTo(x, y, z) -- Move Only (Do Not Dig)
- moveToY(y)
- moveToZ(z)
- moveToX(x)
- end
- -- Debug Functions
- function getRotationName(rotation)
- return rotNames[rotation + 1]
- end
- function printPos()
- print("Current Pos:".. posX ..", ".. posY ..", ".. posZ .." - ".. getRotationName(rot))
- end
- -- API End
- local digX
- local digY
- local digZ
- local diggedBlocks = 0
- local digOrientation = 1
- local goingToX
- local goingToZ
- local mineBlocks = { false, false }
- local args = {...}
- -- Dig Functions
- function dig()
- if(turtle.detect() == true) then
- if(turtle.dig() == true) then
- return true
- end
- return false
- end
- return true
- end
- function digUp()
- if(turtle.detectUp() == true) then
- if(turtle.digUp() == true) then
- return true
- end
- return false
- end
- return true
- end
- function digDown()
- if(turtle.detectDown() == true) then
- if(turtle.digDown() == true) then
- return true
- end
- return false
- end
- return true
- end
- -- Adv Dig Functions
- function lastDigPos(from, to)
- if(from == to) then
- return to
- elseif(from < to) then
- return to - 1
- else
- return from - 1
- end
- return from
- end
- function digToX(x)
- if(x > posX) then
- lookAt(0)
- else
- lookAt(2)
- end
- while(posX ~= x) do
- if(dig() == false or(mineBlocks[1] == true and digDown() == false) or(mineBlocks[2] == true and digUp() == false)) then
- print("Turtle could not break the block. Stopped.")
- return
- end
- forward()
- printPos()
- end
- if((mineBlocks[1] == true and digDown() == false) or(mineBlocks[2] == true and digUp() == false)) then
- print("Turtle could not break the block. Stopped.")
- return
- end
- end
- function digToY(y)
- if(y < posY) then
- while(posY ~= y) do
- if(digDown() == false) then
- print("Turtle could not break the block. Stopped.")
- return
- end
- down()
- printPos()
- end
- else
- while(posY ~= y) do
- if(digUp() == false) then
- print("Turtle could not break the block. Stopped.")
- return
- end
- up()
- printPos()
- end
- end
- end
- function digToZ(z)
- if(z < posZ) then
- lookAt(3)
- else
- lookAt(1)
- end
- while(posZ ~= z) do
- if(dig() == false or(mineBlocks[1] == true and digDown() == false) or(mineBlocks[2] == true and digUp() == false)) then
- print("Turtle could not break the block. Stopped.")
- return
- end
- forward()
- printPos()
- end
- if((mineBlocks[1] == true and digDown() == false) or(mineBlocks[2] == true and digUp() == false)) then
- print("Turtle could not break the block. Stopped.")
- return
- end
- end
- function digTo(x, y, z)
- if(x ~= 0) then
- x = x - 1
- end
- if(y ~= 0) then
- y = y - 1
- end
- if(z ~= 0) then
- z = z - 1
- end
- digToX(x)
- digToZ(z)
- digToY(y)
- end
- -- API End
- digX = tonumber(args[1])
- digY = tonumber(args[2])
- digZ = tonumber(args[3])
- function updateBreakVar()
- if(digY > posY + 1) then
- if(digY > posY + 2) then
- digUp()
- up()
- mineBlocks = {true, true}
- else
- mineBlocks = {false, true}
- end
- end
- end
- function updateGoingToX()
- if(goingToZ ~= 0) then
- goingToX = 0
- else
- goingToX = digX - 1
- end
- end
- function updateGoingToZ()
- if(goingToZ ~= 0) then
- goingToZ = 0
- else
- goingToZ = digZ - 1
- end
- end
- function changeOriotation()
- digOrientation = digOrientation * -1
- end
- -- Set Variables
- updateBreakVar()
- digOrientation = 1
- goingToX = digX - 1
- goingToZ = digZ - 1
- -- Dig First Line
- digToZ(goingToZ)
- updateGoingToZ()
- while(posY ~= (digY - 1)) do
- while(posX ~= goingToX) do
- digToX(posX + digOrientation)
- digToZ(goingToZ)
- updateGoingToZ()
- end
- if(mineBlocks[2] == true) then
- print("Done 1")
- up()
- end
- if(posY + 1 ~= digY) then
- print("Done 2")
- digToY(posY + 1)
- updateBreakVar()
- changeOriotation()
- updateGoingToX()
- digToZ(goingToZ)
- updateGoingToZ()
- end
- end
- moveTo(0, 0, 0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement