Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- enchantTurtle.lua
- -- Wrap the input chest in front
- local frontChest = peripheral.wrap("front")
- if not frontChest then
- error("❌ No chest detected in front of the turtle")
- end
- -- Helper to test if the chest is empty
- local function isChestEmpty(chest)
- -- chest.list() returns a sparse table of slots → items
- return next(chest.list()) == nil
- end
- -- Main sorting loop
- while not isChestEmpty(frontChest) do
- -- Always work in turtle slot 1
- turtle.select(1)
- -- Grab exactly one item from the chest in front
- -- (succeeds only if there was at least one)
- if not turtle.suck(1) then
- -- nothing left?
- break
- end
- -- Inspect what we just pulled
- local tDetail = turtle.getItemDetail(1)
- if tDetail and tDetail.enchantments and #tDetail.enchantments > 0 then
- -- Enchanted → drop up
- if not turtle.dropUp() then
- error("Could not drop enchanted item above!")
- end
- print(("🔼 Enchanted: %s ×1"):format(tDetail.name))
- else
- -- Unenchanted → drop down
- if not turtle.dropDown() then
- error("Could not drop normal item below!")
- end
- print(("🔽 Normal: %s ×1"):format(tDetail and tDetail.name or "<unknown>"))
- end
- end
- print("✅ All items sorted.")
Add Comment
Please, Sign In to add comment