From 02502d5148c636f5f3daf22981ee1b03f0f9cc98 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 14 Aug 2024 17:02:03 +0900 Subject: [PATCH 1/2] Fix potential NPE --- .../impl/client/fabric/CreativeModeTabCollectorImpl.java | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CreativeModeTabCollectorImpl.java b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CreativeModeTabCollectorImpl.java index a89dd979f..a24a34f42 100644 --- a/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CreativeModeTabCollectorImpl.java +++ b/fabric/src/main/java/me/shedaniel/rei/impl/client/fabric/CreativeModeTabCollectorImpl.java @@ -27,6 +27,7 @@ import me.shedaniel.rei.impl.common.InternalLogger; import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries; import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents; +import net.minecraft.core.RegistryAccess; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.world.flag.FeatureFlagSet; @@ -35,16 +36,13 @@ import net.minecraft.world.item.CreativeModeTabs; import net.minecraft.world.item.ItemStack; -import java.util.Collection; -import java.util.LinkedHashMap; -import java.util.LinkedList; -import java.util.Map; +import java.util.*; public class CreativeModeTabCollectorImpl { public static Map> collectTabs() { Map> map = new LinkedHashMap<>(); FeatureFlagSet featureFlags = FeatureFlags.REGISTRY.allFlags(); - CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, BasicDisplay.registryAccess()); + CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, Objects.requireNonNullElseGet(BasicDisplay.registryAccess(), () -> RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY))); for (CreativeModeTab tab : CreativeModeTabs.allTabs()) { if (tab.getType() != CreativeModeTab.Type.HOTBAR && tab.getType() != CreativeModeTab.Type.INVENTORY) { From 63cb335e2bf28df6fcbaa29cde3be33d8842ec03 Mon Sep 17 00:00:00 2001 From: shedaniel Date: Wed, 14 Aug 2024 17:02:50 +0900 Subject: [PATCH 2/2] Fix potential NPE --- .../rei/impl/client/forge/CreativeModeTabCollectorImpl.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java index 39f657bd0..9eb614780 100644 --- a/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java +++ b/forge/src/main/java/me/shedaniel/rei/impl/client/forge/CreativeModeTabCollectorImpl.java @@ -25,6 +25,7 @@ import me.shedaniel.rei.api.common.display.basic.BasicDisplay; import me.shedaniel.rei.impl.common.InternalLogger; +import net.minecraft.core.RegistryAccess; import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.resources.ResourceKey; import net.minecraft.world.flag.FeatureFlagSet; @@ -37,12 +38,13 @@ import java.util.Collection; import java.util.LinkedHashMap; import java.util.Map; +import java.util.Objects; public class CreativeModeTabCollectorImpl { public static Map> collectTabs() { Map> map = new LinkedHashMap<>(); FeatureFlagSet featureFlags = FeatureFlags.REGISTRY.allFlags(); - CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, BasicDisplay.registryAccess()); + CreativeModeTab.ItemDisplayParameters parameters = new CreativeModeTab.ItemDisplayParameters(featureFlags, true, Objects.requireNonNullElseGet(BasicDisplay.registryAccess(), () -> RegistryAccess.fromRegistryOfRegistries(BuiltInRegistries.REGISTRY))); for (CreativeModeTab tab : CreativeModeTabs.allTabs()) { if (tab.getType() != CreativeModeTab.Type.HOTBAR && tab.getType() != CreativeModeTab.Type.INVENTORY) {