Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- local levels = 5
- if #args ~= 0 then
- if tonumber(args[1]) == nil then
- error("input must be a number")
- else
- levels = tonumber(args[1])
- end
- end
- local COBBLE = "minecraft:cobblestone"
- local DEEPSLATE = "minecraft:cobbled_deepslate"
- local COLLBE_STAIRS = "minecraft:cobblestone_stairs"
- local DEEPSLATE_STAIRS = "minecraft:cobbled_deepslate_stairs"
- local TORCH = "minecraft:torch"
- local preferredBuildingBlock = COBBLE
- local preferredStairBlock = COLLBE_STAIRS
- local function selectItem(itemname)
- local function isItem()
- local details = turtle.getItemDetail()
- if details ~= nil then
- if details.name == itemname then
- return true
- end
- end
- return false
- end
- if isItem() then return true end
- for i = 1, 16, 1 do
- turtle.select(i)
- if isItem() then return true end
- end
- return false
- end
- ---@enum Directions
- local Directions = {
- forward = 0,
- up = 2,
- down = 4,
- }
- local function selectAlternateBlock(blockname)
- if blockname == COBBLE then
- if selectItem(DEEPSLATE) then
- preferredBuildingBlock = DEEPSLATE
- else
- error(COBBLE .. " and " .. DEEPSLATE .. " not found in inventory")
- end
- elseif blockname == COLLBE_STAIRS then
- if selectItem(DEEPSLATE_STAIRS) then
- preferredStairBlock = DEEPSLATE_STAIRS
- else
- error(COLLBE_STAIRS .. " and " .. DEEPSLATE_STAIRS .. " not found in inventory")
- end
- else
- error(blockname .. " not found in inventory")
- end
- end
- ---@param direction Directions
- local function placeBlock(direction, blockname)
- if blockname == nil then
- blockname = preferredBuildingBlock
- end
- if not selectItem(blockname) then
- selectAlternateBlock(blockname)
- end
- if direction == Directions.forward then
- turtle.place()
- end
- if direction == Directions.down then
- turtle.placeDown()
- end
- if direction == Directions.up then
- turtle.placeUp()
- end
- end
- local function surroundingsSafe()
- if turtle.inspectDown() or turtle.inspectUp() then
- return false
- end
- return true
- end
- ---comment
- ---@return boolean
- ---@param placeTorch boolean
- local function digLevel(placeTorch)
- preferredBuildingBlock = COBBLE
- local function moveToNextLevel()
- turtle.dig()
- turtle.forward()
- turtle.digDown()
- turtle.down()
- turtle.turnLeft()
- placeBlock(Directions.forward)
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- placeBlock(Directions.up, COLLBE_STAIRS)
- turtle.back()
- turtle.turnRight()
- end
- local function digOneUp()
- while not turtle.up() do
- turtle.digUp()
- end
- placeBlock(Directions.forward)
- end
- moveToNextLevel()
- turtle.up()
- placeBlock(Directions.forward)
- digOneUp()
- digOneUp()
- digOneUp()
- placeBlock(Directions.up)
- turtle.turnRight()
- turtle.turnRight()
- placeBlock(Directions.forward)
- turtle.down()
- placeBlock(Directions.forward)
- turtle.down()
- placeBlock(Directions.forward)
- if placeTorch then
- placeBlock(Directions.up, TORCH)
- end
- turtle.down()
- placeBlock(Directions.forward)
- if not surroundingsSafe() then
- turtle.turnLeft()
- turtle.down()
- return false
- end
- turtle.down()
- placeBlock(Directions.forward)
- turtle.turnLeft()
- return true
- end
- local safe = true
- local counter = 0
- local function levelsAndTorch()
- for i = 1, 5, 1 do
- if not safe then return false end
- if counter >= levels then return false end
- if i < 5 then
- safe = digLevel(false)
- else
- safe = digLevel(true)
- end
- counter = counter + 1
- end
- return true
- end
- local canResume = true
- while canResume do
- canResume = levelsAndTorch()
- end
Advertisement
Add Comment
Please, Sign In to add comment