Model Unwrapping API
PepperCode1 opened this issue ยท 0 comments
Some existing mods like Continuity wrap BakedModel
s to achieve effects like connected and emissive textures on models that the mod itself did not add. Some other mods need to access the root model that is not wrapped and is of a known class. Continuity and likely others use ForwardingBakedModel
to wrap models, but this class does not have a getter for the base model. An example of a mod that needs to access the root model is Modern Industrialization, which at the moment uses reflection to access ForwardingBakedModel
's internal field.
Furthermore, with the changes of 1.19.3 comes a vanilla refactor that requires Continuity to wrap every single BakedModel
instead of only a select few. This raises compatibility concerns, but a model unwrapping API can solve these. My original thought was to add the API to Continuity, but having it standardized like the facade API would be much easier to use.
My current idea of how this API would work is an interface such as
public interface WrappedBakedModel {
BakedModel unwrap();
default BakedModel getRootModel() {
BakedModel model = this;
while (model instanceof WrappedBakedModel wrapped) {
model = wrapped.unwrap();
}
return model;
}
}
ForwardingBakedModel
can implement this interface if needed, but using ForwardingBakedModel
instead of an interface as the API directly seems like a bad idea because multiple inheritance is not possible in Java.