Interface UnwrappableBakedModel
public interface UnwrappableBakedModel
An interface to be implemented by models that wrap and replace another model, such as
WrapperBakedModel
.
This allows mods to access the wrapped model without having to know the exact type of the wrapper model.
If you need to access data stored in one of your BakedModel
subclasses,
and you would normally access the model by its identifier and then cast it:
call unwrap(BakedModel, Predicate)
on the model first, in case another
mod is wrapping your model to alter its rendering.
Note: This interface is automatically implemented on WrapperBakedModel
and subclasses via Mixin and
interface injection.
-
Method Summary
Modifier and TypeMethodDescriptiondefault @Nullable BakedModel
Return the wrapped model, if there is one at the moment, ornull
otherwise.static BakedModel
unwrap
(BakedModel model) Fully unwrap a model, i.e.static @Nullable BakedModel
unwrap
(BakedModel model, Predicate<BakedModel> condition) Iteratively unwrap the given model until the given condition returns true or all models in the hierarchy have been tested.
-
Method Details
-
getWrappedModel
Return the wrapped model, if there is one at the moment, ornull
otherwise.If there are multiple layers of wrapping, this method does not necessarily return the innermost model.
-
unwrap
Iteratively unwrap the given model until the given condition returns true or all models in the hierarchy have been tested. If no model passes the condition, null is returned.A good use of this method is to safely cast a model to an expected type, by passing
model -> model instanceof MyCustomBakedModel
as the condition. -
unwrap
Fully unwrap a model, i.e. return the innermost model.
-