Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- xCoord = 207
- zCoord = 323
- yCoord = 65
- mineStop = 5
- xHome = xCoord
- zHome = zCoord
- yHome = yCoord
- yTunnelTravel = 20
- yQuarryTravel = 80
- woodAmount = 10
- coalAmount = 0
- MinFuel = 5
- oreslots = {}
- curOreslot = 0
- orientation = 1
- orientations = {"north", "east", "south", "west"}
- xCont = {}
- zCont = {}
- yCont = {}
- xChange = {0,1,0,-1}
- zChange = {-1,0,1,0}
- direction = orientations[orientation]
- lines = 10
- lineLength = 10
- lineLength = lineLength - 1
- xQuarry = 999
- zQuarry = 999
- yQuarry = 999
- xTunnel = 999
- zTunnel = 999
- yTunnel = 20
- xTarget = 999
- zTarget = 999
- yTarget = 20
- tunnelFinish = 50
- yMin = yCoord
- function face(direction)
- while direction ~= orientations[orientation] do
- right()
- end
- end
- function left()
- orientation = orientation - 1
- orientation = (orientation - 1) % 4
- orientation = orientation + 1
- turtle.turnLeft()
- end
- function right()
- orientation = orientation - 1
- orientation = (orientation + 1) % 4
- orientation = orientation + 1
- turtle.turnRight()
- end
- function moveForward()
- addCoal = turtle.compare()
- if addCoal then coalAmount = coalAmount + 1
- end
- xCoord = xCoord + xChange[orientation]
- zCoord = zCoord + zChange[orientation]
- moved = false
- while not(moved) do
- turtle.dig()
- moved = turtle.forward()
- end
- end
- function moveUp()
- yCoord = yCoord + 1
- moved = false
- while not(moved) do
- turtle.digUp()
- moved = turtle.up()
- end
- end
- function moveDown()
- yCoord = yCoord - 1
- moved = false
- while not(moved) do
- turtle.digDown()
- moved = turtle.down()
- if yMin > yCoord then
- yMin = yCoord
- end
- end
- end
- function goto(xTarget, zTarget, yTarget)
- while yTarget < yCoord do
- moveDown()
- end
- while yTarget > yCoord do
- moveUp()
- end
- while xTarget < xCoord do
- face("west")
- moveForward()
- end
- while xTarget > xCoord do
- face("east")
- moveForward()
- end
- while zTarget < zCoord do
- face("north")
- moveForward()
- end
- while zTarget > zCoord do
- face("south")
- moveForward()
- end
- end
- function digline()
- for i = 1,lineLength do
- moveForward()
- end
- inventoryFull()
- checkFuel()
- if full then
- returnItems()
- end
- end
- function digLayer()
- for i = 1,lines do
- digline()
- if (i%2) == 1 and i < lines then
- left()
- moveForward()
- left()
- elseif i < lines then
- right()
- moveForward()
- right()
- end
- end
- goto(xQuarry,zQuarry,yCoord)
- face("north")
- moveDown()
- end
- function checkFuel()
- print("Checking Fuel")
- needFuel = turtle.getFuelLevel() < MinFuel
- if needFuel then
- turtle.select(16)
- turtle.refuel(woodAmount - 10)
- woodAmount = woodAmount - woodAmount + 10
- end
- end
- function goHome()
- print("returning home")
- goto(xHome,zHome,yQuarryTravel)
- goto(xHome,zHome,yHome)
- face("west")
- end
- function returnItems()
- goHome()
- face("north")
- for i = 2,16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- end
- function digQuarry(xTarget,zTarget,yTarget)
- checkFuel()
- xQuarry = xTarget
- zQuarry = zTarget
- yQuarry = yTarget
- goto(xQuarry,zQuarry,yQuarryTravel)
- goto(xQuarry,zQuarry,yQuarry)
- face("north")
- while yMin > 7 do
- digLayer()
- end
- goto(xHome,zHome,yTravel)
- goto(xHome,zHome,yHome)
- end
- function digLayerT()
- moveForward()
- left()
- turtle.dig()
- moveUp()
- turtle.dig()
- right()
- right()
- turtle.dig()
- moveDown()
- turtle.dig()
- left()
- end
- function digTunnel(xTarget,zTarget,yTarget)
- term.write("How Far:")
- tunnelFinish = read()
- print("Tunnelling")
- checkFuel()
- print("Fuel Check Done")
- xTunnel = xTarget
- zTunnel = zTarget
- yTunnel = yTarget
- goto(xTunnel,zTunnel,yTunnel)
- face("west")
- for i = 1,tunnelFinish do
- digLayerT()
- end
- end
- function checkAir()
- air= false
- moved = false
- moved = turtle.forward()
- if moved then
- turtle.back()
- air = true
- return
- end
- end
- function checkOre()
- trashSlots = 3
- for t = 1,4 do
- ore = true
- for i = 1,trashSlots do
- turtle.select(i)
- if turtle.compare() then
- ore = false
- end
- end
- if ore then
- checkAir()
- if air then
- ore = false
- end
- end
- if ore then
- return
- end
- right()
- end
- end
- function checkSameOre()
- same = false
- for t = 1,4 do
- turtle.select(oreslots[curOreslot])
- if turtle.compare() then
- same = true
- print("ore is same")
- return
- end
- right()
- end
- end
- function saveCoords()
- table.insert(xCont,xCoord)
- table.insert(zCont,zCoord)
- table.insert(yCont,yCoord)
- end
- function removeCoords()
- table.remove(xCont)
- table.remove(zCont)
- table.remove(yCont)
- end
- function checkUD()
- if turtle.compareDown() then same = true
- end
- if turtle.compareUp() then same = true
- end
- end
- first = true
- function gatherVein()
- same = false
- turtle.select(oreslots[curOreslot])
- if first then
- xStart = xCoord
- zStart = zCoord
- yStart = yCoord
- turtle.select(oreslots[curOreslot])
- turtle.dig()
- moveForward()
- saveCoords()
- end
- first = false
- while turtle.compareUp() do
- saveCoords()
- moveUp()
- if not(turtle.compareUp()) then
- checkSameOre()
- if same then
- return
- end
- end
- end
- while turtle.compareDown() do
- saveCoords()
- moveDown()
- if not(turtle.compareDown()) then
- checkSameOre()
- if same then
- return
- end
- end
- end
- if turtle.compare() then
- saveCoords()
- moveForward()
- checkSameOre()
- checkUD()
- if same then
- return
- end
- end
- C = #xCont
- if C > 0 then
- goto(xCont[C],zCont[C],yCoord)
- goto(xCont[C],zCont[C],yCont[C])
- removeCoords()
- checkSameOre()
- checkUD()
- if same then return
- end
- same = true
- return
- end
- goto(xStart,zStart,yStart)
- same = false
- first = true
- end
- function changeOreslot()
- print("changing ore slot")
- lowestSlot = #oreslots
- changeSlotStart = oreslots[lowestSlot]
- print("the lowest slot is:".. changeSlotStart)
- for i = changeSlotStart,4,-1 do
- if turtle.getItemCount(i) < 1 then
- table.insert(oreslots,i)
- curOreslot = #oreslots
- return
- end
- end
- end
- function checkSameOreSlot()
- sameSlot = false
- if curOreslot == 0 then
- print("first ore")
- table.insert(oreslots,14)
- curOreslot = 1
- sameSlot = true
- return
- end
- for i = 1,#oreslots do
- print("checking if same ore")
- turtle.select(oreslots[i])
- if turtle.compare() then
- print("this is the same")
- curOreslot = oreslots[i]
- sameSlot = true
- return
- end
- end
- print("this is not the same")
- sameSlot = false
- return
- end
- function digShaft()
- same = false
- ore = false
- sameSlot = false
- moveDown()
- while yCoord > mineStop do
- moveDown()
- checkOre()
- print("checked ore")
- while ore do
- print("1")
- checkSameOreSlot()
- if sameSlot == false then
- print("changing slot")
- changeOreslot()
- print("changed ore slot")
- end
- print("2")
- turtle.select(oreslots[curOreslot])
- print("3")
- gatherVein()
- while same do
- gatherVein()
- end
- checkOre()
- end
- end
- goto(xCoord,zCoord,65)
- print("finished")
- end
- function getTree()
- turtle.select(16)
- moveForward()
- woodAmount = woodAmount + 1
- while turtle.compareUp(16) do
- checkFuel()
- moveUp()
- woodAmount = woodAmount + 1
- end
- while not (turtle.detectDown()) do
- moveDown()
- end
- end
- function start()
- turtle.select(1)
- digShaft()
- face("north")
- end
- start()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement