Merge pull request #4 from ReinforceZwei/metadata18

Implement 1.8 Entity MetaData
This commit is contained in:
Anon 2023-03-27 13:52:23 +00:00 committed by GitHub
commit 4ec3d0c13a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 195 additions and 2080 deletions

View file

@ -345,6 +345,17 @@ namespace MinecraftClient.ChatBots
{
var command = text[1..];
if (command.ToLower().Contains("quit") || command.ToLower().Contains("exit"))
{
await botClient.SendTextMessageAsync(
chatId: chatId,
replyToMessageId: message.MessageId,
text: $"{Translations.bot_TelegramBridge_quit_disabled}",
cancellationToken: _cancellationToken,
parseMode: ParseMode.Markdown);
return;;
}
CmdResult result = new();
PerformInternalCommand(command, ref result);

View file

@ -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,

View file

@ -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)

View file

@ -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;
}
}

View file

@ -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;
}
}

View file

@ -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)

File diff suppressed because it is too large Load diff

View file

@ -2034,4 +2034,7 @@ Logging in...</value>
<data name="cmd.dig.cancel" xml:space="preserve">
<value>Cancel mining the block located at {0}.</value>
</data>
<data name="bot.TelegramBridge.quit_disabled" xml:space="preserve">
<value>This command has been disabled due to Telegram caching causing issues, please stop your client manually.</value>
</data>
</root>