-
-
Notifications
You must be signed in to change notification settings - Fork 179
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[1.20.x] Deprecate RegistryObject for removal #35
Conversation
src/main/java/net/minecraftforge/registries/RegistryObject.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/RegistryObject.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/RegistryObject.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/RegistryObject.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/RegistryObject.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredRegister.java
Outdated
Show resolved
Hide resolved
e61eb00
to
138d527
Compare
Suggestion: while this is still being discussed, can we mark this as a draft PR, please? Thanks. |
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
I could but I think we're past that point now :p |
src/main/java/net/minecraftforge/registries/RegistryBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
…ge changes, and revolve more around vanilla Holder types. Mentioned NeoForge Registry changes: neoforged/NeoForge#35 neoforged/NeoForge#37
Changes made, except for the one about the cast in
|
178f3f8
to
c21566b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couple more changes. I also still need to try and figure out/validate whether making all forge registries have a backing vanilla one causes compatibility issues when it comes to syncing, as I am not sure if vanilla will then try to sync all the things in BuiltInRegistries.REGISTRY
... And if it does:
a. There may be issues when using a client that doesn't have this PR on a server that does (or vice versa)
b. It would be syncing things that RegistryBuilder#disableSync
was used to try and disable
src/main/java/net/minecraftforge/registries/RegistryBuilder.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredHolder.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here are my thoughts.
src/main/java/net/minecraftforge/registries/DeferredRegister.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredRegister.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredRegister.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredRegister.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredRegister.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredRegister.java
Outdated
Show resolved
Hide resolved
src/main/java/net/minecraftforge/registries/DeferredRegister.java
Outdated
Show resolved
Hide resolved
8f3361e
to
1e2facb
Compare
DefReg docs updated, rebased to fix compat check that was failing due to #72 |
* @param name the name of the object to look up in the forge registry | ||
* @param registry the forge registry | ||
* @return a {@link RegistryObject} that stores the value of an object from the provided forge registry once it is ready | ||
*/ | ||
public static <T, U extends T> RegistryObject<U> create(final ResourceLocation name, IForgeRegistry<T> registry) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm assuming that most users of this API would be third parties, should they be directed to IForgeRegistry#getHolder?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On a related note, should IForgeRegistry#getHolder be updated to return a DeferredHolder/similar itself?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should they be directed to IForgeRegistry#getHolder
No, probably not, given that getHolder
defers to the vanilla registry, which is implemented as Optional.ofNullable(this.byKey.get(pKey))
. This operation requires that the object be registered before the Holder can be accessed (which is usually not the case at the time of creation of DH/RO's)
IForgeRegistry#getHolder be updated to return a DeferredHolder/similar itself
Since those methods are mostly bouncers to vanilla they will be gone after the upcoming refactor. There might be room to add an additional getDeferredHolder
method to IForgeRegistry
but it would just be a util that wraps create
.
* @param <T> The type of object being held by this DeferredHolder. | ||
*/ | ||
// TODO: (Breaking Change) - Add a second generic type for the base registry type | ||
public class DeferredHolder<T> implements Holder<T> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be one type for the registry and one type for the actual type. The Holder
should have the registry type.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshedding here, but I'd prefer DeferredHolder<TRegistry, TInstance extends TRegistry> implements Holder<TRegistry>
public static <R, T extends R> DeferredHolder<T> create(ResourceKey<? extends Registry<R>> registryKey, ResourceLocation valueName) | ||
{ | ||
return create(ResourceKey.create(registryKey, valueName)); | ||
} | ||
|
||
/** | ||
* Creates a new DeferredHolder targeting the value with the specified name in the specified registry. | ||
* | ||
* @param <T> The registry type. | ||
* @param registryName The name of the registry the target value is a member of. | ||
* @param valueName The name of the target value. | ||
*/ | ||
public static <T> DeferredHolder<T> create(ResourceLocation registryName, ResourceLocation valueName) | ||
{ | ||
return create(ResourceKey.createRegistryKey(registryName), valueName); | ||
} | ||
|
||
/** | ||
* Creates a new DeferredHolder targeting the specified value. | ||
* | ||
* @param <T> The type of the target value. | ||
* @param key The resource key of the target value. | ||
*/ | ||
public static <T> DeferredHolder<T> create(ResourceKey<? super T> key) | ||
{ | ||
return new DeferredHolder<>(key); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constructors will take an unbounded actual type, and I'm not a fan - it's easy to make a mistake. Maybe we make these methods protected. Otherwise we can also split DeferredHolder<R>
and SomeSubclass<R, T>
(R
referring to the registry type here).
* The currently cached value. | ||
*/ | ||
@Nullable | ||
protected Holder<T> holder = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is thread safety a potential concern here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No threading issue is possible here, since bind
will get the same value if called multiple times (setting this to null between), and there is no window in which holder
is no longer null but not the correct holder.
In other words, threading issues would happen in the middle of a call to bind. If one thread finishes bind before the other starts, you just fetch the holder multiple times and get the same value each time. If one thread makes it past line 141 then the other calls bind, it just gets bound again. Worst case scenario is two threads both throw on missing registry.
Superseded by #257, the registry rework PR. |
This PR performs the following goals as an initial transition to the vanilla registry system, in accordance with #37:
RegistryObject
implementHolder
.RegistryObject
for removal, as all uses can be replaced withHolder
.DeferredHolder
to replaces uses ofRegistryObject
not covered byHolder$Reference
.Due to method signatures,
DeferredRegister#register
must still return aRegistryObject
, but callers can switch the return type of the stored value toHolder
orDeferredHolder
.