Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local width = tonumber(tArgs[1])
- local length = tonumber(tArgs[2])
- local depth = tonumber(tArgs[3])
- local dir = 0
- local NORTH,EAST,SOUTH,WEST = 0,1,2,3
- local INPUT_PIPE = 1
- local TRANSPORT_PIPE = 2
- if width > 0 and length > 0 and depth > 0 then
- print ("Digging a "..tostring(width)
- .." x "..tostring(length)
- .." x "..tostring(depth)
- .." square.")
- end
- local function refuel()
- if turtle.getFuelLevel() < 20 then
- local i=1
- while not turtle.refuel(i) do
- turtle.select(i)
- i = i + 1
- if i > 16 then
- print("Need fuel to continue...")
- break
- end
- end
- end
- end
- local function forward()
- while turtle.detect() do
- turtle.dig()
- end
- refuel()
- turtle.forward()
- end
- local function turnRight()
- turtle.turnRight()
- dir = (dir + 1) % 4
- end
- local function turnLeft()
- turtle.turnLeft()
- dir = (dir - 1) % 4
- end
- local function face(d)
- local delta = (d - dir) % 4
- if delta == 0 then
- return
- elseif delta == 1 then
- turnRight()
- elseif delta == 2 then
- turnRight()
- turnRight()
- elseif delta == 3 then
- turnLeft()
- end
- end
- local function placePipe(n)
- turtle.select(n)
- turtle.place()
- end
- local function placeInputPipe()
- placePipe(INPUT_PIPE)
- end
- local function placeTransportPipe()
- placePipe(TRANSPORT_PIPE)
- end
- local function minePipe()
- turtle.select(1)
- turtle.dig()
- end
- local function unload()
- face(WEST)
- placeInputPipe()
- turtle.up()
- turtle.up()
- forward()
- for i=3,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.back()
- turtle.down()
- placeTransportPipe()
- turtle.down()
- minePipe()
- placeTransportPipe()
- end
- local function digRow(n)
- for i=1,n-1 do
- turtle.dig()
- forward()
- end
- end
- local function advanceRowOdd()
- face(EAST)
- turtle.dig()
- forward()
- face(NORTH)
- end
- local function advanceRowEven()
- face(EAST)
- turtle.dig()
- forward()
- face(SOUTH)
- end
- local function advanceLevel()
- unload()
- turtle.digDown()
- turtle.down()
- forward()
- face(NORTH)
- end
- local function startingPoint(x,y)
- face(WEST)
- digRow(x-1)
- if width % 2 == 1 then
- face(SOUTH)
- digRow(y)
- end
- end
- local function digSquare(x,y)
- for i=1,x do
- digRow(y)
- if i ~= x then
- if i % 2 == 0 then
- advanceRowOdd()
- else
- advanceRowEven()
- end
- end
- end
- startingPoint(x,y)
- end
- local function digStairs(x,y,z)
- for i=1, z do
- digSquare(x,y)
- advanceLevel()
- end
- end
- function main()
- digStairs(width,length,depth)
- print("Mine Complete")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement