Advertisement
ceribia

shaft

Jun 18th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. local wallItem = 1 --Top left slot
  2. local ladder = 2 --Top middle slot
  3. local invStart = 3 --Top right slot
  4.  
  5. local function unload( _bKeepOneFuelStack )
  6. print( "Unloading items..." )
  7. for n=invStart,16 do
  8. if n ~= placeItem then
  9. turtle.select(n)
  10. turtle.refuel(0)
  11. turtle.drop()
  12. end
  13. end
  14. end
  15.  
  16. local function isFull()
  17. for n=invStart,16 do
  18. if turtle.getItemCount(n) == 0 then
  19. --Empty slots
  20. return false;
  21. end
  22. end
  23. print( "No empty slots left." )
  24. return true;
  25. end
  26.  
  27. function refuel( ammount )
  28. local fuelLevel = turtle.getFuelLevel()
  29. if fuelLevel == "unlimited" then
  30. return true
  31. end
  32.  
  33. if turtle.getFuelLevel() < 1 then
  34. for n=invStart,16 do
  35. turtle.select(n)
  36. if turtle.refuel(0) then
  37. return true
  38. end
  39. end
  40. return false
  41. end
  42.  
  43. return true
  44. end
  45.  
  46. local function wallAround( slot )
  47. turtle.select(slot)
  48. for n=1,4 do
  49. if not turtle.detect() then
  50. if turtle.getItemCount() == 0 then
  51. print("Out of wall items")
  52. error("Out of wall items")
  53. else
  54. turtle.place()
  55. end
  56. end
  57. turtle.turnLeft()
  58. end
  59. end
  60.  
  61. local function tryDown()
  62. if not refuel() then
  63. print( "Not enough Fuel" )
  64. end
  65.  
  66. while not turtle.down() do
  67. if not turtle.digDown() then
  68. if isFull() then
  69. unload()
  70. elseif turtle.attackDown() then
  71. -- Do Nothing
  72. else
  73. sleep( 0.5 )
  74. end
  75. end
  76. end
  77. return true
  78. end
  79.  
  80. -----------------------------------------------------------------------------
  81. --Main Program
  82. -----------------------------------------------------------------------------
  83.  
  84. local tArgs = { ... }
  85. if #tArgs ~= 1 then
  86. print( "My Version Usage: shaft depth" )
  87. return
  88. end
  89.  
  90. local depth = tonumber( tArgs[1] )
  91.  
  92. if not refuel() then
  93. print( "Out of Fuel" )
  94. return
  95. end
  96.  
  97. print( "Digging a shaft" )
  98. for shaftDepth=1,depth do
  99. print("Shafting " .. shaftDepth .. " / " .. depth)
  100.  
  101. wallAround(wallItem)
  102. tryDown()
  103.  
  104. turtle.select(ladder)
  105. turtle.placeUp()
  106. end
  107.  
  108. print( "Done" )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement