MrFinn

Untitled

Dec 1st, 2024 (edited)
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.03 KB | None | 0 0
  1. local modem = peripheral.wrap("back")
  2. local turtleName = modem.getNameLocal()
  3. local inventory = peripheral.find("minecraft:barrel")
  4. local frontInventory = peripheral.find("powah:energizing_orb") -- Change to the correct inventory type if needed
  5.  
  6. -- Display a helpful message in French
  7. print("Cette tortue est conçue pour faciliter l'alimentation automatique de l'orbe énergisante.")
  8. print("Instructions d'utilisation :")
  9. print("- Assurez-vous que la tortue est alimentée par un signal redstone.")
  10. print("- Placez les éléments requis pour la recette dans l'inv de la tortue.")
  11. print("- Les items seront transférés dans l'orbe.")
  12. print("- Input & output dans le barrel au dessus")
  13. print("")
  14.  
  15. -- Function to check if the slot has items
  16. local function hasItems(slot)
  17. turtle.select(slot)
  18. return turtle.getItemCount(slot) > 0
  19. end
  20.  
  21. -- Function to check if any redstone signal is detected
  22. local function isRedstonePowered()
  23. return redstone.getInput("front") or
  24. redstone.getInput("back") or
  25. redstone.getInput("left") or
  26. redstone.getInput("right") or
  27. redstone.getInput("top") or
  28. redstone.getInput("bottom")
  29. end
  30.  
  31. -- Function to check if the front inventory has items
  32. local function isFrontInventoryEmpty()
  33. if frontInventory then
  34. local items = frontInventory.list()
  35. for _, item in pairs(items) do
  36. if item then
  37. return false -- Inventory is not empty
  38. end
  39. end
  40. end
  41. return true -- Inventory is empty or not found
  42. end
  43.  
  44. -- Function to refill a slot with the correct item from the upper inventory
  45. local function refillSlot(slot)
  46. turtle.select(slot)
  47. local itemDetail = turtle.getItemDetail(slot)
  48. if itemDetail and turtle.getItemCount(slot) < 10 then
  49. -- Search the inventory for matching items
  50. for i, item in ipairs(inventory.list()) do
  51. if item.name == itemDetail.name then
  52. local amountNeeded = 64 - turtle.getItemCount(slot)
  53. if amountNeeded > 0 then
  54. -- Push items from the upper inventory to the turtle's current slot
  55. inventory.pushItems(turtleName, i, amountNeeded, slot)
  56. break
  57. end
  58. end
  59. end
  60. end
  61. end
  62.  
  63. -- Function to loop through inventory slots, refill them, and drop one item below
  64. local function manageInventoryAndDrop()
  65. for slot = 1, 16 do
  66. if hasItems(slot) then
  67. refillSlot(slot) -- Refill the slot if needed
  68. turtle.select(slot)
  69. turtle.drop(1) -- Drop one item
  70. end
  71. end
  72. end
  73.  
  74. -- Main loop
  75. while true do
  76. if not inventory then
  77. print("Inventaire non détecté.")
  78. exit()
  79. else
  80. -- Check if the inventory in front is empty before calling manageInventoryAndDrop
  81. if isRedstonePowered() and isFrontInventoryEmpty() then
  82. manageInventoryAndDrop()
  83. end
  84. sleep(2) -- Wait for 2 seconds
  85. end
  86. end
  87.  
Add Comment
Please, Sign In to add comment