mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Implement 1.8 Entity MetaData
This commit is contained in:
parent
2f1da9e8c9
commit
21cd24e056
5 changed files with 67 additions and 40 deletions
|
|
@ -3,6 +3,9 @@ namespace MinecraftClient.Mapping;
|
|||
public enum EntityMetaDataType
|
||||
{
|
||||
Byte,
|
||||
Short, // 1.8 only
|
||||
Int, // 1.8 only
|
||||
Vector3Int, // 1.8 only (not used by the game)
|
||||
VarInt,
|
||||
VarLong,
|
||||
Float,
|
||||
|
|
|
|||
|
|
@ -16,8 +16,8 @@ public abstract class EntityMetadataPalette
|
|||
|
||||
public static EntityMetadataPalette GetPalette(int protocolVersion)
|
||||
{
|
||||
if (protocolVersion < Protocol18Handler.MC_1_9_Version)
|
||||
throw new NotImplementedException();
|
||||
if (protocolVersion <= Protocol18Handler.MC_1_8_Version)
|
||||
return new EntityMetadataPalette18(); // 1.8
|
||||
else if (protocolVersion <= Protocol18Handler.MC_1_12_2_Version)
|
||||
return new EntityMetadataPalette1122(); // 1.9 - 1.12.2
|
||||
else if (protocolVersion <= Protocol18Handler.MC_1_19_2_Version)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,24 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace MinecraftClient.Mapping.EntityMetadataPalettes;
|
||||
|
||||
public class EntityMetadataPalette18 : EntityMetadataPalette
|
||||
{
|
||||
// 1.8 : https://wiki.vg/index.php?title=Entity_metadata&oldid=6220
|
||||
private readonly Dictionary<int, EntityMetaDataType> entityMetadataMappings = new()
|
||||
{
|
||||
{ 0, EntityMetaDataType.Byte },
|
||||
{ 1, EntityMetaDataType.Short },
|
||||
{ 2, EntityMetaDataType.Int },
|
||||
{ 3, EntityMetaDataType.Float },
|
||||
{ 4, EntityMetaDataType.String },
|
||||
{ 5, EntityMetaDataType.Slot },
|
||||
{ 6, EntityMetaDataType.Vector3Int },
|
||||
{ 7, EntityMetaDataType.Rotation }
|
||||
};
|
||||
|
||||
public override Dictionary<int, EntityMetaDataType> GetEntityMetadataMappingsList()
|
||||
{
|
||||
return entityMetadataMappings;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,31 +0,0 @@
|
|||
using System.Collections.Generic;
|
||||
|
||||
namespace MinecraftClient.Mapping.EntityMetadataPalettes;
|
||||
|
||||
// TODO: Use this for 1.8
|
||||
public class EntityMetadataPalette19 : EntityMetadataPalette
|
||||
{
|
||||
// 1.8 : https://wiki.vg/index.php?title=Entity_metadata&oldid=6220 (Requires a different algorithm)
|
||||
// 1.9 : https://wiki.vg/index.php?title=Entity_metadata&oldid=7416
|
||||
private readonly Dictionary<int, EntityMetaDataType> entityMetadataMappings = new()
|
||||
{
|
||||
{ 0, EntityMetaDataType.Byte },
|
||||
{ 1, EntityMetaDataType.VarInt },
|
||||
{ 2, EntityMetaDataType.Float },
|
||||
{ 3, EntityMetaDataType.String },
|
||||
{ 4, EntityMetaDataType.Chat },
|
||||
{ 5, EntityMetaDataType.Slot },
|
||||
{ 6, EntityMetaDataType.Boolean },
|
||||
{ 7, EntityMetaDataType.Vector3 },
|
||||
{ 8, EntityMetaDataType.Position },
|
||||
{ 9, EntityMetaDataType.OptionalPosition },
|
||||
{ 10, EntityMetaDataType.Direction },
|
||||
{ 11, EntityMetaDataType.OptionalUuid },
|
||||
{ 12, EntityMetaDataType.OptionalBlockId }
|
||||
};
|
||||
|
||||
public override Dictionary<int, EntityMetaDataType> GetEntityMetadataMappingsList()
|
||||
{
|
||||
return entityMetadataMappings;
|
||||
}
|
||||
}
|
||||
|
|
@ -599,18 +599,31 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
}
|
||||
|
||||
//TODO: Refactor this to use new Entity Metadata Palettes
|
||||
/// <summary>
|
||||
/// Read a Entity MetaData and remove it from the cache
|
||||
/// </summary>
|
||||
/// <param name="cache"></param>
|
||||
/// <param name="itemPalette"></param>
|
||||
/// <param name="metadataPalette"></param>
|
||||
/// <returns></returns>
|
||||
/// <exception cref="NotImplementedException"></exception>
|
||||
/// <exception cref="System.IO.InvalidDataException"></exception>
|
||||
public Dictionary<int, object?> ReadNextMetadata(Queue<byte> cache, ItemPalette itemPalette, EntityMetadataPalette metadataPalette)
|
||||
{
|
||||
if (protocolversion <= Protocol18Handler.MC_1_8_Version)
|
||||
throw new NotImplementedException(); // Require sepcial implementation
|
||||
|
||||
Dictionary<int, object?> data = new();
|
||||
byte key = ReadNextByte(cache);
|
||||
byte terminteValue = protocolversion <= Protocol18Handler.MC_1_8_Version
|
||||
? (byte)0x7f // 1.8 (https://wiki.vg/index.php?title=Entity_metadata&oldid=6220#Entity_Metadata_Format)
|
||||
: (byte)0xff; // 1.9+
|
||||
|
||||
while (key != 0xff)
|
||||
while (key != terminteValue)
|
||||
{
|
||||
int typeId = ReadNextVarInt(cache);
|
||||
if (protocolversion <= Protocol18Handler.MC_1_8_Version)
|
||||
key = (byte)(key & 0x1f);
|
||||
|
||||
int typeId = protocolversion <= Protocol18Handler.MC_1_8_Version
|
||||
? key >> 5 // 1.8
|
||||
: ReadNextVarInt(cache); // 1.9+
|
||||
EntityMetaDataType type;
|
||||
try
|
||||
{
|
||||
|
|
@ -626,6 +639,20 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
switch (type)
|
||||
{
|
||||
case EntityMetaDataType.Short: // 1.8 only
|
||||
value = ReadNextShort(cache);
|
||||
break;
|
||||
case EntityMetaDataType.Int: // 1.8 only
|
||||
value = ReadNextInt(cache);
|
||||
break;
|
||||
case EntityMetaDataType.Vector3Int: // 1.8 only
|
||||
value = new List<int>()
|
||||
{
|
||||
ReadNextInt(cache),
|
||||
ReadNextInt(cache),
|
||||
ReadNextInt(cache),
|
||||
};
|
||||
break;
|
||||
case EntityMetaDataType.Byte: // byte
|
||||
value = ReadNextByte(cache);
|
||||
break;
|
||||
|
|
@ -760,7 +787,11 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return data;
|
||||
}
|
||||
|
||||
// Currently not handled. Reading data only
|
||||
/// <summary>
|
||||
/// Currently not handled. Reading data only
|
||||
/// </summary>
|
||||
/// <param name="cache"></param>
|
||||
/// <param name="itemPalette"></param>
|
||||
protected void ReadParticleData(Queue<byte> cache, ItemPalette itemPalette)
|
||||
{
|
||||
if (protocolversion < Protocol18Handler.MC_1_13_Version)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue