fix null metadata happening

This commit is contained in:
Tofaa 2023-11-28 16:20:06 +03:00
parent cf10f2da50
commit 243413dcce
3 changed files with 4 additions and 5 deletions

View file

@ -10,6 +10,7 @@
<set>
<option value="$PROJECT_DIR$" />
<option value="$PROJECT_DIR$/test-plugin" />
<option value="$PROJECT_DIR$/wrapper-entity" />
</set>
</option>
</GradleProjectSettings>

View file

@ -104,9 +104,6 @@ public final class EntityLib {
checkInit();
Metadata m = new Metadata(entityId);
BiFunction<Integer, Metadata, EntityMeta> function = metaRegistry.get(entityType);
if (function == null) {
throw new IllegalArgumentException("No meta converter for entity type " + entityType);
}
EntityMeta meta = function.apply(entityId, m);
metadata.put(entityId, meta);
return meta;

View file

@ -30,6 +30,7 @@ import me.tofaa.entitylib.meta.mobs.villager.VillagerMeta;
import me.tofaa.entitylib.meta.mobs.villager.WanderingTraderMeta;
import me.tofaa.entitylib.meta.projectile.*;
import me.tofaa.entitylib.meta.types.PlayerMeta;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import java.util.HashMap;
@ -159,8 +160,8 @@ final class MetaConverterRegistry {
return (Class<T>) metaClasses.get(entityType);
}
public @Nullable BiFunction<Integer, Metadata, EntityMeta> get(EntityType entityType) {
return converters.get(entityType);
public @NotNull BiFunction<Integer, Metadata, EntityMeta> get(EntityType entityType) {
return converters.getOrDefault(entityType, EntityMeta::new);
}
}