Minecraft crashes when I open my GUI or when I access slots from procedures

Section

Did you just make your perfect GUI and wanted to test it out in Minecraft. You right click and the game crashes.

The crash log usually contains the following lines:

java.lang.ArrayIndexOutOfBoundsException: [some number]
    at java.util.Arrays$ArrayList.get(Arrays.java:3841)
    at net.minecraft.util.NonNullList.get(NonNullList.java:51)
    at mod.mcreator.mcreator_runeInfuser$TileEntityCustom.getStackInSlot(YOURGUI.java:177)
    at net.minecraft.inventory.Slot.getStack(Slot.java:81)
    at net.minecraft.inventory.Container.detectAndSendChanges(Container.java:97)
    at net.minecraft.entity.player.EntityPlayerMP.onUpdate(EntityPlayerMP.java:365)
    at net.minecraft.world.World.updateEntityWithOptionalForce(World.java:2171)
    at net.minecraft.world.WorldServer.updateEntityWithOptionalForce(WorldServer.java:871)
    at net.minecraft.world.World.updateEntity(World.java:2130)
    at net.minecraft.world.WorldServer.tickPlayers(WorldServer.java:672)
    at net.minecraft.world.World.updateEntities(World.java:1906)
    at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:643)
    at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:842)
    at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:743)
    at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:192)
    at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:592)
    at java.lang.Thread.run(Thread.java:748)

This happens when you want to access the slot of the block GUI is bound to that does not exist in the block.

If you set the inventory size of the block your GUI is bound to say 10, this means your block has 10 slots. This means that you can use slots from ID 0 to ID 9 (slot IDs start with 0). If you use slot bound to inherited inventory and use ID 10 in our case, you will get this kind of crash where [some number] will be 10.

Rule of thumb

If you want to make sure that your GUI does not crash, make sure to set the inventory size of the block you GUI is bound to at least for one number larger than the biggest ID of the slot in your GUI.

Accessing slots from procedures

The same rule applies when you try to access slots from GUI or block from a procedure. If you try to access a slot with the ID that does not exist or access block inventory slot with ID larger than inventorySize - 1, the game will crash.

Related Minecraft crashes

A similar crash can also be observed if you access a slot ID that is not defined. If your GUI has no slot with ID 3, but you access slot 3 in your procedure, the game will crash.

The crash log usually contains the following lines:

java.lang.ArrayIndexOutOfBoundsException: [some number]
    at java.util.Arrays$ArrayList.get(Arrays.java:3841)
    at net.minecraft.util.NonNullList.get(NonNullList.java:51)
    at mod.mcreator.mcreator_runeInfuser$TileEntityCustom.getStackInSlot(YOURGUI.java:177)

or

java.lang.NullPointerException: Cannot invoke "net.minecraft.world.inventory.Slot.getItem()" because the return value of "java.util.Map.get(Object)" is null

This can also happen if you call a procedure you made for one GUI on another GUI with fewer slots or slots that don't exist for this another GUI.



Donate to MCreator

By donating to developers you can speed up development, as with more resources, we can dedicate more time to MCreator. It is a free project made by developers working on it in their free time.