Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- The next 8 variables are user controlled.
- The current coordinates of the turtle are used in the
- variables, xCoord, zCoord, yCoord. Pretty sure you
- are able to figure out which are which. The looking
- variable is simply which way the turtle is looking.
- 1 is north, 2 is east, 3 is south, and 4 is west.
- The manager variable is simply the id of your
- manager computer. If you don't want to have multiple
- turtles going then simply comment out the getJob()
- function and call the digQuarry() function with the
- coordinates of the quarry. yTravel is at what height
- the turtle will travel at that height to get to and
- from. lineLength is the size of the quarry. qDirection
- is the direction the quarry is dug in. The turtle will
- go to the starting point of the quarry and then look
- in the direction specified. The quarry is dug forward
- and to the left of the turtle. qBottom specifies the
- bottom layer of the quarry.
- ]]--
- local xCoord = 1754
- local zCoord = 1754
- local yCoord = 64
- local looking = 2
- local manager = 349
- local yTravel = 75
- local lineLength = 10
- local qDirection = 3
- local qBottom = 7
- -- Variables
- local orientation = looking
- local orientations = {"north", "east", "south", "west"}
- local xQuarry = 999
- local zQuarry = 999
- local yQuarry = 150
- local xProgress = xCoord
- local zProgress = zCoord
- local yProgress = yCoord
- local oProgress = orientation
- local xFProgress = xCoord
- local zFProgress = zCoord
- local yFProgress = yCoord
- local oFProgress = orientation
- local xHome = xCoord
- local zHome = zCoord
- local yHome = yCoord
- local oHome = orientations[orientation]
- local zDiff = {-1, 0, 1, 0}
- local xDiff = {0, 1, 0, -1}
- local jobAvailable = true
- -- Program
- -- Checks if the inventory is full.
- function inventoryFull()
- turtle.select(16)
- full = turtle.getItemCount(16) > 0
- turtle.select(1)
- return full
- end
- -- Custom turn left.
- function left()
- orientation = orientation - 1
- orientation = (orientation - 1) % 4
- orientation = orientation + 1
- turtle.turnLeft()
- end
- -- Custom turn right.
- function right()
- orientation = orientation - 1
- orientation = (orientation + 1) % 4
- orientation = orientation + 1
- turtle.turnRight()
- end
- -- Custom forward.
- function forward()
- xCoord = xCoord + xDiff[orientation]
- zCoord = zCoord + zDiff[orientation]
- while turtle.detect() do
- turtle.dig()
- end
- moved = false
- while not moved do
- moved = turtle.forward()
- end
- end
- -- Custom up.
- function up()
- yCoord = yCoord + 1
- turtle.digUp()
- moved = false
- while not moved do
- moved = turtle.up()
- end
- end
- -- Custom down.
- function down()
- yCoord = yCoord - 1
- turtle.digDown()
- moved = false
- while not moved do
- moved = turtle.down()
- end
- end
- -- Look in a certain direction.
- function look(direction)
- while direction ~= orientations[orientation] do
- right()
- end
- end
- -- Goto.
- function goto(xTarget, zTarget, yTarget)
- while yTarget < yCoord do
- down()
- end
- while yTarget > yCoord do
- up()
- end
- if xTarget < xCoord then
- look("west")
- while xTarget < xCoord do
- forward()
- end
- end
- if xTarget > xCoord then
- look("east")
- while xTarget > xCoord do
- forward()
- end
- end
- if zTarget < zCoord then
- look("north")
- while zTarget < zCoord do
- forward()
- end
- end
- if zTarget > zCoord then
- look("south")
- while zTarget > zCoord do
- forward()
- end
- end
- end
- -- Drops off all items.
- function returnItems()
- xProgress = xCoord
- zProgress = zCoord
- yProgress = yCoord
- oProgress = orientation
- goto(xHome, zHome, yTravel)
- goto(xHome, zHome, yHome)
- look(oHome)
- for i = 1, 16 do
- details = turtle.getItemDetail(i)
- turtle.select(i)
- if details.name == "minecraft:coal" then
- left()
- turtle.drop()
- right()
- else
- turtle.drop()
- end
- end
- turtle.select(1)
- goto(xProgress, zProgress, yTravel)
- goto(xProgress, zProgress, yProgress)
- look(orientations[oProgress])
- end
- -- Gets fuel from chest.
- function getFuel()
- xFProgress = xCoord
- zFProgress = zCoord
- yFProgress = yCoord
- oFProgress = orientation
- goto(xHome, zHome, yTravel)
- goto(xHome, zHome, yHome)
- look(oHome)
- left()
- turtle.select(16)
- turtle.suck(64)
- turtle.refuel(64)
- turtle.select(1)
- goto(xFProgress, zFProgress, yTravel)
- goto(xFProgress, zFProgress, yFProgress)
- look(orientations[oFProgress])
- end
- -- Digs a line of the quarry.
- function digLine()
- for i = 1, (lineLength - 1) do
- if inventoryFull() then
- returnItems()
- end
- forward()
- end
- if turtle.getFuelLevel() < 300 then
- getFuel()
- end
- end
- -- Digs a layer of the quarry.
- function digLayer()
- for i = 1, lineLength do
- digLine()
- if (i%2) == 1 and i < lineLength then
- left()
- forward()
- left()
- elseif i < lineLength then
- right()
- forward()
- right()
- end
- end
- goto(xQuarry, zQuarry, yCoord)
- look(orientations[qDirection])
- down()
- end
- -- Digs the whole quarry.
- function digQuarry(xTarget, zTarget, yTarget)
- xQuarry = xTarget
- zQuarry = zTarget
- yQuarry = yTarget
- goto(xQuarry, zQuarry, yTravel)
- goto(xQuarry, zQuarry, yQuarry)
- look("south")
- while yCoord > qBottom do
- digLayer()
- end
- goto(xQuarry, zQuarry, yQuarry)
- goto(xHome, zHome, yTravel)
- goto(xHome, zHome, yHome)
- yMin = 999
- end
- -- Gets a job from the manager.
- function getJob()
- while jobAvailable do
- rednet.send(manager, "getJob")
- id, message, dist = rednet.receive()
- if message == "yes" then
- id, xRec, dist = rednet.receive()
- id, zRec, dist = rednet.receive()
- id, yRec, dist = rednet.receive()
- xQuarry = tonumber(xRec)
- zQuarry = tonumber(zRec)
- yQuarry = tonumber(yRec)
- digQuarry(xQuarry, zQuarry, yQuarry)
- elseif message == "no" then
- jobAvailable = false
- end
- end
- end
- -- Checks all sides for modems and opens them.
- local function openRednet()
- for _,side in ipairs(rs.getSides()) do
- if peripheral.isPresent(side) and peripheral.getType(side) == "modem" then
- rednet.open(side)
- return side
- end
- end
- end
- -- Open rednet.
- openRednet()
- -- Starts the program.
- getJob()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement