Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs ~= 3 then
- print("Usage: mining <main tunnel length> <side tunnel length> <side tunnel every [] blocks>")
- return
- end
- mTLength = tonumber(tArgs[1])
- sTLength = tonumber(tArgs[2])
- sTSpacing = tonumber(tArgs[3])
- x = 0
- z = 0
- dir = 0
- mined = 0
- function goto(tx, tz, tdir)
- dx = x - tx
- dz = z - tz
- if dz > 0 and dx > 0 then
- while dir ~= 1 do
- turnLeft()
- end
- while z > tz do
- forward()
- end
- while dir ~= 2 do
- turnLeft()
- end
- while x > tx do
- forward()
- end
- elseif dz < 0 and dx < 0 then
- while dir ~= 0 do
- turnLeft()
- end
- while x < tx do
- forward()
- end
- while dir ~= 3 do
- turnLeft()
- end
- while z < tz do
- forward()
- end
- end
- while dir ~= tdir do
- turnLeft()
- end
- end
- function returnHome()
- goto(0, 0, 2)
- end
- function isFull()
- return mined >= 16*64
- end
- function turnRight()
- turtle.turnRight()
- dir = (dir - 1) % 4
- end
- function turnLeft()
- turtle.turnLeft()
- dir = (dir + 1) % 4
- end
- function forward()
- if dir == 0 then x = x + 1
- elseif dir == 1 then z = z - 1
- elseif dir == 2 then x = x - 1
- elseif dir == 3 then z = z + 1
- end
- return turtle.forward()
- end
- function forceForward()
- if turtle.detect then
- turtle.dig()
- mined = mined + 1
- if isFull() then emptyInv() end
- end
- forward()
- turtle.digUp()
- mined = mined + 1
- if isFull() then emptyInv() end
- turtle.digDown()
- mined = mined + 1
- if isFull() then emptyInv() end
- end
- function emptyInv()
- memX = x
- memY = y
- memDir = dir
- returnHome()
- for i = 1,16 do
- if turtle.refuel(0) and turtle.getFuelLevel() < turtle.getFuelLimit()/10 then
- turtle.refuel()
- else
- turtle.drop()
- end
- end
- goto(memX, memY, memDir)
- end
- for i = 1,mTLength do
- forceForward()
- turnRight()
- forceForward()
- if i%sTSpacing == 0 then
- memZ = z
- for j = 1,sTLength do
- forceForward()
- end
- turnLeft()
- turnLeft()
- for j = 1,sTLength do
- forward()
- end
- else
- turnLeft()
- turnLeft()
- end
- forward()
- turnRight()
- end
- returnHome()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement