dcchill

Untitled

May 10th, 2023
5
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. -- Configurations
  2. local CHEST_CAPACITY = 27 -- Number of slots in a chest
  3. local MAX_CHESTS = 64 -- Maximum number of chests to manage
  4.  
  5. -- Peripheral Wrapping
  6. local function findChests()
  7. local chests = {}
  8. for _, side in ipairs(rs.getSides()) do
  9. if peripheral.isPresent(side) and peripheral.getType(side) == "minecraft:chest" then
  10. table.insert(chests, peripheral.wrap(side))
  11. end
  12. end
  13. return chests
  14. end
  15.  
  16. -- Inventory Management
  17. local function findEmptySlot()
  18. for slot = 1, 16 do
  19. if turtle.getItemCount(slot) == 0 then
  20. return slot
  21. end
  22. end
  23. return nil
  24. end
  25.  
  26. local function emptyInventoryToChest(chest)
  27. for slot = 1, 16 do
  28. turtle.select(slot)
  29. turtle.drop()
  30. end
  31. chest.pullItems(rs.getNameID(), nil, 64)
  32. end
  33.  
  34. -- Pathfinding
  35. local function moveToNextChest(chests)
  36. for i = 1, #chests do
  37. local chest = chests[i]
  38. if chest.getItemCount() < CHEST_CAPACITY then
  39. return i
  40. end
  41. end
  42. return nil
  43. end
  44.  
  45. -- Main Program
  46. local function main()
  47. local chests = findChests()
  48. while true do
  49. local nextChestIndex = moveToNextChest(chests)
  50. if nextChestIndex then
  51. local chest = chests[nextChestIndex]
  52. local emptySlot = findEmptySlot()
  53. if emptySlot then
  54. turtle.select(emptySlot)
  55. emptyInventoryToChest(chest)
  56. else
  57. print("No empty slots available.")
  58. -- You can add logic here to expand your storage system.
  59. -- For example, you could add another turtle or use additional inventory management techniques.
  60. return
  61. end
  62. else
  63. print("No available chests for storage.")
  64. -- You can add logic here to expand your storage system.
  65. -- For example, you could add another turtle or use additional inventory management techniques.
  66. return
  67. end
  68. end
  69. end
  70.  
  71. main()
  72.  
Add Comment
Please, Sign In to add comment