From 2f75c6ce5fcf36e2f27e3cd852f49aa4ce79604c Mon Sep 17 00:00:00 2001
From: Technici4n <13494793+Technici4n@users.noreply.github.com>
Date: Tue, 17 Aug 2021 20:08:55 +0200
Subject: [PATCH] Add BlockApiLookup#registerForBlockEntity (#1638)

* Add BlockApiLookup#registerForBlockEntity

* Typo
---
 .../api/lookup/v1/block/BlockApiLookup.java   | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/api/lookup/v1/block/BlockApiLookup.java b/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/api/lookup/v1/block/BlockApiLookup.java
index e16077db6..2e40affbe 100644
--- a/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/api/lookup/v1/block/BlockApiLookup.java
+++ b/fabric-api-lookup-api-v1/src/main/java/net/fabricmc/fabric/api/lookup/v1/block/BlockApiLookup.java
@@ -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.