Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- digger v1.1 by bigougit
- youtube.com/user/bigougit
- This program is for turtles only,
- ideally mining turtles.
- To install in-game, make sure
- that http = true in your
- computercraft config.
- To install, open your turtle
- and type:
- pastebin get fxZCZprs digger
- usage: digger x y z [d]
- x = how far forward the turtle will dig
- y = how far up or down the turtle will dig
- z = how far to the right the turtle will dig
- [d] = optional, will make the turtle dig
- down instead of up.
- The turtle will not start if it doesn't have
- enough fuel.
- to calculate fuel needed:
- x*y*z*1.5
- not the best calculation, but
- it works and the turtle usually
- doesn't need more fuel while working.
- report any errors to me on youtube or
- twitter.
- http://youtube.com/user/bigougit
- http://twitter.com/bigougit
- --]]
- --return how many items in [slot]
- local function sCount(slot)
- return turtle.getItemCount(slot)
- end
- --move similar items to [slot]
- function stack(slot)
- local room = turtle.getItemSpace(slot)
- local s = 0
- while room > 0 do
- s = s + 1
- if s >= 16 then
- room = 0
- end
- if s ~= slot then
- turtle.select(s)
- if turtle.compareTo(slot) then
- if sCount(s) >= room then
- turtle.transferTo(slot, room)
- room = 0
- else
- local temp = sCount(s)
- turtle.transferTo(slot,temp)
- room = room - temp
- end
- end
- end
- end
- end
- function fuel(slot, need)
- local iCount = sCount(slot)
- --stack(slot)
- local cont = true
- while cont do
- if turtle.getFuelLevel() < need then
- if iCount > 1 then
- turtle.select(slot)
- turtle.refuel(1)
- if iCount == sCount(slot) then
- cont = false
- else
- iCount = sCount(slot)
- end
- else
- cont = false
- end
- else
- return true
- end
- end
- if turtle.getFuelLevel() < need then
- return false
- else
- return true
- end
- end
- function tryForward(n)
- n = n or 1
- for i=1,n do
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- end
- end
- end
- function tryUp(n)
- n = n or 1
- for i=1,n do
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- end
- end
- end
- function tryDown(n)
- n = n or 1
- for i=1,n do
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- end
- end
- end
- function left(n)
- n = n or 1
- for i=1,n do
- turtle.turnLeft()
- end
- end
- function right(n)
- n = n or 1
- for i=1,n do
- turtle.turnRight()
- end
- end
- function haveRoom()
- local hasRoom = false
- for i=1,16 do
- if sCount(i) == 0 then
- hasRoom = true
- end
- end
- return hasRoom
- end
- function turnTo(curF,toF)
- while curF ~= toF do
- if curF > 3 then
- turtle.turnRight()
- curF = 0
- elseif curF == 3 then
- turtle.turnRight()
- curF = 0
- elseif curF > -1 then
- turtle.turnRight()
- curF = curF + 1
- end
- end
- return curF
- end
- function calcF(dir,curF)
- if dir:lower() == "right" then
- if curF >= 3 then
- curF = 0
- else
- curF = curF + 1
- end
- else
- if curF <= 0 then
- curF = 3
- else
- curF = curF-1
- end
- end
- return curF
- end
- function goTo(x,y,z,f,toX,toY,toZ,toF)
- local xDir = 1
- local yDir = 1
- local zDir = 1
- if x > toX then
- xDir = -1
- end
- if y > toY then
- yDir = -1
- end
- if z > toZ then
- zDir = -1
- end
- if y ~= toY then
- for curY=(y+yDir),toY,yDir do
- if yDir > 0 then
- tryUp()
- else
- tryDown()
- end
- end
- end
- if x ~= toX then
- if xDir > 0 then
- f = turnTo(f,0)
- else
- f = turnTo(f,2)
- end
- for curX=(x+xDir),toX,xDir do
- tryForward()
- end
- end
- if z ~= toZ then
- if zDir > 0 then
- f = turnTo(f,1)
- else
- f = turnTo(f,3)
- end
- for curZ=(z+zDir),toZ,zDir do
- tryForward()
- end
- end
- f = turnTo(f,toF)
- end
- local tArgs = { ... }
- local x,y,z
- local error = false
- if tArgs[1] then
- x = tonumber(tArgs[1])
- if tArgs[2] then
- y = tonumber(tArgs[2])
- if tArgs[3] then
- z = tonumber(tArgs[3])
- else
- error = true
- end
- else error = true
- end
- else error = true
- end
- if error then
- print(" Incorrect usage")
- print("-----------------------------------")
- print(" usage: digger x y z [d]")
- print(" ")
- print("x,y,x are the dimmensions to dig")
- print("If d, I will dig down,up is default")
- print(" ")
- print("Put fuel in the first slot and a")
- print("chest behind me, for proper use.")
- print("-----------------------------------")
- return true
- end
- local yDir = 1
- local dDown = false
- if tArgs[4] == "d" or tArgs[4] == 'd' then
- yDir = -1
- dDown = true
- end
- x = math.abs(x)
- y = math.abs(y)
- z = math.abs(z)
- local f = 0
- local curX = 0
- local curY = 0
- local curZ = 0
- local function inv()
- if not haveRoom() then
- goTo(curX,curY,curZ,f,0,0,0,2)
- for slot = 2 , 16 do
- turtle.select(slot)
- turtle.drop()
- end
- turtle.select(1)
- goTo(0,0,0,2,curX,curY,curZ,f)
- end
- end
- local function move()
- --if turtle.getItemSpace(1) > 0 then
- -- bMan.stack(1)
- --end
- if f == 0 then
- curX = curX + 1
- elseif f == 1 then
- curZ = curZ + 1
- elseif f == 2 then
- curX = curX - 1
- elseif f == 3 then
- curZ = curZ - 1
- else
- print("error!")
- end
- inv()
- end
- local dir = 0
- local fNeeded = x*y*z
- if not fuel(1,fNeeded*1.5) then
- print("not enough fuel! try again...")
- else
- for cY=1,y do
- for cZ=1,z do
- for cX=2,x do
- tryForward()
- move()
- end
- if cZ < z then
- if dir == 0 then
- right()
- f = calcF("right",f)
- tryForward()
- move()
- right()
- f = calcF("right",f)
- dir = 1
- elseif dir == 1 then
- left()
- f = calcF("left",f)
- tryForward()
- move()
- left()
- f = calcF("left",f)
- dir = 0
- end
- end
- end
- if cY < y then
- if dDown then
- inv()
- tryDown()
- curY = curY -1
- else
- inv()
- tryUp()
- curY = curY + 1
- end
- left(2)
- f = calcF("left",f)
- f = calcF("left",f)
- end
- end
- end
- print("going home")
- goTo(curX,curY,curZ,f,0,0,0,0)
Advertisement
Add Comment
Please, Sign In to add comment