DevNatan / inventory-framework

Minecraft Inventory API framework
MIT License
127 stars 22 forks source link

ArrayIndexOutOfBoundsException when setting an item on the 27th slot in a 3-row container. #681

Closed 2lay closed 3 weeks ago

2lay commented 2 months ago

Is there an existing issue for this?

🐛 Describe the bug

Plugin throws an ArrayIndexOutOfBoundsException error when trying to set an item on the 27'th / last slot.

Stack Trace:

[20:54:49 ERROR]: [CommandAPI] Unhandled exception executing '/opengold'
java.lang.ArrayIndexOutOfBoundsException: Index 27 out of bounds for length 27
        at java.base/java.util.Arrays$ArrayList.set(Arrays.java:4271) ~[?:?]
        at net.minecraft.core.NonNullList.set(NonNullList.java:50) ~[paper-1.21.1.jar:1.21.1-98-9b1ee0d]
        ...

✔️ Expected behavior

GUI is supposed to open and show an item on the 27'th / last slot.

👣 Steps to Reproduce

  1. Create a Container.
  2. Set an item to the 27 using render.slot or render.lastSlot method.
  3. GUI doesn't open and throws an ArrayIndexOutOfBoundsException error.

💻 Platform

⭐ Server Version

1.21.1

📚 Library Version

3.0.11

✍️ Additional context

No response

nicolube commented 1 month ago

@2lay Did u put it on index 27? Indexing starts at 0 so the 27th slot would be position 26...

2lay commented 1 month ago

No, I am using render.lastSlot, or setting it to the 26'th slot.

DevNatan commented 3 weeks ago

@2lay I'm not being able to reproduce. Both slot(26, [...]) (slot(27) will fail) and lastSlot([...]) with config.size(3) or config.size(27) on container config works fine.

onRender's context slot(x) is index-based so I recommend you to check container size before adding it otherwise it will throw an exception. You can use render.getContainer() to access container settings.