From a02bec7ebe07cb4d707eba513f7be66e81a37449 Mon Sep 17 00:00:00 2001 From: Ben Staddon Date: Thu, 15 Nov 2018 21:52:45 +0000 Subject: [PATCH] Fix some null returns from defaulted registries (#5235) --- src/main/java/net/minecraftforge/registries/ForgeRegistry.java | 3 ++- .../minecraftforge/registries/NamespacedDefaultedWrapper.java | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/minecraftforge/registries/ForgeRegistry.java b/src/main/java/net/minecraftforge/registries/ForgeRegistry.java index d764fe593..f38d1cb91 100644 --- a/src/main/java/net/minecraftforge/registries/ForgeRegistry.java +++ b/src/main/java/net/minecraftforge/registries/ForgeRegistry.java @@ -212,7 +212,8 @@ public class ForgeRegistry> implements IForgeRe @Override public ResourceLocation getKey(V value) { - return this.names.inverse().get(value); + ResourceLocation ret = this.names.inverse().get(value); + return ret == null ? this.defaultKey : ret; } @Override diff --git a/src/main/java/net/minecraftforge/registries/NamespacedDefaultedWrapper.java b/src/main/java/net/minecraftforge/registries/NamespacedDefaultedWrapper.java index 2f922a8f4..c1adb1485 100644 --- a/src/main/java/net/minecraftforge/registries/NamespacedDefaultedWrapper.java +++ b/src/main/java/net/minecraftforge/registries/NamespacedDefaultedWrapper.java @@ -124,7 +124,7 @@ class NamespacedDefaultedWrapper> extends Regis public V getRandom(Random random) { Collection values = this.delegate.getValues(); - return values.stream().skip(random.nextInt(values.size())).findFirst().orElse(null); + return values.stream().skip(random.nextInt(values.size())).findFirst().orElse(this.delegate.getDefault()); } @Override