using System.Collections.Generic;
namespace MinecraftClient.Mapping.EntityPalettes
{
public abstract class EntityPalette
{
///
/// Get mapping dictionary. Must be overriden with proper implementation.
///
/// Palette dictionary
protected abstract Dictionary GetDict();
///
/// Get mapping dictionary for pre-1.14 non-living entities.
///
/// Palette dictionary for non-living entities (pre-1.14)
protected virtual Dictionary? GetDictNonLiving()
{
return null;
}
///
/// Get entity type from type ID
///
/// Entity type ID
/// EntityType corresponding to the specified ID
public EntityType FromId(int id, bool living)
{
Dictionary entityTypes = GetDict();
Dictionary? entityTypesNonLiving = GetDictNonLiving();
if (entityTypesNonLiving != null && !living)
{
//Pre-1.14 non-living entities have a different set of IDs (entityTypesNonLiving != null)
if (entityTypesNonLiving.ContainsKey(id))
return entityTypesNonLiving[id];
}
else
{
//1.14+ entities have the same set of IDs regardless of living status
if (entityTypes.ContainsKey(id))
return entityTypes[id];
}
throw new System.IO.InvalidDataException("Unknown Entity ID " + id + ". Is Entity Palette up to date for this Minecraft version?");
}
}
}