Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --Desc: A turtle program which attempts to stair down through blocks, number of stairs defined by the user
- -- Useful for making mineshafts or traversing the nether
- --By: hornedcommando and BadPunBananas
- --TODO: currently it is hardcoded to only place dirtblocks, should be updated to a dict with at least cobble and netherack
- local function input()
- while true do
- write("How Many Stairs?\n")
- size = tonumber(read())
- break
- end
- end
- local function isForbiddenBlock(blockName)
- local forbiddenBlocks = {
- "forbidden_arcanus:stella_arcanum",
- "minecraft:bedrock"
- }
- for _, forbiddenBlock in ipairs(forbiddenBlocks) do
- if blockName == forbiddenBlock then
- return true
- end
- end
- return false
- end
- function searchInventory(name)
- for slot = 1, 16 do
- turtle.select(slot)
- local slotDetail = turtle.getItemDetail()
- if slotDetail and slotDetail.name:find(name) then
- return slot -- Return the slot number if item found
- end
- end
- return nil -- Return nil if item not found
- end
- function fill(name)
- local found, slot = searchInventory(name)
- if found then
- turtle.placeDown() -- Place the block
- print("Placed block:", name)
- else
- print("Block not found:", name)
- end
- end
- --Function to refuel the turtle, attempts to maintain a specified fuel level, this could be adjusted based on abundance of fuel or time between fuel calls
- local function smartRefuel()
- print("Checking Fuel")
- -- Check if fuel level is below 1000
- while turtle.getFuelLevel() < 1000 do
- print("Refueling")
- for slot = 1, 16 do
- turtle.select(slot) -- Select the slot
- if turtle.refuel(0) then
- -- Check if the selected item is a fuel
- turtle.refuel(1) -- Refuel with the selected item
- break -- Stop searching for fuel after refueling
- end
- end
- end
- end
- function gd()
- print("Going down")
- local success, block = turtle.inspectDown()
- if isForbiddenBlock(block.name) then
- print("Detected block is forbidden")
- return false
- else
- local success, block = turtle.inspectUp()
- if isForbiddenBlock(block.name) then
- print("Detected block is forbidden")
- return false
- else
- turtle.digUp()
- while not turtle.down() do
- print("Digging down")
- turtle.digDown()
- end
- if not turtle.inspectDown() then
- fill("minecraft:dirt")
- end
- return true
- end
- end
- end
- function gf()
- print("Going forward")
- local success, block = turtle.inspect()
- if isForbiddenBlock(block.name) then
- print("Detected block is forbidden")
- return false
- else
- while not turtle.forward() do
- print("Digging forward")
- turtle.dig()
- end
- end
- end
- function stairDown()
- for i = 1, size do
- gd()
- gf()
- end
- end
- input()
- smartRefuel()
- stairDown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement