Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Last pos: -7944
- SAFE_SLOTS = 3
- LAST_FILLER_SLOT = 8
- SLOT_COUNT = 16
- CHUNK_LOADER_PERIOD=16
- function selectFiller()
- for slot = SAFE_SLOTS + 1, SLOT_COUNT do
- turtle.select(slot)
- if turtle.compareTo(2) and turtle.getItemCount() > 1 then
- return
- end
- end
- end
- function selectFillerDestination()
- turtle.select(SAFE_SLOTS + 1)
- end
- function placeFiller(direction)
- if direction == nil then
- direction = ''
- end
- while turtle['detect' .. direction]() do
- selectFillerDestination()
- turtle['dig' .. direction]()
- end
- selectFiller()
- turtle['place' .. direction]()
- end
- function clear(direction)
- if direction == nil then
- direction = ''
- end
- while turtle['detect' .. direction]() do
- selectFiller()
- turtle['place' .. direction]()
- selectFillerDestination()
- turtle['dig' .. direction]()
- end
- end
- function move(direction)
- clear(direction)
- if direction == nil or direction == '' then
- turtle.forward()
- elseif direction == 'Up' then
- turtle.up()
- else
- turtle.down()
- end
- end
- function dropNonFuel()
- for slot = LAST_FILLER_SLOT + 1, SLOT_COUNT do
- turtle.select(slot)
- if not turtle.refuel() then
- turtle.drop()
- end
- end
- end
- function buildLayer(width, height)
- local startFuel = turtle.getFuelLevel()
- local left = math.floor(width / 2)
- local right = left
- move()
- turtle.turnLeft()
- for i = 1, left + 1 do
- placeFiller('Down')
- clear('')
- move()
- end
- placeFiller('Down')
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, height - 1 do
- move('Up')
- clear()
- placeFiller('Down')
- end
- placeFiller('Up')
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- placeFiller()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, width do
- placeFiller('Up')
- move()
- end
- placeFiller('Up')
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, height - 1 do
- move('Down')
- clear()
- placeFiller('Up')
- end
- placeFiller('Down')
- turtle.forward()
- turtle.turnLeft()
- turtle.turnLeft()
- placeFiller()
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, right - 1 do
- placeFiller('Down')
- move()
- end
- placeFiller('Down')
- local currentDirection = 'Up'
- move('Up')
- for x = 1, width - 2 do
- for y = 1, height - 3 do
- move(currentDirection)
- end
- move()
- if currentDirection == 'Up' then
- currentDirection = 'Down'
- else
- currentDirection = 'Up'
- end
- end
- if currentDirection == 'Down' then
- for y = 1, height - 2 do
- move('Down')
- end
- else
- move('Down')
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, left do
- move()
- end
- turtle.turnLeft()
- local consumedFuel = startFuel - turtle.getFuelLevel()
- dropNonFuel()
- return consumedFuel
- end
- function moveChunkLoader()
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(3)
- turtle.place()
- turtle.up()
- for i = 1, CHUNK_LOADER_PERIOD do
- move()
- end
- turtle.down()
- turtle.dig()
- turtle.up()
- for i = 1, CHUNK_LOADER_PERIOD do
- turtle.back()
- end
- turtle.down()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- args = {...}
- tunnelWidth = tonumber(args[1])
- tunnelHeight = tonumber(args[2])
- if turtle.getFuelLevel() < tunnelWidth * tunnelHeight then
- error('Need some fuel to get started!')
- end
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.select(3)
- turtle.place()
- turtle.turnLeft()
- turtle.turnLeft()
- fuelUsage = buildLayer(tunnelWidth, tunnelHeight)
- averageFuelUsage = fuelUsage
- layers = 1
- while turtle.getFuelLevel() > 2 * fuelUsage and (#args < 3 or layers < tonumber(args[3])) do
- fuelUsage = buildLayer(tunnelWidth, tunnelHeight)
- layers = layers + 1
- averageFuelUsage = averageFuelUsage + (fuelUsage - averageFuelUsage) / layers
- if layers % CHUNK_LOADER_PERIOD == 0 then
- moveChunkLoader()
- end
- if turtle.getFuelLevel() <= 2 * fuelUsage then
- turtle.select(1)
- turtle.refuel(1)
- end
- end
- print('Ran out of fuel or terminated after ' .. tostring(layers) .. ' layers!')
- print('Average fuel usage was: ' .. tostring(averageFuelUsage))
Add Comment
Please, Sign In to add comment