Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- local levelHeight = 5
- local width = 5
- local cactusSlot = 1
- local floorSlot = 2
- local wallSlot = 3
- local baseSlot = 4
- local sandSlot = 5
- local fenceSlot = 6
- local torchSlot = 7
- local ladderSlot = 8
- local reservedSlots = 8
- local moveSleep = 0.2
- local paintSleep = 0.5
- local blockedMoveSleep = 2
- local doLadders = turtle.getItemCount(ladderSlot) > 0
- local doPaintWalls = turtle.getItemCount(wallSlot) > 0
- local doPaintFloor = turtle.getItemCount(floorSlot) > 0
- local function printUsage()
- print("Usage: cactus <levelCount>")
- print("")
- print("Slots:")
- print(" 1 - Cactus")
- print(" 2 - Floor")
- print(" 3 - Wall")
- print(" 4 - Base")
- print(" 5 - Sand")
- print(" 6 - Fence")
- print(" 7 - Torch")
- print(" 8 - Ladder")
- print("")
- end
- if #tArgs ~= 1 then
- printUsage()
- return
- end
- local levelCount = tonumber(tArgs[1])
- local roomHeight = levelCount * levelHeight + 2
- local function selectMaterial(typeSlot)
- turtle.select(typeSlot)
- if turtle.getItemCount(typeSlot) > 1 then
- return true
- else
- for otherSlot = 16, 1, -1 do
- if (turtle.compareTo(otherSlot)) then
- if otherSlot <= reservedSlots then
- if turtle.getItemCount(otherSlot) > 1 then
- turtle.select(otherSlot)
- return true
- end
- else
- turtle.select(otherSlot)
- return true
- end
- end
- end
- end
- return false
- end
- local function turtleForward()
- local moveSuccess = false
- while (not moveSuccess) do
- while turtle.detect() do
- turtle.dig()
- sleep(moveSleep)
- end
- moveSuccess = turtle.forward()
- if (not moveSuccess) then
- sleep(blockedMoveSleep)
- end
- end
- end
- local function turtleUp()
- local moveSuccess = false
- while (not moveSuccess) do
- while turtle.detectUp() do
- turtle.digUp()
- sleep(moveSleep)
- end
- moveSuccess = turtle.up()
- if (not moveSuccess) then
- sleep(blockedMoveSleep)
- end
- end
- end
- local function turtleUpX(count)
- for i = 1, count do
- turtleUp()
- end
- end
- local function turtleDown()
- local moveSuccess = false
- while (not moveSuccess) do
- while turtle.detectDown() do
- turtle.digDown()
- sleep(moveSleep)
- end
- moveSuccess = turtle.down()
- if (not moveSuccess) then
- sleep(blockedMoveSleep)
- end
- end
- end
- local function turtleDownX(count)
- for i = 1, count do
- turtleDown()
- end
- end
- local function doPaintSide()
- if doPaintWalls then
- if selectMaterial(wallSlot) then
- if not turtle.compare() then
- while turtle.detect() do
- turtle.dig()
- sleep(paintSleep)
- end
- turtle.place()
- end
- end
- end
- end
- function plant()
- selectMaterial(cactusSlot)
- turtle.placeDown()
- end
- local function returnToLevelStart(oddWidth)
- if oddWidth then
- -- odd width of chamber.. in opposite end.
- turtle.turnRight()
- for j = 1, 2 do
- turtle.turnRight()
- for i = 1, width - 1 do
- turtleForward()
- end
- end
- turtle.turnRight()
- else
- -- even width.. back in same end as we started.
- turtle.turnRight()
- for i = 1, width - 1 do
- turtleForward()
- end
- turtle.turnRight()
- end
- end
- local function turnAround(turnRight, steps)
- if turnRight then
- turtle.turnRight()
- for i = 1, steps do
- turtleForward()
- end
- turtle.turnRight()
- else
- turtle.turnLeft()
- for i = 1, steps do
- turtleForward()
- end
- turtle.turnLeft()
- end
- return (not turnRight)
- end
- local function turn(turnRight)
- if turnRight then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- local function digLevel(digup, digdown)
- local turnRight = true
- for i = 1, width do
- for j = 1, width - 1 do
- if (digup) then
- turtle.digUp()
- end
- if (digdown) then
- turtle.digDown()
- end
- turtleForward()
- end
- if (digup) then
- turtle.digUp()
- end
- if (digdown) then
- turtle.digDown()
- end
- if i < width then
- turnRight = turnAround(turnRight, 1)
- end
- end
- returnToLevelStart(turnRight)
- end
- local function paintWall()
- if selectMaterial(wallSlot) then
- if not turtle.compare() then
- while turtle.detect() do
- turtle.dig()
- sleep(paintSleep)
- end
- turtle.place()
- end
- end
- end
- local function paintLeftWall()
- turtle.turnLeft()
- paintWall()
- turtle.turnRight()
- end
- local function placeDown(slot)
- if selectMaterial(slot) then
- if not turtle.compareDown() then
- while turtle.detectDown() do
- turtle.digDown()
- sleep(paintSleep)
- end
- turtle.placeDown()
- end
- end
- end
- local function paintFloorBlock()
- placeDown(floorSlot)
- end
- local function placeBaseBlock()
- placeDown(baseSlot)
- end
- local function placeSandBlock()
- placeDown(sandSlot)
- end
- local function placeCactusBlock()
- placeDown(cactusSlot)
- end
- local function placeFenceBlock()
- placeDown(fenceSlot)
- end
- local function placeTorchBlock()
- placeDown(torchSlot)
- end
- local function paintLevelWalls()
- for i = 1, 4 do
- for j = 1, width - 1 do
- paintLeftWall()
- turtleForward()
- end
- paintLeftWall()
- turtle.turnRight()
- end
- end
- local function paintEntireFloor()
- local turnRight = true
- for i = 1, width do
- for j = 1, width - 1 do
- paintFloorBlock()
- turtleForward()
- end
- paintFloorBlock()
- if i < width then
- turnRight = turnAround(turnRight, 1)
- end
- end
- returnToLevelStart(turnRight)
- end
- local function placeDeltaGridBlocks(paintFunc, offsetX, deltaX, offsetY, deltaY)
- local turnRight = true
- turtle.turnRight()
- for i = 1, offsetX do
- turtleForward()
- end
- turtle.turnLeft()
- for i = 1, offsetY do
- turtleForward()
- end
- local xWidth = width - (2 * offsetX)
- local yWidth = width - (2 * offsetY)
- local x = 0
- while x < xWidth do
- for y = 0, yWidth - 1 do
- if y % deltaY == 0 then
- paintFunc()
- end
- if (y < yWidth - 1) then
- turtleForward()
- end
- end
- if x < xWidth - 1 then
- turnRight = turnAround(turnRight, deltaX)
- end
- x = x + deltaX
- end
- turn(turnRight)
- for i = 1, offsetX do
- turtleForward()
- end
- turn(not turnRight)
- for i = 1, offsetY do
- turtleForward()
- end
- returnToLevelStart(turnRight)
- end
- local function placeGridBlocks(paintFunc)
- placeDeltaGridBlocks(paintFunc, 1, 2, 1, 2)
- end
- local function placeBetweenGridBlocks(paintFunc)
- placeDeltaGridBlocks(paintFunc, 2, 4, 1, 2)
- end
- local function placeBaseBlocks()
- placeGridBlocks(placeBaseBlock)
- end
- local function placeSandBlocks()
- placeGridBlocks(placeSandBlock)
- end
- local function placeCactusBlocks()
- placeGridBlocks(placeCactusBlock)
- end
- local function placeFenceBlocks()
- placeBetweenGridBlocks(placeFenceBlock)
- end
- local function placeTorchBlocks()
- placeBetweenGridBlocks(placeTorchBlock)
- end
- local function digout2(height)
- for i = 1, height do
- digLevel(false, false)
- if (doPaintWalls) then
- paintLevelWalls()
- end
- if i < height then
- turtleDown()
- end
- end
- if (doPaintFloor) then
- paintEntireFloor()
- end
- end
- local function paintWalls(height)
- for i = 1, height - 1 do
- turtleUp()
- end
- paintLevelWalls()
- for i = 1, height - 1 do
- turtleDown()
- paintLevelWalls()
- end
- end
- local function digout(height)
- local i = 0
- while (i < height) do
- local delta = 0
- if (height - i >= 3) then
- turtleDown()
- digLevel(true, true)
- turtleDown()
- delta = 3
- elseif (height - i == 2) then
- turtleDown()
- digLevel(true, false)
- delta = 2
- elseif (height - i == 1) then
- digLevel(false, false)
- delta = 1
- end
- i = i + delta
- -- if (doPaintWalls) then
- -- paintWalls(delta)
- -- end
- if i < height then
- turtleDown()
- end
- end
- if (doPaintFloor) then
- paintEntireFloor()
- end
- end
- local function placeLevel()
- turtleUp()
- placeBaseBlocks()
- turtleUp()
- placeSandBlocks()
- turtleUp()
- placeCactusBlocks()
- turtleUp()
- placeFenceBlocks()
- turtleUp()
- placeTorchBlocks()
- end
- local function moveUpDown(goingUp)
- if (goingUp) then
- turtleUp()
- else
- turtleDown()
- end
- end
- local function paintWalls2()
- turtleUpX(roomHeight - 1)
- turtle.turnLeft()
- local goingUp = false
- for k = 1, 4 do
- for j = 1, width do
- for i = 1, roomHeight do
- paintWall()
- if (i < roomHeight) then
- moveUpDown(goingUp)
- end
- end
- goingUp = not goingUp
- if j < width then
- turtle.turnRight()
- turtleForward()
- turtle.turnLeft()
- end
- end
- turtle.turnRight()
- end
- turtle.turnRight()
- turtleDownX(roomHeight - 1)
- end
- digout(roomHeight)
- if (doPaintWalls) then
- paintWalls2()
- end
- turtleUp()
- for i = 1, levelCount do
- placeLevel()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement