mirror of
https://github.com/FabricMC/fabric.git
synced 2025-04-21 03:10:54 -04:00
Make BlockApiLookup expose the API and context classes (#1486)
* Make BlockApiLookup expose the API and context classes * Test API and context classes in testmod
This commit is contained in:
parent
18ef9af8ec
commit
1d383bb698
4 changed files with 31 additions and 1 deletions
fabric-api-lookup-api-v1
|
@ -1,5 +1,5 @@
|
|||
archivesBaseName = "fabric-api-lookup-api-v1"
|
||||
version = getSubprojectVersion(project, "1.0.2")
|
||||
version = getSubprojectVersion(project, "1.1.0")
|
||||
|
||||
moduleDependencies(project, [
|
||||
'fabric-api-base',
|
||||
|
|
|
@ -217,6 +217,16 @@ public interface BlockApiLookup<A, C> {
|
|||
*/
|
||||
void registerFallback(BlockApiProvider<A, C> fallbackProvider);
|
||||
|
||||
/**
|
||||
* Return the API class of this lookup.
|
||||
*/
|
||||
Class<A> apiClass();
|
||||
|
||||
/**
|
||||
* Return the context class of this lookup.
|
||||
*/
|
||||
Class<C> contextClass();
|
||||
|
||||
@FunctionalInterface
|
||||
interface BlockApiProvider<A, C> {
|
||||
/**
|
||||
|
|
|
@ -48,12 +48,14 @@ public final class BlockApiLookupImpl<A, C> implements BlockApiLookup<A, C> {
|
|||
}
|
||||
|
||||
private final Class<A> apiClass;
|
||||
private final Class<C> contextClass;
|
||||
private final ApiProviderMap<Block, BlockApiProvider<A, C>> providerMap = ApiProviderMap.create();
|
||||
private final List<BlockApiProvider<A, C>> fallbackProviders = new CopyOnWriteArrayList<>();
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private BlockApiLookupImpl(Class<?> apiClass, Class<?> contextClass) {
|
||||
this.apiClass = (Class<A>) apiClass;
|
||||
this.contextClass = (Class<C>) contextClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
@ -172,6 +174,16 @@ public final class BlockApiLookupImpl<A, C> implements BlockApiLookup<A, C> {
|
|||
fallbackProviders.add(fallbackProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<A> apiClass() {
|
||||
return apiClass;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<C> contextClass() {
|
||||
return contextClass;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public BlockApiProvider<A, C> getProvider(Block block) {
|
||||
return providerMap.get(block);
|
||||
|
|
|
@ -83,6 +83,14 @@ public class FabricApiLookupTest implements ModInitializer {
|
|||
BlockApiLookup<Void, Void> wrongInsertable = BlockApiLookup.get(new Identifier("testmod:item_insertable"), Void.class, Void.class);
|
||||
wrongInsertable.registerFallback((world, pos, state, be, nocontext) -> null);
|
||||
}, "The registry should have prevented creation of another instance with different classes, but same id.");
|
||||
|
||||
if (insertable2.apiClass() != ItemInsertable.class) {
|
||||
throw new AssertionError("Incorrect API class was returned.");
|
||||
}
|
||||
|
||||
if (insertable2.contextClass() != Direction.class) {
|
||||
throw new AssertionError("Incorrect context class was returned.");
|
||||
}
|
||||
}
|
||||
|
||||
private static void testSelfRegistration() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue