Implement entity types (#1001)

Implement palette generation and investigate palette changes between
versions. Turns out 1.13- has legacy IDs, 1.14 switches to entity
palette and 1.15 refreshes the whole palette just to insert Bee.

Also refactor entity handling code here and there.
This commit is contained in:
ORelio 2020-05-24 18:21:22 +02:00
parent 5b0b0c9cc3
commit bd85c46663
27 changed files with 1113 additions and 259 deletions

View file

@ -0,0 +1,51 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
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.13. May be overriden with proper implementation.
/// </summary>
/// <returns>Palette dictionary for non-living entities (pre-1.13)</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 != null && !living)
{
//Pre-1.13 non-living entities have a different set of IDs (entityTypesNonLiving != null)
if (entityTypesNonLiving.ContainsKey(id))
return entityTypesNonLiving[id];
}
else
{
//Post-1.13 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?");
}
}
}