Lee_Lenalee

Block miner

Jan 25th, 2021 (edited)
1,217
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.50 KB | None | 0 0
  1. shell.openTab("shell")
  2.  
  3. STONE_SLOT = 1
  4. MC_STACK_DEFAULT_SIZE= 64
  5.  
  6. local function _turnToCardinalDirection(direction)
  7.     while  peripheral.find("NBT_Observer").read_state().facing ~= direction do
  8.         turtle.turnRight()
  9.     end
  10. end
  11.  
  12. function faceNorth()
  13.     _turnToCardinalDirection("north")
  14. end
  15.  
  16. function faceEast()
  17.     _turnToCardinalDirection("east")
  18. end
  19.  
  20. function faceSouth()
  21.     _turnToCardinalDirection("south")
  22. end
  23.  
  24. function faceWest()
  25.     _turnToCardinalDirection("west")
  26. end
  27.  
  28. function _emptySlot(slot)
  29.     turtle.select(slot)
  30.     turtle.drop()
  31. end
  32.  
  33. function fillStone()
  34.     turnToStoneChest()
  35.     turtle.select(STONE_SLOT)
  36.     turtle.suck(MC_STACK_DEFAULT_SIZE - (turtle.getItemDetail(STONE_SLOT) and turtle.getItemDetail(STONE_SLOT).count or 0))
  37. end
  38.  
  39. function dropInvOres()
  40.     turnToOreChest()
  41.     for slot=2, 16 do
  42.         _emptySlot(slot)
  43.     end
  44. end
  45.  
  46. function turnToBlockToMine()
  47.     faceWest()
  48. end
  49.  
  50. function turnToStoneChest()
  51.     faceSouth()
  52. end
  53.  
  54. function turnToOreChest()
  55.     faceNorth()
  56. end
  57.  
  58. function blockReadyToMine()
  59.     turnToBlockToMine()
  60.     bool, block = turtle.inspect()
  61.     return bool and block.name ~= "minecraft:stone"
  62. end
  63.  
  64. function blockIsAir()
  65.     turnToBlockToMine()
  66.     bool = turtle.inspect()
  67.     return not bool
  68. end
  69.  
  70. function placeStone()
  71.     turnToBlockToMine()
  72.     turtle.select(STONE_SLOT)
  73.     turtle.place()
  74. end
  75.  
  76. while true do
  77.     if blockReadyToMine() then
  78.         turtle.dig()
  79.         placeStone()
  80.     end
  81.    
  82.     while blockIsAir() do
  83.         turtle.attack()
  84.         placeStone()
  85.     end
  86.    
  87.     dropInvOres()
  88.     fillStone()
  89.     os.sleep(5)
  90. end
Add Comment
Please, Sign In to add comment