2022-10-02 18:31:08 +08:00
|
|
|
|
using System.Collections.Generic;
|
2020-05-24 18:21:22 +02:00
|
|
|
|
|
|
|
|
|
|
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>
|
2020-05-25 21:39:24 +02:00
|
|
|
|
/// Get mapping dictionary for pre-1.14 non-living entities.
|
2020-05-24 18:21:22 +02:00
|
|
|
|
/// </summary>
|
2020-05-25 21:39:24 +02:00
|
|
|
|
/// <returns>Palette dictionary for non-living entities (pre-1.14)</returns>
|
2022-10-02 18:31:08 +08:00
|
|
|
|
protected virtual Dictionary<int, EntityType>? GetDictNonLiving()
|
2020-05-24 18:21:22 +02:00
|
|
|
|
{
|
|
|
|
|
|
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();
|
2022-10-02 18:31:08 +08:00
|
|
|
|
Dictionary<int, EntityType>? entityTypesNonLiving = GetDictNonLiving();
|
2020-05-24 18:21:22 +02:00
|
|
|
|
|
refactor: convert == null / != null to is null / is not null in 31 files
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>
2026-03-24 00:42:59 +00:00
|
|
|
|
if (entityTypesNonLiving is not null && !living)
|
2020-05-24 18:21:22 +02:00
|
|
|
|
{
|
refactor: convert == null / != null to is null / is not null in 31 files
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>
2026-03-24 00:42:59 +00:00
|
|
|
|
//Pre-1.14 non-living entities have a different set of IDs (entityTypesNonLiving is not null)
|
2020-05-24 18:21:22 +02:00
|
|
|
|
if (entityTypesNonLiving.ContainsKey(id))
|
|
|
|
|
|
return entityTypesNonLiving[id];
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
2020-05-25 21:39:24 +02:00
|
|
|
|
//1.14+ entities have the same set of IDs regardless of living status
|
2020-05-24 18:21:22 +02:00
|
|
|
|
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?");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|