Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --TODO continue after chunk reload
- function printUsage()
- print( "Usage:" )
- print( "Mine <forward> <right> <down>" )
- end
- tArgs = { ... }
- if #tArgs ~= 3 then
- printUsage()
- return
- elseif tonumber(tArgs[1]) == nil or tonumber(tArgs[2]) == nil or tonumber(tArgs[3]) == nil then
- printUsage()
- return
- end
- dropped = 0
- attacked = 0
- turn = 0
- mined = 0
- deep = 3
- compared = 0 --added
- slot = 5 -- was 1
- turtle.select(slot)
- A = tonumber(tArgs[1])
- B = tonumber(tArgs[2])
- C = tonumber(tArgs[3])
- if A < 1 or A > 256 then
- print("forward must be between 1 and 256")
- error()
- elseif B < 1 or B > 256 then
- print("right must be between 1 and 256")
- error()
- elseif C < 1 or C > 256 then
- print("down must be between 1 and 256")
- error()
- end
- forward = A - 1
- right = B - 1
- down = math.floor(C / 3) - 1
- downRemaining = math.fmod(C,3)
- if down < 0 then
- down = 0
- downRemaining = 0
- end
- if C < 3 then
- oneLayer = 0
- else
- oneLayer = C - 3
- end
- function fuel()
- fuelNeeded = (A * B - 1) * math.ceil(C / 3) + oneLayer
- fuelLevel = turtle.getFuelLevel()
- fuelDifference = fuelNeeded - fuelLevel
- fuelCoal = math.ceil(fuelDifference / 80)
- if fuelLevel >= fuelNeeded then
- print("*Fuel usage: ".. fuelNeeded .." out of ".. fuelLevel .."")
- print("*Enough fuel to proceed")
- else
- print("*Need ".. fuelDifference .." more fuel (".. fuelCoal .." Coal)")
- while fuelNeeded > fuelLevel do
- C = C - 1
- if C < 3 then
- oneLayer = 0
- else
- oneLayer = C - 3
- end
- fuelNeeded = (A * B - 1) * math.ceil(C / 3) + oneLayer
- end
- print("*Max area with current fuel: ".. A .." ".. B .." ".. C .."")
- print("*Shutting Down...")
- error()
- end
- end
- fuel()
- print("'Put an enderchest in slot 1'")
- print("'put compare blocks in slot 2/3/4") --added
- print("'Turtle will mine forward, right, down'")
- print("'Type in anything to start'")
- io.read()
- function compareUp() --added
- for ore=2, 4 do
- turtle.select(ore)
- if turtle.compareUp() then
- compared = compared + 1
- return true
- end
- end
- return false
- end
- function compareDown() --added
- for ore=2, 4 do
- turtle.select(ore)
- if turtle.compareDown() then
- compared = compared + 1
- return true
- end
- end
- return false
- end
- function full()
- if turtle.getItemCount(16) > 0 then
- dropOff()
- end
- end
- function dropOff()
- turtle.select(1)
- while turtle.placeUp() == false do
- if turtle.digUp() == false then
- turtle.attackUp()
- end
- end
- slot = 5
- for e=1, 12 do
- turtle.select(slot)
- turtle.dropUp()
- slot = slot + 1
- end
- turtle.select(1)
- turtle.digUp()
- dropped = dropped + 1
- end
- function mine()
- full()
- while turtle.forward() == false do
- if turtle.dig() == false then
- turtle.attack()
- mined = mined - 1
- attacked = attacked + 1
- end
- mined = mined + 1
- end
- full()
- if not compareDown() then --added
- if turtle.digDown() then
- mined = mined + 1
- end
- end
- full()
- if not compareUp() then --added
- if turtle.digUp() then
- mined = mined + 1
- end
- end
- end
- function line()
- for x=1, forward do
- mine()
- end
- end
- function square()
- for y=1, right do
- line()
- if turn == 0 then
- turtle.turnRight()
- mine()
- turtle.turnRight()
- turn = turn + 1
- else
- turtle.turnLeft()
- mine()
- turtle.turnLeft()
- turn = turn - 1
- end
- end
- line()
- end
- function cube()
- full()
- if not compareDown() then --added
- if turtle.digDown() then
- mined = mined + 1
- end
- end
- full()
- if not compareUp() then --added
- if turtle.digUp() then
- mined = mined + 1
- end
- end
- square()
- for z=1, down do
- digCube()
- end
- if downRemaining ~= 0 then
- deep = downRemaining
- digCube()
- end
- end
- function digCube()
- for d=1, deep do
- while turtle.down() == false do
- if turtle.digDown() == false then
- turtle.attackDown()
- mined = mined - 1
- attacked = attacked + 1
- end
- mined = mined + 1
- end
- end
- full()
- if not compareDown() then --added
- if turtle.digDown() then
- mined = mined + 1
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- square()
- end
- cube()
- dropOff()
- print ("Mined ".. mined .." blocks")
- print ("Attacked ".. attacked .." times")
- print ("Dropped off ".. dropped .." times")
- print ("Found ".. compared .." special ores")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement