Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("back")
- local turtleName = modem.getNameLocal()
- local inventory = peripheral.find("minecraft:barrel")
- local frontInventory = peripheral.find("powah:energizing_orb") -- Change to the correct inventory type if needed
- -- Display a helpful message in French
- print("Cette tortue est conçue pour faciliter l'alimentation automatique de l'orbe énergisante.")
- print("Instructions d'utilisation :")
- print("- Assurez-vous que la tortue est alimentée par un signal redstone.")
- print("- Placez les éléments requis pour la recette dans l'inv de la tortue.")
- print("- Les items seront transférés dans l'orbe.")
- print("- Input & output dans le barrel au dessus")
- print("")
- -- Function to check if the slot has items
- local function hasItems(slot)
- turtle.select(slot)
- return turtle.getItemCount(slot) > 0
- end
- -- Function to check if any redstone signal is detected
- local function isRedstonePowered()
- return redstone.getInput("front") or
- redstone.getInput("back") or
- redstone.getInput("left") or
- redstone.getInput("right") or
- redstone.getInput("top") or
- redstone.getInput("bottom")
- end
- -- Function to check if the front inventory has items
- local function isFrontInventoryEmpty()
- if frontInventory then
- local items = frontInventory.list()
- for _, item in pairs(items) do
- if item then
- return false -- Inventory is not empty
- end
- end
- end
- return true -- Inventory is empty or not found
- end
- -- Function to refill a slot with the correct item from the upper inventory
- local function refillSlot(slot)
- turtle.select(slot)
- local itemDetail = turtle.getItemDetail(slot)
- if itemDetail and turtle.getItemCount(slot) < 10 then
- -- Search the inventory for matching items
- for i, item in ipairs(inventory.list()) do
- if item.name == itemDetail.name then
- local amountNeeded = 64 - turtle.getItemCount(slot)
- if amountNeeded > 0 then
- -- Push items from the upper inventory to the turtle's current slot
- inventory.pushItems(turtleName, i, amountNeeded, slot)
- break
- end
- end
- end
- end
- end
- -- Function to loop through inventory slots, refill them, and drop one item below
- local function manageInventoryAndDrop()
- for slot = 1, 16 do
- if hasItems(slot) then
- refillSlot(slot) -- Refill the slot if needed
- turtle.select(slot)
- turtle.drop(1) -- Drop one item
- end
- end
- end
- -- Main loop
- while true do
- if not inventory then
- print("Inventaire non détecté.")
- exit()
- else
- -- Check if the inventory in front is empty before calling manageInventoryAndDrop
- if isRedstonePowered() and isFrontInventoryEmpty() then
- manageInventoryAndDrop()
- end
- sleep(2) -- Wait for 2 seconds
- end
- end
Add Comment
Please, Sign In to add comment