Fabric API

Fabric API

111M Downloads

Transfer API WaterPotionStorage#isWaterPotion() needs to check for empty components

Closed this issue ยท 0 comments

commented

net.minecraft.component.ComponentChanges#get() returns a Nullable Optional<T> value.

private static boolean isWaterPotion(ContainerItemContext context) {
ItemVariant variant = context.getItemVariant();
Optional<? extends PotionContentsComponent> potionContents = variant.getComponents().get(DataComponentTypes.POTION_CONTENTS);
RegistryEntry<Potion> potion = potionContents.map(PotionContentsComponent::potion).orElse(null).orElse(null);

Will cause a null pointer exception when the potionContents.map method is called

java.lang.NullPointerException: Cannot invoke "java.util.Optional.map(java.util.function.Function)" because "potionContents" is null
at knot//net.fabricmc.fabric.impl.transfer.fluid.WaterPotionStorage.isWaterPotion(WaterPotionStorage.java:56)
at knot//net.fabricmc.fabric.impl.transfer.fluid.WaterPotionStorage.find(WaterPotionStorage.java:50)
at knot//net.fabricmc.fabric.impl.transfer.fluid.CombinedProvidersImpl.lambda$createEvent$0(CombinedProvidersImpl.java:42)
at knot//net.fabricmc.fabric.impl.transfer.fluid.CombinedProvidersImpl$Provider.find(CombinedProvidersImpl.java:80)
at knot//net.fabricmc.fabric.impl.transfer.fluid.CombinedProvidersImpl$Provider.find(CombinedProvidersImpl.java:65)
at knot//net.fabricmc.fabric.impl.lookup.item.ItemApiLookupImpl.find(ItemApiLookupImpl.java:67)
at knot//me.shedaniel.rei.impl.common.compat.FabricFluidAPISupportPlugin.lambda$registerFluidSupport$2(FabricFluidAPISupportPlugin.java:48)