Advertisement
ironman2745

stairway

Apr 2nd, 2024 (edited)
765
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.15 KB | None | 0 0
  1. require("turtleLib")
  2.  
  3. function setupTorchesInInventory()
  4.     local torchesPresent = false
  5.     local previousSlot = turtle.getSelectedSlot()
  6.     local torchesIndex = searchInventoryForItem("minecraft:torch")
  7.     if torchesIndex > -1 then
  8.         torchesPresent = true
  9.         turtle.select(torchesIndex)
  10.         turtle.transferTo(16)
  11.         turtle.select(previousSlot)
  12.     end
  13.     return torchesPresent
  14. end
  15.  
  16. function placeTorch()
  17.     if turtle.getItemDetail(16) ~= nil then
  18.         if turtle.getItemDetail(16).name == "minecraft:torch" then
  19.             local previousSlot = turtle.getSelectedSlot()
  20.             local torchIndex = searchInventoryForItem("minecraft:torch")
  21.             turtle.select(torchIndex)
  22.             turtle.placeUp()
  23.             turtle.select(previousSlot)
  24.         end
  25.     end
  26. end
  27.  
  28.  
  29. local torches = setupTorchesInInventory()
  30. local depth = 0;
  31. -- Dig forward a couple blocks for a doorway
  32. turtle.dig()
  33. goForward()
  34. turtle.digUp()
  35. turtle.dig()
  36. goForward()
  37. turtle.digUp()
  38. turtle.digDown()
  39.  
  40. -- Start digging the stairway
  41. local success, data = turtle.inspectDown()
  42. while data.name ~= "minecraft:bedrock" do
  43.     turtle.dig()
  44.     goForward()
  45.     turtle.digUp()
  46.     if (depth%5)==0 then
  47.         placeTorch()
  48.     end
  49.     turtle.digDown()
  50.     goDown()
  51.     turtle.digDown()
  52.     depth = depth + 1
  53.     success, data = turtle.inspectDown()
  54. end
  55.  
  56. -- Continue until reaching bedrock
  57. -- turn around
  58. turtle.turnRight()
  59. turtle.turnRight()
  60.  
  61. local stairsIndex = searchInventoryForItem("minecraft:cobblestone_stairs")
  62. local stairsPresent = (stairsIndex > -1)
  63.  
  64. -- Return to surface
  65. for i=1, depth do -- fixme. use for loop and counter
  66.     goForward()
  67.     -- if stairs present in inventory
  68.     if stairsPresent then
  69.         local preselectedSlot = turtle.getSelectedSlot()
  70.         local itemDetail = turtle.getItemDetail(stairsIndex)
  71.         -- Because staircase can be more than 64 deep...
  72.         -- Make sure we still have stairs selected
  73.         if(itemDetail == nil or itemDetail.name ~= "minecraft:cobblestone_stairs") then
  74.             stairsIndex = searchInventoryForItem("minecraft:cobblestone_stairs")
  75.             stairsPresent = (stairsIndex > -1)
  76.         end
  77.         turtle.select(stairsIndex)
  78.         turtle.digDown()
  79.         turtle.placeDown()
  80.         -- check to make sure stairs are right side up
  81.         local success, data = turtle.inspectDown()
  82.         if success and data.state.half == "top" then
  83.             -- stair is upsidown
  84.             turtle.digDown()
  85.             goDown()
  86.             local fillerBlockIndex = searchInventoryForItem("minecraft:cobblestone")
  87.             if fillerBlockIndex > -1 then
  88.                 turtle.select(fillerBlockIndex)
  89.             else
  90.                 fillerBlockIndex = searchInventoryForItem("minecraft:cobbled_deepslate")
  91.                 if fillerBlockIndex > -1 then
  92.                     turtle.select(fillerBlockIndex)
  93.                 end
  94.             end
  95.             turtle.placeDown()
  96.             goUp()
  97.             turtle.select(stairsIndex)
  98.             turtle.placeDown()
  99.         end
  100.         if(i==depth) then
  101.             turtle.dig()
  102.             turtle.place()
  103.         end
  104.         turtle.select(preselectedSlot)
  105.         else
  106.     end
  107.     -- endif
  108.     goUp()
  109. end
  110.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement