SHOW:
|
|
- or go back to the newest paste.
| 1 | - | -- listChests.lua |
| 1 | + | -- pushTest.lua |
| 2 | ||
| 3 | - | -- Get all peripheral names |
| 3 | + | -- 1) Find all adjacent chests |
| 4 | - | local names = { peripheral.find("minecraft:chest") }
|
| 4 | + | local chests = { peripheral.find("minecraft:chest") }
|
| 5 | if #chests < 2 then | |
| 6 | - | -- Filter for those matching "minecraft:chest" |
| 6 | + | print("❌ Need at least two chests attached to test pushItems")
|
| 7 | - | local chestNames = {}
|
| 7 | + | return |
| 8 | - | for _, peripheral in ipairs(names) do |
| 8 | + | |
| 9 | - | table.insert(chestNames, peripheral) |
| 9 | + | |
| 10 | -- 2) Pick the first two | |
| 11 | local chestA = chests[1] | |
| 12 | - | -- Print results |
| 12 | + | local chestB = chests[2] |
| 13 | - | if #chestNames == 0 then |
| 13 | + | local nameA = peripheral.getName(chestA) |
| 14 | - | print("â No peripherals found")
|
| 14 | + | local nameB = peripheral.getName(chestB) |
| 15 | print(("Testing push from %q → %q"):format(nameA, nameB))
| |
| 16 | - | print("ð Found the following peripherals")
|
| 16 | + | |
| 17 | - | for i, name in ipairs(chestNames) do |
| 17 | + | -- 3) Verify pushItems exists |
| 18 | - | print(string.format("%d) %s", i, name.size()))
|
| 18 | + | local methodsA = peripheral.getMethods(nameA) |
| 19 | - | end |
| 19 | + | local hasPush = false |
| 20 | for _, m in ipairs(methodsA) do | |
| 21 | - | |
| 21 | + | if m == "pushItems" then hasPush = true break end |
| 22 | end | |
| 23 | if not hasPush then | |
| 24 | print("⚠️ pushItems not supported on this chest peripheral.")
| |
| 25 | return | |
| 26 | end | |
| 27 | ||
| 28 | -- 4) Attempt to move one item from slot 1 | |
| 29 | -- This will throw an error if something’s wrong | |
| 30 | local moved = chestA.pushItems(nameB, 1, 1) | |
| 31 | if moved == 0 then | |
| 32 | print("ℹ️ pushItems succeeded but moved 0 items (slot 1 empty?)")
| |
| 33 | else | |
| 34 | print(("✅ pushItems moved %d item(s) from slot 1"):format(moved))
| |
| 35 | end |