Class WrapperBlockStateModel

java.lang.Object
net.fabricmc.fabric.api.client.model.loading.v1.wrapper.WrapperBlockStateModel
All Implemented Interfaces:
FabricBlockStateModel, net.minecraft.client.renderer.block.dispatch.BlockStateModel

public abstract class WrapperBlockStateModel extends Object implements net.minecraft.client.renderer.block.dispatch.BlockStateModel
A simple implementation of BlockStateModel that delegates all method calls to the wrapped field. Implementations must set the wrapped field somehow.
  • Nested Class Summary

    Nested classes/interfaces inherited from interface net.minecraft.client.renderer.block.dispatch.BlockStateModel

    net.minecraft.client.renderer.block.dispatch.BlockStateModel.SimpleCachedUnbakedRoot, net.minecraft.client.renderer.block.dispatch.BlockStateModel.Unbaked, net.minecraft.client.renderer.block.dispatch.BlockStateModel.UnbakedRoot
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected net.minecraft.client.renderer.block.dispatch.BlockStateModel
     
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    protected
     
    protected
    WrapperBlockStateModel(net.minecraft.client.renderer.block.dispatch.BlockStateModel wrapped)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    collectParts(net.minecraft.util.RandomSource random, List<net.minecraft.client.renderer.block.dispatch.BlockStateModelPart> parts)
     
    @Nullable Object
    createGeometryKey(net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.util.RandomSource random)
    Creates a geometry key using the given context.
    void
    emitQuads(QuadEmitter emitter, net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.util.RandomSource random, Predicate<@Nullable net.minecraft.core.Direction> cullTest)
    Produces this model's geometry.
    boolean
    hasMaterialFlag(int flag)
     
    boolean
    hasMaterialFlag(net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.util.RandomSource random, int flag)
    Extension of BlockStateModel.hasMaterialFlag(int) that accepts level state.
    int
     
    int
    materialFlags(net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.util.RandomSource random)
    Extension of BlockStateModel.materialFlags() that accepts level state.
    net.minecraft.client.resources.model.sprite.Material.Baked
     
    net.minecraft.client.resources.model.sprite.Material.Baked
    particleMaterial(net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
    Extension of BlockStateModel.particleMaterial() that accepts level state.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • wrapped

      protected net.minecraft.client.renderer.block.dispatch.BlockStateModel wrapped
  • Constructor Details

    • WrapperBlockStateModel

      protected WrapperBlockStateModel()
    • WrapperBlockStateModel

      protected WrapperBlockStateModel(net.minecraft.client.renderer.block.dispatch.BlockStateModel wrapped)
  • Method Details

    • collectParts

      public void collectParts(net.minecraft.util.RandomSource random, List<net.minecraft.client.renderer.block.dispatch.BlockStateModelPart> parts)
      Specified by:
      collectParts in interface net.minecraft.client.renderer.block.dispatch.BlockStateModel
    • particleMaterial

      public net.minecraft.client.resources.model.sprite.Material.Baked particleMaterial()
      Specified by:
      particleMaterial in interface net.minecraft.client.renderer.block.dispatch.BlockStateModel
    • materialFlags

      public int materialFlags()
      Specified by:
      materialFlags in interface net.minecraft.client.renderer.block.dispatch.BlockStateModel
    • hasMaterialFlag

      public boolean hasMaterialFlag(int flag)
      Specified by:
      hasMaterialFlag in interface net.minecraft.client.renderer.block.dispatch.BlockStateModel
    • emitQuads

      public void emitQuads(QuadEmitter emitter, net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.util.RandomSource random, Predicate<@Nullable net.minecraft.core.Direction> cullTest)
      Description copied from interface: FabricBlockStateModel
      Produces this model's geometry. This method must be called instead of BlockStateModel.collectParts(RandomSource, List); the vanilla method should be considered deprecated as it may not produce accurate results. However, it is acceptable for a custom model to only implement the vanilla method as the default implementation of this method will delegate to it.

      Like BlockStateModel.collectParts(RandomSource, List), this method may be called outside of chunk rebuilds. For example, some entities and block entities render blocks. In some such cases, the provided position may be the nearest position and not actual position. In others, the provided level may be empty.

      If multiple independent subtasks use the provided random, it is recommended that implementations reseed the random using a predetermined value before invoking each subtask, so that one subtask's operations do not affect subsequent subtasks. For example, if a model collects geometry from multiple submodels, each submodel is considered a subtask and thus the random should be reseeded before collecting geometry from each submodel. See MultiPartModel.collectParts(RandomSource, List) for an example implementation of this.

      Implementations should rely on pre-baked meshes as much as possible and keep dynamic transformations to a minimum for performance.

      Implementations should generally also override FabricBlockStateModel.createGeometryKey(BlockAndTintGetter, BlockPos, BlockState, RandomSource).

      Specified by:
      emitQuads in interface FabricBlockStateModel
      Parameters:
      emitter - Accepts model output.
      level - Access to level state.
      pos - Position of block for model being rendered.
      state - Block state whose model was queried for geometry. This is not guaranteed to be the state corresponding to this model!
      random - Random object seeded per vanilla conventions. Do not cache or retain a reference.
      cullTest - A test that returns true for faces which will be culled and false for faces which may or may not be culled. Meant to be used to cull groups of quads or expensive dynamic quads early for performance. Early culled quads will likely not be added the emitter, so callers of this method must account for this. In general, prefer using MutableQuadView.cullFace(Direction) instead of this test.
      See Also:
    • createGeometryKey

      public @Nullable Object createGeometryKey(net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.util.RandomSource random)
      Description copied from interface: FabricBlockStateModel
      Creates a geometry key using the given context. A geometry key represents the exact geometry output from FabricBlockStateModel.emitQuads(QuadEmitter, BlockAndTintGetter, BlockPos, BlockState, RandomSource, Predicate) when given the same parameters as this method and a cull test that always returns false. Geometry keys are intended to be used in a cache to avoid recomputing expensive transformations applied to a certain model's geometry.

      The geometry key must implement Object.equals(Object) and Object.hashCode(). The geometry key may be compared to the geometry key of any other model, not just those produced by this model instance, so care should be taken when selecting the type of the key. Generally, one class of model will want to make its own record class to use for geometry keys.

      A null key means that a geometry key does not exist for specifically the given context; a key may exist for a different context. It is always possible to create a key for any context, but some custom models may choose not to if doing so is too complex. Vanilla models correctly implement this method, but may return null when delegating to a submodel that returns null.

      Specified by:
      createGeometryKey in interface FabricBlockStateModel
      Parameters:
      level - The level in which the block exists.
      pos - The position of the block in the level.
      state - The block state whose model was queried for a geometry key. This is not guaranteed to be the state corresponding to this model!
      random - Random object seeded per vanilla conventions.
      Returns:
      the geometry key, or null if one does not exist for the given context
      See Also:
    • particleMaterial

      public net.minecraft.client.resources.model.sprite.Material.Baked particleMaterial(net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state)
      Description copied from interface: FabricBlockStateModel
      Extension of BlockStateModel.particleMaterial() that accepts level state. This method will be invoked most of the time, but the vanilla method may still be invoked when no level context is available.

      If your model delegates to other BlockStateModels, ensure that it also delegates invocations of this method to its submodels as appropriate!

      Specified by:
      particleMaterial in interface FabricBlockStateModel
      Parameters:
      level - The level in which the block exists.
      pos - The position of the block in the level.
      state - The block state whose model was queried for the particle material. This is not guaranteed to be the state corresponding to this model!
      Returns:
      the particle material
    • materialFlags

      public int materialFlags(net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.util.RandomSource random)
      Description copied from interface: FabricBlockStateModel
      Extension of BlockStateModel.materialFlags() that accepts level state. This method will be invoked most of the time, but the vanilla method may still be invoked when no level context is available. Alternatively, this method may not be invoked at all; see the rest of this documentation for more details.

      If your model delegates to other BlockStateModels, ensure that it also delegates invocations of this method to its submodels as appropriate!

      This method exists solely for performance of dynamic models. It is acceptable and sometimes desirable for material flags to be "generalized"; in other words, it is functionally correct for a model to report that it has translucent or animated geometry even when it does not. It is up to the implementor of the model to decide how much the model should generalize its flags. This decision is primarily informed by how dynamic the model is and how often it is expected to be rendered. More generalized flags are cheaper to compute and use less context, but are less accurate, which can result in performance loss elsewhere in the rendering pipeline. As BlockStateModel.materialFlags() does not receive any context, it must return the most generalized flags, which must be functionally correct in all possible level contexts.

      The result of this method is inherently tied to the result of FabricBlockStateModel.emitQuads(QuadEmitter, BlockAndTintGetter, BlockPos, BlockState, RandomSource, Predicate). It is required that, for some level context and an arbitrary cull test, applying ModelHelper.computeMaterialFlags(QuadView) to every quad output by FabricBlockStateModel.emitQuads(QuadEmitter, BlockAndTintGetter, BlockPos, BlockState, RandomSource, Predicate) must produce flags that are at least as accurate as the result of this method. In other words, code that uses this model may, for performance reasons, inspect the geometry output and compute the material flags from it instead of calling this method, and this model must account for that.

      Specified by:
      materialFlags in interface FabricBlockStateModel
      Parameters:
      level - The level in which the block exists.
      pos - The position of the block in the level.
      state - The block state whose model was queried for the particle material. This is not guaranteed to be the state corresponding to this model!
      random - The random object seeded per vanilla conventions.
      Returns:
      the material flags
    • hasMaterialFlag

      public boolean hasMaterialFlag(net.minecraft.client.renderer.block.BlockAndTintGetter level, net.minecraft.core.BlockPos pos, net.minecraft.world.level.block.state.BlockState state, net.minecraft.util.RandomSource random, int flag)
      Description copied from interface: FabricBlockStateModel
      Extension of BlockStateModel.hasMaterialFlag(int) that accepts level state. This method will be invoked most of the time, but the vanilla method may still be invoked when no level context is available. Alternatively, this method may not be invoked at all; see the rest of this documentation for more details.

      If you need to check this model's flags more than once in some context, call FabricBlockStateModel.materialFlags(BlockAndTintGetter, BlockPos, BlockState, RandomSource) manually instead and perform the checks manually to avoid recomputing the flags for each check, which can be computationally expensive.

      This method should generally not be overridden.

      Specified by:
      hasMaterialFlag in interface FabricBlockStateModel
      Parameters:
      level - The level in which the block exists.
      pos - The position of the block in the level.
      state - The block state whose model was queried for the particle material. This is not guaranteed to be the state corresponding to this model!
      random - The random object seeded per vanilla conventions.
      flag - The flag mask to check against.
      Returns:
      whether this model has the given material flag
      See Also: