Interface BlockApiCache<A,​C>

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

@NonExtendable public interface BlockApiCache<A,​C>
A BlockApiLookup bound to a ServerWorld 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:
BlockApiLookup
  • Method Summary

    Modifier and Type
    Method
    Description
    static <A,​ C> BlockApiCache<A,​C>
    create​(BlockApiLookup<A,​C> lookup, net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.BlockPos pos)
    Create a new instance bound to the passed ServerWorld and position, and querying the same API as the passed lookup.
    find​(@Nullable net.minecraft.block.BlockState state, C context)
    Attempt to retrieve an API from a block in the world, using the world and the position passed at creation time.
    default A
    find​(C context)
    Attempt to retrieve an API from a block in the world, using the world and the position passed at creation time.
  • Method Details

    • find

      @Nullable default A find(C context)
      Attempt to retrieve an API from a block in the world, using the world 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 @Nullable net.minecraft.block.BlockState state, C context)
      Attempt to retrieve an API from a block in the world, using the world 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.
    • create

      static <A,​ C> BlockApiCache<A,​C> create(BlockApiLookup<A,​C> lookup, net.minecraft.server.world.ServerWorld world, net.minecraft.util.math.BlockPos pos)
      Create a new instance bound to the passed ServerWorld and position, and querying the same API as the passed lookup.