-- The identifier of this program is vHc0EfGD
-- This program implements the flying quarry mining turtles
-- This is the variable declaration section of the program
quarryLength = 11 quarryWidth = quarryLength quarryDepth = 3
xStart = -696 zStart = -3484 yStart = 50 orientationStart = 4
chestX = -701 chestZ = -3484 chestY = 89 chestOrientation = 3
progressX =0 progressZ = 0 progressY = 0 progressOrientation = 0
xCoord = chestX -- East and west coordinates
zCoord = chestZ -- North and south coordinates
yCoord = chestY -- Vertical coordinates
orientation = chestOrientation
directions = {"north", "east", "south", "west"} -- Directions indexed as 1 to 4
xDiff = {0, 1, 0, -1}
zDiff = {-1, 0, 1, 0}
-- This is the function declaration section of the program
local function tryDig() -- This function digs forward one block
while turtle.detect() do
if turtle.dig() then
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigUp() -- This function digs up one block
while turtle.detectUp() do
if turtle.digUp() then
sleep(0.5)
else
return false
end
end
return true
end
local function tryDigDown() -- This function digs down one block
while turtle.detectDown() do
if turtle.digDown() then
sleep(0.5)
else
return false
end
end
return true
end
function tLeft() -- This function turns the turtle left and updates orientation
orientation = orientation - 1
orientation = (orientation - 1) % 4
orientation = orientation + 1
turtle.turnLeft()
end
function tRight() -- This function turns the turtle right and updates orientation
orientation = orientation - 1
orientation = (orientation + 1) % 4
orientation = orientation + 1
turtle.turnRight()
end
function mForward() -- This function moves the turtle forward and updates coordinates
local moved = false
while not(moved) do
moved = turtle.forward()
end
xCoord = xCoord + xDiff[orientation]
zCoord = zCoord + zDiff[orientation]
end
function mBack() -- This function moves the turtle backward and updates coordinates
local moved = false
while not(moved) do
moved = turtle.back()
end
xCoord = xCoord - xDiff[orientation]
zCoord = zCoord - zDiff[orientation]
end
function mUp() -- This function moves the turtle upward and updates coordinates
local moved = false
while not(moved) do
moved = turtle.up()
end
yCoord = yCoord + 1
end
function mDown() -- This function moves the turtle downward and updates coordinates
local moved = false
while not(moved) do
moved = turtle.down()
end
yCoord = yCoord - 1
end
function look(direction) -- This function turns the turtle to the desired direction
while direction ~= directions[orientation] do
tRight()
end
end
function moveTo(xTarget, zTarget, yTarget)
while yTarget < yCoord do
mDown()
end
while yTarget > yCoord do
mUp()
end
if xTarget < xCoord then
look("west")
while xTarget < xCoord do
mForward()
end
end
if xTarget > xCoord then
look("east")
while xTarget > xCoord do
mForward()
end
end
if zTarget < zCoord then
look("north")
while zTarget < zCoord do
mForward()
end
end
if zTarget > zCoord then
look("south")
while zTarget > zCoord do
mForward()
end
end
end
function dumpBlocks(continue)
progressX =xCoord progressZ = zCoord progressY = yCoord progressOrientation = orientation
moveTo(chestX, chestZ, chestY) look(directions[chestOrientation])
for i = 1, 16 do
turtle.select( i )
turtle.drop(64)
end
turtle.select( 1 )
if continue == "y" then moveTo(progressX, progressZ, (progressY + 1)) look(directions[progressOrientation])
mDown()
else return "true" end
end
function cutSquare(size, depth)
for a = 1, depth do -- Cut the number of squares specified by the depth variable
for b = 1, size do -- Cut the number of rows specified by the size variable
for c = 1, size do -- Cut a column of the square
-- Check if this is the first block of a new square else cut column
if (b == 1 and c == 1) then tryDigDown() mDown() elseif c > 1 then tryDig() mForward() end
-- Check if slot #16 has items put into it then dump blocks in chest
if (c == 5 and turtle.getItemCount(16) > 0) then dumpBlocks("y") end
end
if (b < size) then --Position to cut the next column of the square
if (b % 2 == 1) then --Position to cut the next column of the square
tRight()
tryDig()
mForward()
tRight()
else
tLeft()
tryDig()
mForward()
tLeft()
end
end
end
yStart = yStart - 1
moveTo(xStart, zStart, yStart) look(directions[orientationStart])
-- if (a < depth) then
-- tryDigDown()
-- mDown()
-- end
end
end
-- This is the main loop section of the program
moveTo(xStart, zStart, yStart) look(directions[orientationStart])
cutSquare(quarryLength, quarryDepth)
dumpBlocks("n")
moveTo(chestX, chestZ, chestY) look(directions[chestOrientation])
yStart = yStart - quarryDepth
print("Fuel level is "..turtle.getFuelLevel())
Comments