-
Notifications
You must be signed in to change notification settings - Fork 111
Server Registry Stuff #1085
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
base: main
Are you sure you want to change the base?
Server Registry Stuff #1085
Conversation
| var registry = cx.lookupRegistry(param, from); | ||
|
|
||
| if (from instanceof Holder<?> h) { | ||
| return Holder.Reference.createStandAlone(Cast.to(registry.holderOwner()), h.getKey()); |
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 createStandAlone guaranteed to be safe?
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.
In what context? When serializing with a registry present (the intent & use case I have), yes. For retrieving a value/id from the registry itself (or the holder even), no
| static Holder.Reference<?> wrapRef(KubeJSContext cx, Object from, TypeInfo param) { | ||
| if (from instanceof Holder.Reference<?> h) { | ||
| return h; | ||
| } else if (from == null) { | ||
| throw Context.reportRuntimeError("Can't interpret 'null' as a holder", cx); | ||
| } | ||
|
|
||
| var registry = cx.lookupRegistry(param, from); | ||
|
|
||
| if (from instanceof Holder<?> h) { | ||
| return Holder.Reference.createStandAlone(Cast.to(registry.holderOwner()), h.getKey()); | ||
| } else if (!ID.isKey(from)) { | ||
| throw Context.reportRuntimeError("Can't interpret '" + from + "' as a reference holder", cx); | ||
| } | ||
|
|
||
| var id = ID.mc(from); | ||
| return Holder.Reference.createStandAlone(Cast.to(registry.holderOwner()), ResourceKey.create(registry.key(), id)); | ||
| } | ||
|
|
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.
Actually, more general question, is there any time where we shouldn't just be using the regular wrap() method and then convert that (either cast or retrieve delegate) to a reference holder?
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.
The only time a holder's delegate would be a reference holder is reference holders themselves and bound deferred holders, and the latter has problems due to only being bound if the registry has the id registered and the actual registry either being non-existent or frozen.
But wrapping as a holder and simply using its key if present should work the same (possibly more?) that what I currently have
Mind explaining / giving a brief example on why this is needed and why we specifically need to create a new RAC instance here? |
It is quite common for server registry objects to reference other objects via holders (placed features are literally a configured feature holder and a list of placement modifiers) and holder sets (TFC's forest feature; builder). Kube's wrappers for these two types requires the registry they're for to be present and the codecs will only serialize to the object/tag id if the registry is present in the Even if scriptors passed in a I tried to find a place where these registries existed and that was before datapacks were parsed, but there does not seem to be such a place. |
Makes some adjustments so dealing with
ServerEvents.registryis relatively nice.RegistryAccessContainerhas 'access' to non-static registries by making an empty registry on demand and providing that. This is needed for wrappingHolders andHolderSets of server registriesDeferredHolderwhich is typically made cannot serializeThese changes were tested locally against this commit