Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs < 3 then
- print( "Usage: buildplane <n up> <n right> <n forward>" )
- return
- end
- -- Mine in a quarry pattern until we hit something we can't dig
- --local length = tonumber( tArgs[1] )
- local rDn = tonumber( tArgs[1] )
- local rRt = tonumber( tArgs[2] )
- local rFd = tonumber( tArgs[3] )
- -- if length < 1 then
- -- print( "Tunnel length must be positive" )
- -- return
- -- end
- local cDn = 0
- local cFd = 0
- local cRt = 0
- local hFd = 1
- local hRt = 0
- local collected = 0
- local slotsAvailable = {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true}
- local function collect()
- collected = collected + 1
- if math.fmod(collected, 25) == 0 then
- print( "Mined "..collected.." items." )
- end
- end
- local function selectLastAvailableSlot()
- local cSlot = 1
- slotsAvailable = {true, true, true, true, true, true, true, true, true, true, true, true, true, true, true, true}
- repeat
- if (turtle.getItemCount(1) < 2) then
- slotsAvailable[1] = false
- print("out of Blocks (1-12)")
- io.read()
- else
- slotsAvailable[1] = true
- for cSlot=12,2,-1 do
- if (turtle.getItemCount(cSlot)>0) then
- if (slotsAvailable[cSlot] == true) then
- turtle.select(cSlot)
- if (turtle.compareTo(1)) then
- turtle.select(cSlot)
- return
- else
- slotsAvailable[cSlot] = false
- end
- end
- else
- slotsAvailable[cSlot] = false
- end
- end
- turtle.select(1)
- return
- end
- until ( slotsAvailable[1] == true )
- end
- --placing block underneath
- local function placeBlockDown()
- if not (turtle.detectDown()) then
- selectLastAvailableSlot()
- turtle.placeDown()
- end
- end
- --placing block in front of
- local function placeBlock()
- selectLastAvailableSlot()
- turtle.place()
- end
- local function tryDig()
- while turtle.dig() do
- collect()
- end
- return true
- end
- local function tryDigUp()
- while turtle.digUp() do
- collect()
- --sleep(0.5)
- end
- return true
- end
- local function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- for n=1,16 do
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- sleep(1)
- end
- print( "Resuming Tunnel." )
- end
- end
- local function tryDown()
- refuel()
- while not turtle.down() do
- if turtle.detectDown() then
- if not turtle.digDown() then
- return false
- end
- elseif turtle.attackDown() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryForward()
- refuel()
- while not turtle.forward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryUp()
- refuel()
- while not turtle.up() do
- if turtle.detectUp() then
- if not tryDigUp() then
- return false
- end
- elseif turtle.attackUp() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local lastTurnR = 0
- print( "Building..." )
- if (rFd==0 and rRt == 0) then
- --up only
- for n=0,rDn do
- if tryUp() then
- --if (n % 2==0) then
- placeBlockDown()
- --end
- else
- print("cannot dig up")
- end
- end
- else
- for n=0,rDn do
- while cRt <= rRt do
- while cFd < rFd do
- if tryForward() then
- cFd = cFd + 1
- --put block
- placeBlockDown()
- else
- print("cannot dig fd")
- end
- end
- if cRt ~= rRt then
- if lastTurnR == 1 then
- turtle.turnLeft()
- tryForward()
- --put block
- placeBlockDown()
- turtle.turnLeft()
- lastTurnR = 0
- elseif lastTurnR == 0 then
- turtle.turnRight()
- tryForward()
- --put block
- placeBlockDown()
- turtle.turnRight()
- lastTurnR = 1
- end
- else
- turtle.turnRight()
- turtle.turnRight()
- end
- cFd=0
- cRt= cRt + 1
- end
- cRt=0
- if n~=rDn then
- if not tryUp() then
- print("cannot dig dn")
- else
- --put block
- placeBlockDown()
- end
- end
- end
- end
- print( "Construction complete." )
- print( "Mined "..collected.." items total." )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement