Primal Magick

Primal Magick

459k Downloads

Missing null check in TileEntity.getCapability() casuing NPE with some other mods

shBLOCK opened this issue ยท 0 comments

commented

@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction face) {
if (!this.remove && cap == ForgeCapabilities.ITEM_HANDLER) {
if (this.getInventoryIndexForFace(face).isPresent()) {
return this.itemHandlerOpts.get(this.getInventoryIndexForFace(face).getAsInt()).cast();
} else {
return LazyOptional.empty();
}
} else {
return super.getCapability(cap, face);
}
}

Here the 2nd parameter (face) is nullable, causing an NPE in the getInventoryIndexForFace() method when used with other mods.

Here's one example of the crash with the MultiStorage mod (I only kept the useful part of the log):

java.lang.NullPointerException: Cannot invoke "net.minecraft.core.Direction.ordinal()" because "face" is null
	at com.verdantartifice.primalmagick.common.tiles.devices.ResearchTableTileEntity.getInventoryIndexForFace(ResearchTableTileEntity.java:64) ~[primalmagick-4.0.9.jar%231141!/:4.0.9] {re:classloading,pl:rei_plugin_compatibilities:B}
	at com.verdantartifice.primalmagick.common.tiles.base.AbstractTileSidedInventoryPM.getCapability(AbstractTileSidedInventoryPM.java:109) ~[primalmagick-4.0.9.jar%231141!/:4.0.9] {re:classloading,pl:rei_plugin_compatibilities:B}
	at shetiphian.multistorage.common.misc.InventoryWatcher.getInventory(InventoryWatcher.java:26) ~[multistorage-forge-1.20.1-1.0.jar%231086!/:forge-1.20.1-1.0] {re:mixin,re:classloading,pl:rei_plugin_compatibilities:B}
	at shetiphian.multistorage.common.misc.InventoryWatcher.isInventory(InventoryWatcher.java:21) ~[multistorage-forge-1.20.1-1.0.jar%231086!/:forge-1.20.1-1.0] {re:mixin,re:classloading,pl:rei_plugin_compatibilities:B}
	at net.minecraft.world.level.Level.handler$djd000$multistorage_changeTracker_save(Level.java:11538) ~[server-1.20.1-20230612.114412-srg.jar%231315!/:?]