Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- pastebin get 180C8NRw TakeItem
- local function suckSpecificItem(itemName, count)
- local chest = peripheral.wrap("front")
- if not chest or not chest.list then
- print("Keine Kiste vor der Turtle erkannt.")
- return false
- end
- local chestItems = chest.list()
- local foundSlots = {}
- local totalAvailable = 0
- -- 1. Scanne Kiste nach dem gewünschten Item
- for slot, item in pairs(chestItems) do
- if item.name == itemName then
- table.insert(foundSlots, {slot = slot, count = item.count})
- totalAvailable = totalAvailable + item.count
- end
- end
- if totalAvailable < count then
- print("Nicht genügend Items gefunden.")
- return false
- end
- -- 2. Finde freien Slot in der Turtle für gecachtes Item
- local cachedItemSlot = nil
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- cachedItemSlot = i
- break
- end
- end
- if not cachedItemSlot then
- print("Kein freier Slot zum Zwischenspeichern des Kisten-Items.")
- return false
- end
- turtle.select(cachedItemSlot)
- local cachedItem = nil
- local list = chest.list()
- if list[1] and list[1].name ~= itemName then
- if turtle.suck(64) then
- cachedItem = turtle.getItemDetail(cachedItemSlot)
- end
- end
- -- 3. Erstes gewünschtes Item in Slot 1 schieben
- local nextSlotIndex = 1
- if not chest.getItemDetail(1) then
- local nextSource = foundSlots[nextSlotIndex]
- chest.pushItems("front", nextSource.slot, nextSource.count, 1)
- nextSlotIndex = nextSlotIndex + 1
- elseif (chest.getItemDetail(1) and chest.getItemDetail(1).name == itemName) then
- nextSlotIndex = nextSlotIndex + 1
- end
- -- 4. Gecachtes Item zurückgeben
- if cachedItem then
- turtle.select(cachedItemSlot)
- turtle.drop() -- Kiste verteilt es automatisch auf einen freien Slot ≠ 1
- end
- -- 5. Zielitems absaugen
- local collected = 0
- turtle.select(cachedItemSlot) -- Wiederverwenden für Einsammeln
- while collected < count do
- local remaining = count - collected
- local slot1Item = chest.getItemDetail(1)
- local pullCount = math.min(slot1Item.count, remaining)
- if turtle.suck(pullCount) then
- collected = collected + pullCount
- end
- if collected < count and nextSlotIndex <= #foundSlots then
- local nextSource = foundSlots[nextSlotIndex]
- chest.pushItems("front", nextSource.slot, nextSource.count, 1)
- nextSlotIndex = nextSlotIndex + 1
- end
- end
- return true
- end
- suckSpecificItem("minecraft:chest", 200)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement