Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --define--
- x = 0
- y = 0
- z = 0
- tx = 0
- ty = 0
- tz = 0
- mx = 0
- my = 0--mvariables are used for orientation during mining--
- mz = 0
- rx = 0
- ry = 0 --rvariables is where the turtle goes after its done working--
- rz = 0
- height = 0
- rotation = 1 --North = 1 (default), East = 2, South = 3, West = 4--
- depositChest = 2
- refuelChest = 4
- usingEnderchest = false -- set to true if you are using an enderchest for depositing--
- refuelTimes = 0
- fuelMultiplier = 15 --default value for wooden planks--
- jobs = 0
- Mr = rotation
- ----------
- --functions--
- function rotate(w)
- if (rotation == 1 and w == 4) or (rotation == w + 1) then
- turtle.turnLeft()
- rotation = rotation - 1
- if rotation == 0 then
- rotation = 4
- end
- end
- while rotation ~= w do
- rotation = rotation + 1
- turtle.turnRight()
- if rotation == 5 then
- rotation = 1
- end
- end
- end
- function LoadCoords()
- file = fs.open("/disk/info.lua","r")
- x = tonumber(file.readLine())
- y = tonumber(file.readLine())
- z = tonumber(file.readLine())
- tx = tonumber(file.readLine())
- ty = tonumber(file.readLine())
- tz = tonumber(file.readLine())
- area = tonumber(file.readLine())
- height = tonumber(file.readLine())
- file.close()
- end
- function SaveCoords() --takes a job and changes it so other turtles doesn't mine the same stuff--
- file = fs.open("/disk/info.lua","w")
- file.writeLine(x)
- file.writeLine(y)
- file.writeLine(z)
- file.writeLine(tx+area)
- file.writeLine(ty)
- file.writeLine(tz)
- file.writeLine(area)
- file.writeLine(height)
- file.close()
- end
- function Refuel()
- for i = 1, 2 do
- if x > tx then
- fuelx = (x - tx) + mx
- else
- fuelx = (tx - x) + mx
- end
- if y > ty then
- fuely = (y - ty) + my
- else
- fuely = (ty - y) + my
- end
- if z > tz then
- fuelz = (z - tz) + mz
- else
- fuelz = (tx - x) + mz
- end
- if (refuelTimes == 0)then
- refuelAmount = fuelx+fuely+fuelz+(area*area*ty) - turtle.getFuelLevel()
- else
- refuelAmount = fuelx+fuely+fuelz - turtle.getFuelLevel()
- end
- refuelTimes = refuelTimes + 1
- rotate(4)
- turtle.select(2)
- while (math.ceil((refuelAmount/fuelMultiplier)) > 64) do
- turtle.suck(64)
- turtle.refuel(64)
- refuelAmount = fuelx+fuely+fuelz - turtle.getFuelLevel()
- end
- if (math.ceil((refuelAmount/fuelMultiplier)) < 64) and math.ceil((refuelAmount/fuelMultiplier)) > 0 then
- turtle.suck(math.ceil((refuelAmount/fuelMultiplier)))
- turtle.refuel(math.ceil((refuelAmount/fuelMultiplier)))
- refuelAmount = fuelx+fuely+fuelz - turtle.getFuelLevel()
- end
- end
- rotate(1)
- end
- -- proper use of these are Go(from, to)--
- function GoX(cx,gx)
- if cx > gx then
- rotate(4)
- for i = cx, gx + 1, -1 do
- turtle.dig()
- turtle.forward()
- end
- elseif cx < gx then
- rotate(2)
- for i = cx, gx - 1 do
- turtle.dig()
- turtle.forward()
- end
- end
- end
- function GoY(cy,gy)
- if cy > gy then
- for i = cy, gy + 1, -1 do
- turtle.digDown()
- turtle.down()
- end
- elseif cy < gy then
- for i = cy, gy - 1 do
- turtle.digUp()
- turtle.up()
- end
- end
- end
- function GoZ(cz,gz)
- if cz > gz then
- rotate(1)
- for i = cz, gz+1, -1 do
- turtle.dig()
- turtle.forward()
- end
- elseif cz < gz then
- rotate(3)
- for i = cz, gz - 1 do
- turtle.dig()
- turtle.forward()
- end
- end
- end
- function fromM()
- Mr = rotation
- rotate(1)
- GoY(ty-my,height)
- GoX(tx+mx,x)
- GoZ(tz+mz,z)
- GoY(height,y)
- end
- function toM()
- rotate(1)
- GoY(y,height)
- GoX(x,tx+mx)
- GoZ(z,tz+mz)
- GoY(height,ty-my)
- rotate(Mr)
- end
- function Drop()
- rotate(depositChest)
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop(64)
- end
- end
- function inventoryCheck()
- if turtle.getItemCount(16) > 0 then
- if usingEnderchest == true then
- turtle.select(1)
- turtle.placeUp()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop(64)
- end
- turtle.select(1)
- turtle.digUp()
- else
- fromM()
- Drop()
- Refuel()
- toM()
- end
- end
- end
- function MineFloor()
- for i = 0, ty-1 do
- GoX(tx+mx,tx)
- GoZ(tz+mz,tz)
- inventoryCheck()
- turtle.digDown()
- turtle.down()
- for x = 0, area do
- while turtle.detect() == true do
- inventoryCheck()
- if turtle.dig() == false then
- fromM()
- newJob()
- end
- end
- turtle.forward()
- end
- for b = 0, area-1 do
- if rotation == 1 then
- rotate(2)
- inventoryCheck()
- turtle.dig()
- turtle.forward()
- rotate(3)
- elseif rotation == 3 then
- rotate(2)
- inventoryCheck()
- turtle.dig()
- turtle.forward()
- rotate(1)
- end
- end
- end
- end
- function newJob()
- LoadCoords()
- SaveCoords()
- Drop()
- Refuel()
- Mr = 1
- mx = 0
- mz = 0
- my = 0
- toM()
- for u = 1, ty-1 do
- MineFloor()
- end
- fromM()
- Drop()
- jobs = jobs + 1
- end
- -------------
- --main--
- while jobs < 3 do
- newJob()
- end
- tx = rx
- tz = rz
- ty = ry
- Refuel()
- toM()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement