Advertisement
Wassaa

pushtest

Jun 25th, 2025 (edited)
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- pushTest.lua
  2.  
  3. -- 1) Find all adjacent chests
  4. local chests = { peripheral.find("minecraft:chest") }
  5. if #chests < 2 then
  6.   print("❌ Need at least two chests attached to test pushItems")
  7.   return
  8. end
  9.  
  10. -- 2) Pick the first two
  11. local chestA = chests[1]
  12. local chestB = chests[2]
  13. local nameA  = peripheral.getName(chestA)
  14. local nameB  = peripheral.getName(chestB)
  15. print(("Testing push from %q → %q"):format(nameA, nameB))
  16.  
  17. -- 3) Verify pushItems exists
  18. local methodsA = peripheral.getMethods(nameA)
  19. local hasPush = false
  20. for _, m in ipairs(methodsA) do
  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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement