mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Replace old-style null comparisons with modern C# pattern matching syntax across Commands, Protocol, Mapping, ChatBots, Physics, Inventory, Logger, CommandHandler, Scripting, Crypto, and other modules. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
48 lines
1.8 KiB
C#
48 lines
1.8 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace MinecraftClient.Mapping.EntityPalettes
|
|
{
|
|
public abstract class EntityPalette
|
|
{
|
|
/// <summary>
|
|
/// Get mapping dictionary. Must be overriden with proper implementation.
|
|
/// </summary>
|
|
/// <returns>Palette dictionary</returns>
|
|
protected abstract Dictionary<int, EntityType> GetDict();
|
|
|
|
/// <summary>
|
|
/// Get mapping dictionary for pre-1.14 non-living entities.
|
|
/// </summary>
|
|
/// <returns>Palette dictionary for non-living entities (pre-1.14)</returns>
|
|
protected virtual Dictionary<int, EntityType>? GetDictNonLiving()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get entity type from type ID
|
|
/// </summary>
|
|
/// <param name="id">Entity type ID</param>
|
|
/// <returns>EntityType corresponding to the specified ID</returns>
|
|
public EntityType FromId(int id, bool living)
|
|
{
|
|
Dictionary<int, EntityType> entityTypes = GetDict();
|
|
Dictionary<int, EntityType>? entityTypesNonLiving = GetDictNonLiving();
|
|
|
|
if (entityTypesNonLiving is not null && !living)
|
|
{
|
|
//Pre-1.14 non-living entities have a different set of IDs (entityTypesNonLiving is not 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?");
|
|
}
|
|
}
|
|
}
|