Ensure that all meta are registered

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2022-01-20 21:04:14 +01:00
parent 7f9f33d462
commit 9947afe18b
2 changed files with 19 additions and 1 deletions

View File

@ -45,7 +45,7 @@ import java.util.function.BiFunction;
record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType { record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType {
private static final Registry.Container<EntityType> CONTAINER = Registry.createContainer(Registry.Resource.ENTITIES, private static final Registry.Container<EntityType> CONTAINER = Registry.createContainer(Registry.Resource.ENTITIES,
(namespace, object) -> new EntityTypeImpl(Registry.entity(namespace, object, null))); (namespace, object) -> new EntityTypeImpl(Registry.entity(namespace, object, null)));
private static final Map<String, BiFunction<Entity, Metadata, EntityMeta>> ENTITY_META_SUPPLIER = createMetaMap(); static final Map<String, BiFunction<Entity, Metadata, EntityMeta>> ENTITY_META_SUPPLIER = createMetaMap();
static EntityType get(@NotNull String namespace) { static EntityType get(@NotNull String namespace) {
return CONTAINER.get(namespace); return CONTAINER.get(namespace);
@ -75,6 +75,7 @@ record EntityTypeImpl(Registry.EntityEntry registry) implements EntityType {
supplier.put("minecraft:axolotl", AxolotlMeta::new); supplier.put("minecraft:axolotl", AxolotlMeta::new);
supplier.put("minecraft:bat", BatMeta::new); supplier.put("minecraft:bat", BatMeta::new);
supplier.put("minecraft:bee", BeeMeta::new); supplier.put("minecraft:bee", BeeMeta::new);
supplier.put("minecraft:blaze", BlazeMeta::new);
supplier.put("minecraft:boat", BoatMeta::new); supplier.put("minecraft:boat", BoatMeta::new);
supplier.put("minecraft:cat", CatMeta::new); supplier.put("minecraft:cat", CatMeta::new);
supplier.put("minecraft:cave_spider", CaveSpiderMeta::new); supplier.put("minecraft:cave_spider", CaveSpiderMeta::new);

View File

@ -0,0 +1,17 @@
package net.minestom.server.entity;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertNotNull;
public class EntityMetaTest {
@Test
public void ensureRegistration() throws IllegalAccessException {
var fields = EntityTypes.class.getDeclaredFields();
for (var field : fields) {
EntityType entityType = (EntityType) field.get(this);
assertNotNull(EntityTypeImpl.ENTITY_META_SUPPLIER.get(entityType.name()), "Meta for " + entityType.name() + " is null");
}
}
}