Interface BlockApiCache<A, C extends @Nullable Object>

Type Parameters:
A - The type of the API.
C - The type of the additional context object.

@NonExtendable public interface BlockApiCache<A, C extends @Nullable Object>
A BlockApiLookup bound to a ServerLevel and a position, providing much faster API access. Refer to BlockApiLookup for example code.

This object caches the block entity at the target position, and the last used API provider, removing those queries. If a block entity is available or if the block state is passed as a parameter, the block state doesn't have to be looked up either.

See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A, C extends @Nullable Object>
    BlockApiCache<A,C>
    create(BlockApiLookup<A,C> lookup, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos)
    Create a new instance bound to the passed ServerLevel and position, and querying the same API as the passed lookup.
    default @Nullable A
    find(C context)
    Attempt to retrieve an API from a block in the level, using the level and the position passed at creation time.
    @Nullable A
    find(@Nullable net.minecraft.world.level.block.state.BlockState state, C context)
    Attempt to retrieve an API from a block in the level, using the level and the position passed at creation time.
    @Nullable net.minecraft.world.level.block.entity.BlockEntity
    Return the block entity at the target position of this lookup.
    net.minecraft.server.level.ServerLevel
    Return the level this cache is bound to.
    Return the lookup this cache is bound to.
    net.minecraft.core.BlockPos
    Return the position this cache is bound to.
  • Method Details

    • find

      default @Nullable A find(C context)
      Attempt to retrieve an API from a block in the level, using the level and the position passed at creation time.

      Note: If the block state is known, it is more efficient to use find(BlockState, Object).

      Parameters:
      context - Additional context for the query, defined by type parameter C.
      Returns:
      The retrieved API, or null if no API was found.
    • find

      @Nullable A find(@Nullable net.minecraft.world.level.block.state.BlockState state, C context)
      Attempt to retrieve an API from a block in the level, using the level and the position passed at creation time.
      Parameters:
      state - The block state at the target position, or null if unknown.
      context - Additional context for the query, defined by type parameter C.
      Returns:
      The retrieved API, or null if no API was found.
    • getBlockEntity

      @Nullable net.minecraft.world.level.block.entity.BlockEntity getBlockEntity()
      Return the block entity at the target position of this lookup.

      This is the most efficient way to query the block entity at the target position repeatedly: unless the block entity has been loaded or unloaded since the last query, the result will be cached.

    • getLookup

      BlockApiLookup<A,C> getLookup()
      Return the lookup this cache is bound to.
    • getLevel

      net.minecraft.server.level.ServerLevel getLevel()
      Return the level this cache is bound to.
    • getPos

      net.minecraft.core.BlockPos getPos()
      Return the position this cache is bound to.
    • create

      static <A, C extends @Nullable Object> BlockApiCache<A,C> create(BlockApiLookup<A,C> lookup, net.minecraft.server.level.ServerLevel level, net.minecraft.core.BlockPos pos)
      Create a new instance bound to the passed ServerLevel and position, and querying the same API as the passed lookup.