Class ForwardingBakedModel

java.lang.Object
net.fabricmc.fabric.api.renderer.v1.model.ForwardingBakedModel
All Implemented Interfaces:
FabricBakedModel, WrapperBakedModel, BakedModel

public abstract class ForwardingBakedModel extends Object implements BakedModel, FabricBakedModel, WrapperBakedModel
Base class for specialized model implementations that need to wrap other baked models. Avoids boilerplate code for pass-through methods.
  • Field Details

    • wrapped

      protected BakedModel wrapped
      implementations must set this somehow.
  • Constructor Details

    • ForwardingBakedModel

      public ForwardingBakedModel()
  • Method Details

    • emitBlockQuads

      public void emitBlockQuads(BlockRenderView blockView, BlockState state, BlockPos pos, Supplier<Random> randomSupplier, RenderContext context)
      Description copied from interface: FabricBakedModel
      This method will be called during chunk rebuilds to generate both the static and dynamic portions of a block model when the model implements this interface and FabricBakedModel.isVanillaAdapter() returns false.

      During chunk rebuild, this method will always be called exactly one time per block position, irrespective of which or how many faces or block render layers are included in the model. Models must output all quads/meshes in a single pass.

      Also called to render block models outside of chunk rebuild or block entity rendering. Typically, this happens when the block is being rendered as an entity, not as a block placed in the world. Currently, this happens for falling blocks and blocks being pushed by a piston, but renderers should invoke this for all calls to BlockModelRenderer.render(BlockRenderView, BakedModel, BlockState, BlockPos, MatrixStack, VertexConsumer, boolean, Random, long, int) that occur outside of chunk rebuilds to allow for features added by mods, unless FabricBakedModel.isVanillaAdapter() returns true.

      Outside of chunk rebuilds, this method will be called every frame. Model implementations should rely on pre-baked meshes as much as possible and keep transformation to a minimum. The provided block position may be the nearest block position and not actual. For this reason, neighbor state lookups are best avoided or will require special handling. Block entity lookups are likely to fail and/or give meaningless results.

      In all cases, renderer will handle face occlusion and filter quads on faces obscured by neighboring blocks (if appropriate). Models only need to consider "sides" to the extent the model is driven by connection with neighbor blocks or other world state.

      Note: with BakedModel.getQuads(BlockState, net.minecraft.util.math.Direction, Random), the random parameter is normally initialized with the same seed prior to each face layer. Model authors should note this method is called only once per block, and call the provided Random supplier multiple times if re-seeding is necessary. For wrapped vanilla baked models, it will probably be easier to use RenderContext.fallbackConsumer() which handles re-seeding per face automatically.

      Specified by:
      emitBlockQuads in interface FabricBakedModel
      Parameters:
      blockView - Access to world state. Using RenderAttachedBlockView.getBlockEntityRenderAttachment(BlockPos) to retrieve block entity state unless thread safety can be guaranteed. param safeBlockEntityAccessor Thread-safe access to block entity data
      state - Block state for model being rendered.
      pos - Position of block for model being rendered.
      randomSupplier - Random object seeded per vanilla conventions. Call multiple times to re-seed. Will not be thread-safe. Do not cache or retain a reference.
      context - Accepts model output.
    • isVanillaAdapter

      public boolean isVanillaAdapter()
      Description copied from interface: FabricBakedModel
      When true, signals renderer this producer is implemented through BakedModel.getQuads(BlockState, net.minecraft.util.math.Direction, Random). Also means the model does not rely on any non-vanilla features. Allows the renderer to optimize or route vanilla models through the unmodified vanilla pipeline if desired.

      Fabric overrides to true for vanilla baked models. Enhanced models that use this API should return false, otherwise the API will not recognize the model.

      Specified by:
      isVanillaAdapter in interface FabricBakedModel
    • emitItemQuads

      public void emitItemQuads(ItemStack stack, Supplier<Random> randomSupplier, RenderContext context)
      Description copied from interface: FabricBakedModel
      This method will be called during item rendering to generate both the static and dynamic portions of an item model when the model implements this interface and FabricBakedModel.isVanillaAdapter() returns false.

      Vanilla item rendering is normally very limited. It ignores lightmaps, vertex colors, and vertex normals. Renderers are expected to implement enhanced features for item models. If a feature is impractical due to performance or other concerns, then the renderer must at least give acceptable visual results without the need for special case handling in model implementations.

      Calls to this method will generally happen on the main client thread but nothing prevents a mod or renderer from calling this method concurrently. Implementations should not mutate the ItemStack parameter, and best practice will be to make the method thread-safe.

      Implementing this method does NOT mitigate the need to implement a functional BakedModel.getOverrides() method, because this method will be called on the result of BakedModel.getOverrides(). However, that method can simply return the base model because the output from this method will be used for rendering.

      Renderer implementations should also use this method to obtain the quads used for item enchantment glint rendering. This means models can put geometric variation logic here, instead of returning every possible shape from BakedModel.getOverrides() as vanilla baked models.

      Specified by:
      emitItemQuads in interface FabricBakedModel
    • getQuads

      public List<BakedQuad> getQuads(BlockState blockState, Direction face, Random rand)
      Specified by:
      getQuads in interface BakedModel
    • useAmbientOcclusion

      public boolean useAmbientOcclusion()
      Specified by:
      useAmbientOcclusion in interface BakedModel
    • hasDepth

      public boolean hasDepth()
      Specified by:
      hasDepth in interface BakedModel
    • isBuiltin

      public boolean isBuiltin()
      Specified by:
      isBuiltin in interface BakedModel
    • getParticleSprite

      public Sprite getParticleSprite()
      Specified by:
      getParticleSprite in interface BakedModel
    • isSideLit

      public boolean isSideLit()
      Specified by:
      isSideLit in interface BakedModel
    • getTransformation

      public ModelTransformation getTransformation()
      Specified by:
      getTransformation in interface BakedModel
    • getOverrides

      public ModelOverrideList getOverrides()
      Specified by:
      getOverrides in interface BakedModel
    • getWrappedModel

      public BakedModel getWrappedModel()
      Description copied from interface: WrapperBakedModel
      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.

      Specified by:
      getWrappedModel in interface WrapperBakedModel