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
- area = 0
- height = 0 -- how far up it will go(to avoid going through your base)
- 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
- ----------
- --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 ChangeCoords() --takes a job and changes it so other turtles doesn't mine the same stuff--
- file = fs.open("/disk/info.lua","r") --reads from the disk drive under it--
- 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()
- sleep(0.5)
- 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()
- print("returning")
- 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)
- end
- function check()
- while turtle.detect() == true do
- if turtle.detect() == true and turtle.dig() == false then
- Return()
- else
- turtle.dig()
- turtle.forward()
- end
- end
- 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 MineDown()
- GoX(tx+mx,tx)
- GoZ(tz+mz,tz)
- mx = 0
- mz = 0
- rotate(1)
- inventoryCheck()
- turtle.digDown()
- turtle.down()
- my = my + 1
- print("Dig down")
- end
- function MineFloor()
- for i = 1, area do
- for f = 1, area-1 do
- inventoryCheck()
- if area > 1 then
- turtle.dig()
- turtle.forward()
- end
- if rotation == 1 then
- mz = mz - 1
- else
- mz = mz + 1
- end
- end
- if (area > 1) and (i < area) then
- if (rotation == 1 ) then
- rotate(2)
- inventoryCheck()
- turtle.dig()
- turtle.forward()
- mx = mx + 1
- rotate(3)
- elseif (rotation == 3 ) then
- rotate(2)
- inventoryCheck()
- turtle.dig()
- turtle.forward()
- mx = mx + 1
- rotate(1)
- end
- end
- end
- MineDown()
- end
- -------------
- --main--
- while jobs <3 do
- ChangeCoords()
- Refuel()
- toM()
- for u = 1, ty-1 do
- MineFloor()
- end
- fromM()
- Drop()
- mx = 0
- mz = 0
- my = 0
- jobs = jobs + 1
- end
- tx = rx
- tz = rz
- ty = ry
- Refuel()
- toM()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement