Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local width = tonumber(args[1])
- local height = tonumber(args[2])
- local depth = tonumber(args [3])
- if table.getn(args) < 3 then
- print('Usage: ' .. shell.getRunningProgram() .. ' <width> <length> <depth>')
- error()
- end
- if width == nil or height == nil or depth == nil then
- print('Dimensions must be numbers')
- error()
- end
- if width ~= math.floor(width) or height ~= math.floor(height) or depth ~= math.floor(depth) then
- print('Dimensions must be whole numbers')
- error()
- end
- if width < 1 or height < 1 or depth < 1 then
- print('All dimensions must be at least 1')
- error()
- end
- local x = 0
- local y = 0 --in minecraft y is really z but the turtles coords are relative to itself so it doesnt matter
- local z = 0
- local orient = 1 -- 1 = default, goes clockwise
- local useEnderChest = false
- local xDiff = {0, 1, 0, -1}
- local yDiff = {1, 0, -1, 0}
- if turtle.getItemCount(1) == 1 then
- useEnderChest = true
- end
- local function hasSpace()
- for n = 1, 16 do
- if turtle.getItemCount(n) == 0 then
- return true
- end
- sleep(0)
- end
- return false
- end
- local function dumpItems(dir, force)
- if not useEnderChest then
- return
- end
- if hasSpace() and not force then
- return
- end
- local place = turtle.place
- local dig = turtle.dig
- local drop = turtle.drop
- local detect = turtle.detect
- if dir == "up" then
- place = turtle.placeUp
- dig = turtle.digUp
- drop = turtle.dropUp
- detect = turtle.detectUp
- elseif dir == "down" then
- place = turtle.placeDown
- dig = turtle.digDown
- drop = turtle.dropDown
- detect = turtle.detectDown
- end
- while detect() and not dig() do end
- turtle.select(1)
- while not place() do end
- for n = 1, 16 do
- turtle.select(n)
- drop()
- end
- turtle.select(1)
- while not dig() do end
- end
- local function forward()
- x = x + xDiff[orient + 1]
- y = y + yDiff[orient + 1]
- moved = turtle.forward()
- while not moved do
- turtle.attack()
- if turtle.getFuelLevel() == 0 then
- print('Out of fuel\nWaiting for fuel in slot 2...')
- turtle.select(2)
- while turtle.getFuelLevel() == 0 do
- turtle.refuel()
- end
- print('Fuel level is: ' .. turtle.getFuelLevel())
- end
- if turtle.detect() then turtle.dig() dumpItems() end
- moved = turtle.forward()
- end
- if z > -depth + 1 and turtle.detectDown() then turtle.digDown() dumpItems("down") end
- if turtle.detectUp() then turtle.digUp() dumpItems("up") end
- end
- local function left()
- orient = orient - 1
- orient = (orient % 4)
- turtle.turnLeft()
- end
- local function right()
- orient = orient + 1
- orient = (orient % 4)
- turtle.turnRight()
- end
- local function up()
- if turtle.detectUp() then turtle.digUp() dumpItems("up") end
- moved = turtle.up()
- if not moved then
- repeat
- if turtle.detectUp() then turtle.digUp() dumpItems("up") end
- moved = turtle.up()
- until moved
- end
- z = z + 1
- if turtle.detectUp() and z < height -1 then turtle.digUp() dumpItems("up") end
- end
- local function down()
- local dug = true
- if turtle.detectDown() then turtle.digDown() dumpItems("down") end
- moved = turtle.down()
- if not moved then
- repeat
- if turtle.detectDown() then dug = turtle.digDown() dumpItems("down") end
- if not dug then --bedrock
- dumpItems(nil, true)
- error()
- end
- moved = turtle.down()
- until moved
- end
- z = z - 1
- if turtle.detectDown() and z > -depth + 1 then turtle.digDown() dumpItems("down") end
- end
- local function isEven(n)
- return n % 2 == 0
- end
- local function round(n) -- rounds numbers
- return math.floor(n + 0.5)
- end
- local function turn(n)
- if n % 2 == 0 then left()
- else right() end
- end
- local function digStrip()
- for n=0, height-2 do
- forward()
- end
- end
- local function digLayer()
- for n = 0, width-1 do
- if n ~= width-1 then
- digStrip()
- turn(n)
- forward()
- turn(n)
- end
- end
- digStrip()
- if width % 2 ~= 0 then left() end
- for n = 1, 3 do
- if z > -depth + 1 then down() end
- end
- end
- local function digCube()
- if depth > 1 then down() end
- for n = 1, (round((depth + 1)/3)*3)/3 do
- digLayer()
- left()
- end
- end
- if width % 2 == 0 then
- width, height = height, width
- for n=0, width-2 do forward() end
- left()
- orient = 1
- x, y = 0, 0
- end
- digCube()
- dumpItems(nil, true)
Advertisement
Add Comment
Please, Sign In to add comment