Add BlockApiLookup#registerForBlockEntity ()

* Add BlockApiLookup#registerForBlockEntity

* Typo
This commit is contained in:
Technici4n 2021-08-17 20:08:55 +02:00 committed by GitHub
parent 0d7a4ee070
commit 2f75c6ce5f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -16,6 +16,8 @@
package net.fabricmc.fabric.api.lookup.v1.block;
import java.util.function.BiFunction;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;
@ -200,9 +202,26 @@ public interface BlockApiLookup<A, C> {
*/
void registerForBlocks(BlockApiProvider<A, C> provider, Block... blocks);
/**
* Expose the API for instances of the passed block entity type.
* The mapping from the parameters of the query to the API is handled by the passed {@code provider}.
* This overload allows using the correct block entity class directly.
*
* @param <T> The block entity class for which an API is exposed.
* @param provider The provider: returns an API if available in the passed block entity with the passed context,
* or {@code null} if no API is available.
* @param blockEntityType The block entity type.
*/
@SuppressWarnings("unchecked")
default <T extends BlockEntity> void registerForBlockEntity(BiFunction<? super T, C, @Nullable A> provider, BlockEntityType<T> blockEntityType) {
registerForBlockEntities((blockEntity, context) -> provider.apply((T) blockEntity, context), blockEntityType);
}
/**
* Expose the API for instances of the passed block entity types.
* The mapping from the parameters of the query to the API is handled by the passed {@link BlockEntityApiProvider}.
* This overload allows registering multiple block entity types at once,
* but due to how generics work in java, the provider has to cast to the correct block entity class if necessary.
*
* @param provider The provider.
* @param blockEntityTypes The block entity types.