Advertisement
hornedcommando

Minecraft Turtle stairDown

May 2nd, 2024
829
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.17 KB | Gaming | 0 0
  1. --Desc: A turtle program which attempts to stair down through blocks, number of stairs defined by the user
  2. -- Useful for making mineshafts or traversing the nether
  3. --By: hornedcommando and BadPunBananas
  4.  
  5. --TODO: currently it is hardcoded to only place dirtblocks, should be updated to a dict with at least cobble and netherack
  6.  
  7.  
  8. local function input()
  9.     while true do
  10.         write("How Many Stairs?\n")
  11.         size = tonumber(read())
  12.         break
  13.     end
  14. end
  15.  
  16. local function isForbiddenBlock(blockName)
  17.     local forbiddenBlocks = {
  18.         "forbidden_arcanus:stella_arcanum",
  19.         "minecraft:bedrock"
  20.     }
  21.     for _, forbiddenBlock in ipairs(forbiddenBlocks) do
  22.         if blockName == forbiddenBlock then
  23.             return true
  24.         end
  25.     end
  26.     return false
  27. end
  28.  
  29. function searchInventory(name)
  30.     for slot = 1, 16 do
  31.         turtle.select(slot)
  32.         local slotDetail = turtle.getItemDetail()
  33.         if slotDetail and slotDetail.name:find(name) then
  34.             return slot -- Return the slot number if item found
  35.         end
  36.     end
  37.     return nil -- Return nil if item not found
  38. end
  39.  
  40. function fill(name)
  41.     local found, slot = searchInventory(name)
  42.     if found then
  43.         turtle.placeDown()  -- Place the block
  44.         print("Placed block:", name)
  45.     else
  46.         print("Block not found:", name)
  47.     end
  48. end
  49.  
  50. --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
  51. local function smartRefuel()
  52.     print("Checking Fuel")
  53.     -- Check if fuel level is below 1000
  54.     while turtle.getFuelLevel() < 1000 do
  55.         print("Refueling")
  56.         for slot = 1, 16 do
  57.             turtle.select(slot) -- Select the slot
  58.             if turtle.refuel(0) then
  59.                 -- Check if the selected item is a fuel
  60.                 turtle.refuel(1) -- Refuel with the selected item
  61.                 break -- Stop searching for fuel after refueling
  62.             end
  63.         end
  64.     end
  65. end
  66.  
  67. function gd()
  68.     print("Going down")
  69.     local success, block = turtle.inspectDown()
  70.     if isForbiddenBlock(block.name) then
  71.         print("Detected block is forbidden")
  72.         return false
  73.     else
  74.         local success, block = turtle.inspectUp()
  75.         if isForbiddenBlock(block.name) then
  76.             print("Detected block is forbidden")
  77.             return false
  78.         else
  79.             turtle.digUp()
  80.             while not turtle.down() do
  81.                 print("Digging down")
  82.                 turtle.digDown()
  83.             end
  84.             if not turtle.inspectDown() then
  85.                 fill("minecraft:dirt")
  86.             end
  87.             return true
  88.         end
  89.     end
  90.  
  91. end
  92.  
  93. function gf()
  94.     print("Going forward")
  95.     local success, block = turtle.inspect()
  96.     if isForbiddenBlock(block.name) then
  97.         print("Detected block is forbidden")
  98.         return false
  99.     else
  100.         while not turtle.forward() do
  101.             print("Digging forward")
  102.             turtle.dig()
  103.         end
  104.     end
  105. end
  106.  
  107. function stairDown()
  108.     for i = 1, size do
  109.         gd()
  110.         gf()
  111.     end
  112. end
  113.  
  114. input()
  115. smartRefuel()
  116. stairDown()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement