Interface FabricBlockView
BlockView
subclasses.
These extensions were designed primarily for use by methods invoked during chunk building, but they can also be used in other contexts.
Note: This interface is automatically implemented on all BlockView
instances via Mixin and interface injection.
-
Method Summary
Modifier and TypeMethodDescriptiondefault @UnknownNullability RegistryEntry
<Biome> getBiomeFabric
(BlockPos pos) Retrieves the biome at the given position if biome retrieval is supported.default @Nullable Object
Retrieves block entity render data for a given block position.default boolean
Checks whether biome retrieval is supported.
-
Method Details
-
getBlockEntityRenderData
Retrieves block entity render data for a given block position.This method must be used instead of
BlockView.getBlockEntity(BlockPos)
in cases where the user knows that the current context may be multithreaded, such as chunk building, to ensure thread safety and data consistency. Using aBlockEntity
directly may not be thread-safe since it may lead to non-atomic modification of the internal state of theBlockEntity
(such as through lazy computation). Using aBlockEntity
directly may not be consistent since the internal state of theBlockEntity
may change on a different thread.As previously stated, a common environment to use this method in is chunk building. Methods that are invoked during chunk building and that thus should use this method include, but are not limited to,
FabricBakedModel#emitBlockQuads
(block models),BlockColorProvider#getColor
(block color providers), andFabricBlock#getAppearance
(block appearance computation).Users of this method are required to check the returned object before using it. Users must check if it is null and if it is of the correct type to avoid null pointer and class cast exceptions, as the returned data is not guaranteed to be what the user expects. A simple way to implement these checks is to use
instanceof
, since it always returnsfalse
if the object is null. If theinstanceof
returnsfalse
, a fallback path should be used.- Parameters:
pos
- the position of the block entity- Returns:
- the render data provided by the block entity, or null if there is no block entity at this position
- See Also:
-
hasBiomes
default boolean hasBiomes()Checks whether biome retrieval is supported. The returned value will not change between multiple calls of this method. SeegetBiomeFabric(BlockPos)
for more information.- Returns:
- whether biome retrieval is supported
- See Also:
-
getBiomeFabric
Retrieves the biome at the given position if biome retrieval is supported. IfhasBiomes()
returnstrue
, this method will always return a non-nullRegistryEntry
whosevalue
is non-null. IfhasBiomes()
returnsfalse
, this method will always returnnull
.Prefer using
WorldView.getBiome(BlockPos)
instead of this method if this instance is known to implementWorldView
.- Parameters:
pos
- the position for which to retrieve the biome- Returns:
- the biome, or null if biome retrieval is not supported
- See Also:
- Implementation Note:
- Implementations which do not return null are encouraged to use the plains biome as the default value, for example when the biome at the given position is unknown.
-