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 Type
    Method
    Description
    default @Nullable BakedModel
    Return the wrapped model, if there is one at the moment, or null otherwise.
    static BakedModel
    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

      @Nullable default @Nullable BakedModel getWrappedModel()
      Return the wrapped model, if there is one at the moment, or null otherwise.

      If there are multiple layers of wrapping, this method does not necessarily return the innermost model.

    • unwrap

      @Nullable 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. 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

      static BakedModel unwrap(BakedModel model)
      Fully unwrap a model, i.e. return the innermost model.