mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Fix RegistryObject not working if created after registry events (#8383)
This commit is contained in:
1 parent
2765c0d8d9
commit
b25d9562f2
3 files changed
+74
-4
No files matched your search
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* Minecraft Forge
|
||||
* Copyright (c) 2016-2021.
|
||||
* Copyright (c) 2016-2022.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -76,8 +76,9 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
ObjectHolderRegistry.addHandler(pred ->
|
||||
{
|
||||
if (pred.test(registry.getRegistryName()))
|
||||
this.value = registry.containsKey(this.name) ? (T)registry.getValue(this.name) : null;
|
||||
this.updateReference((IForgeRegistry<? extends T>) registry);
|
||||
});
|
||||
this.updateReference(((IForgeRegistry<? extends T>) registry));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@@ -99,9 +100,15 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
throw new IllegalStateException("Unable to find registry for type " + baseType.getName() + " for mod \"" + modid + "\". Check the 'caused by' to see futher stack.", callerStack);
|
||||
}
|
||||
if (pred.test(registry.getRegistryName()))
|
||||
RegistryObject.this.value = registry.containsKey(RegistryObject.this.name) ? (T)registry.getValue(RegistryObject.this.name) : null;
|
||||
RegistryObject.this.updateReference((IForgeRegistry<? extends T>) registry);
|
||||
}
|
||||
});
|
||||
IForgeRegistry<V> registry = RegistryManager.ACTIVE.getRegistry(baseType);
|
||||
// allow registry to be null, this might be for a custom registry that does not exist yet
|
||||
if (registry != null)
|
||||
{
|
||||
this.updateReference(((IForgeRegistry<? extends T>) registry));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -117,9 +124,10 @@ public final class RegistryObject<T extends IForgeRegistryEntry<? super T>> impl
|
||||
return ret;
|
||||
}
|
||||
|
||||
@Deprecated(since = "1.18.1") // TODO: make package-private
|
||||
public void updateReference(IForgeRegistry<? extends T> registry)
|
||||
{
|
||||
this.value = registry.getValue(getId());
|
||||
this.value = registry.containsKey(this.name) ? registry.getValue(getId()) : null;
|
||||
}
|
||||
|
||||
public ResourceLocation getId()
|
||||
|
||||
Reference in new issue
Block a user