Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local xWidth = tonumber(tArgs[1])
- local zWidth = tonumber(tArgs[2]) or 1
- local useEnder = tArgs[3] or false
- local xPos = 1
- local zPos = 1
- local xDir, zDir = 1, 0
- local curSlot = 1
- local function selectResource()
- while turtle.getItemCount(curSlot) == 0 and curSlot < 16 do
- curSlot = curSlot + 1
- end
- turtle.select(curSlot)
- if curSlot == 16 then
- if not useEnder then
- return false
- end
- turtle.placeUp()
- for i = 1, 15, 1 do
- turtle.select(i)
- turtle.suckUp()
- end
- turtle.select(curSlot)
- turtle.digUp()
- curSlot = 1
- turtle.select(curSlot)
- end
- return true
- end
- local function placeDown()
- local result = selectResource()
- if not result then
- return false
- end
- return turtle.placeDown()
- end
- local function fillUnit()
- local y = 0
- while not turtle.detectDown() do
- local down = false
- while not down do
- down = turtle.down()
- end
- y = y - 1
- end
- local result = true
- while y < 0 and result do
- local up = false
- while not up do
- up = turtle.up()
- end
- result = placeDown()
- y = y + 1
- end
- if y == 0 then
- return true
- end
- while y < 0 do
- local up = false;
- while not up do
- up = turtle.up()
- end
- y = y + 1
- end
- return false
- end
- local function turnRight(times)
- times = times or 1
- for i = 1, times, 1 do
- if xDir == 1 then
- xDir = 0
- zDir = 1
- elseif xDir == -1 then
- xDir = 0
- zDir = -1
- elseif zDir == 1 then
- xDir = -1
- zDir = 0
- else
- xDir = 1
- zDir = 0
- end
- turtle.turnRight()
- end
- end
- local function turnLeft(times)
- times = times or 1
- for i = 1, times, 1 do
- if xDir == 1 then
- xDir = 0
- zDir = -1
- elseif xDir == -1 then
- xDir = 0
- zDir = 1
- elseif zDir == 1 then
- xDir = 1
- zDir = 0
- else
- xDir = -1
- zDir = 0
- end
- turtle.turnLeft()
- end
- end
- local function forward(times)
- times = times or 1
- local result = false
- for i = 1, times, 1 do
- while not result do
- turtle.dig()
- result = turtle.forward()
- end
- if result then
- xPos = xPos + xDir
- zPos = zPos + zDir
- else
- return false
- end
- end
- return true
- end
- local result = fillUnit()
- local done = false
- local doneRow = false
- while not done and result do
- if doneRow then
- if xDir == 1 then
- turnRight()
- result = forward()
- result = result and fillUnit()
- turnRight()
- else
- turnLeft()
- result = forward()
- result = result and fillUnit()
- turnLeft()
- end
- doneRow = false
- else
- result = forward()
- result = result and fillUnit()
- if xPos == 1 or xPos == xWidth then
- doneRow = true
- end
- if doneRow and zPos == zWidth then
- done = true
- end
- end
- end
- if xDir == 1 then
- turnLeft()
- else
- turnRight()
- end
- while zPos > 1 do
- forward()
- end
- turnLeft()
- while xPos > 1 do
- forward()
- end
Advertisement
Add Comment
Please, Sign In to add comment