Inventory, Terrain and Entity handling

This commit is contained in:
Anon 2024-07-02 11:08:46 +02:00
parent 58a5260b5b
commit 5a6fd577e5
35 changed files with 3456 additions and 66 deletions

View file

@ -797,10 +797,12 @@ namespace MinecraftClient.Protocol.Handlers
};
break;
case EntityMetaDataType.OptionalVarInt: // Optional VarInt
if (ReadNextBool(cache))
if (protocolversion < Protocol18Handler.MC_1_20_6_Version)
{
value = ReadNextVarInt(cache);
}
if (ReadNextBool(cache))
value = ReadNextVarInt(cache);
} else value = ReadNextVarInt(cache);
break;
case EntityMetaDataType.Pose: // Pose
@ -879,15 +881,21 @@ namespace MinecraftClient.Protocol.Handlers
switch (particleId)
{
case 1: // 1.20.6+
if (protocolversion >= Protocol18Handler.MC_1_20_6_Version)
ReadNextVarInt(cache); // BlockState (minecraft:block)
break;
case 2:
// 1.18 +
// 1.18
if (protocolversion > Protocol18Handler.MC_1_17_1_Version)
ReadNextVarInt(cache); // Block state (minecraft:block)
ReadNextVarInt(cache); // Block state (minecraft:block before 1.20.6, minecraft:block_marker in 1.20.6+)
break;
case 3:
if (protocolversion is < Protocol18Handler.MC_1_17_Version or > Protocol18Handler.MC_1_17_1_Version)
if (protocolversion is (< Protocol18Handler.MC_1_17_Version or > Protocol18Handler.MC_1_17_1_Version)
and < Protocol18Handler.MC_1_20_6_Version)
ReadNextVarInt(
cache); // Block State (minecraft:block before 1.18, minecraft:block_marker after 1.18)
cache); // Block State (minecraft:block before 1.18, minecraft:block_marker after 1.18 up to 1.20.6)
break;
case 4:
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
@ -898,11 +906,24 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion < Protocol18Handler.MC_1_15_Version)
ReadDustParticle(cache);
break;
case 13:
// 1.20,6+ - minecraft:dust
ReadDustParticle(cache);
break;
case 14:
// 1.15 - 1.16.5 and 1.18 - 1.19.4
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version
or > Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache);
switch (protocolversion)
{
// 1.15 - 1.16.5 and 1.18 - 1.20.4
case >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version
or > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_20_6_Version:
ReadDustParticle(cache);
break;
// 1.20.6+
case >= Protocol18Handler.MC_1_20_6_Version:
ReadDustParticleColorTransition(cache);
break;
}
break;
case 15:
switch (protocolversion)
@ -910,7 +931,8 @@ namespace MinecraftClient.Protocol.Handlers
case Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version:
ReadDustParticle(cache);
break;
case > Protocol18Handler.MC_1_17_1_Version:
// 1.18 - 1.20.4
case > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_20_6_Version:
ReadDustParticleColorTransition(cache);
break;
}
@ -920,21 +942,26 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
ReadDustParticleColorTransition(cache);
break;
case 20:
// 1.20.6+
if (protocolversion >= Protocol18Handler.MC_1_20_6_Version)
ReadNextInt(cache); // minecraft:entity_effect
break;
case 23:
// 1.15 - 1.16.5
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 24:
// 1.18 - 1.19.2 onwards
// 1.18 - 1.19.3
if (protocolversion is > Protocol18Handler.MC_1_17_1_Version
and < Protocol18Handler.MC_1_19_3_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 25:
// 1.17 - 1.17.1 and 1.19.3 onwards
// 1.17 - 1.17.1 and 1.19.3 - 1.20.4
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version
or >= Protocol18Handler.MC_1_19_3_Version)
or (>= Protocol18Handler.MC_1_19_3_Version and < Protocol18Handler.MC_1_20_6_Version))
ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break;
case 27:
@ -942,8 +969,14 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion < Protocol18Handler.MC_1_15_Version)
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break;
case 28:
// 1.20.6+
if (protocolversion > Protocol18Handler.MC_1_20_6_Version)
ReadNextVarInt(cache); // minecraft:falling_dust (BlockState)
break;
case 30:
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version)
// 1.19.3 - 1.20.4
if (protocolversion is >= Protocol18Handler.MC_1_19_3_Version and < Protocol18Handler.MC_1_20_6_Version)
ReadNextFloat(cache); // Roll (minecraft:sculk_charge)
break;
case 32:
@ -951,6 +984,11 @@ namespace MinecraftClient.Protocol.Handlers
if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version)
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break;
case 35:
// 1.20.6+
if (protocolversion > Protocol18Handler.MC_1_20_6_Version)
ReadNextFloat(cache); // minecraft:sculk_charge (Roll)
break;
case 36:
switch (protocolversion)
{
@ -958,6 +996,7 @@ namespace MinecraftClient.Protocol.Handlers
case Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version:
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break;
// 1.18 - 1.19.2
case > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_19_3_Version:
// minecraft:vibration
ReadNextLocation(cache); // Origin (Starting Position)
@ -968,7 +1007,7 @@ namespace MinecraftClient.Protocol.Handlers
break;
case 37:
// minecraft:vibration
// minecraft:vibration - 1.17 - 1.17.1
if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
{
ReadNextDouble(cache); // Origin X
@ -982,11 +1021,13 @@ namespace MinecraftClient.Protocol.Handlers
break;
case 39:
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version)
// 1.19.3 - 1.20.4
if (protocolversion is >= Protocol18Handler.MC_1_19_3_Version and < Protocol18Handler.MC_1_20_6_Version)
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break;
case 40:
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version)
// 1.19.3 - 1.20.4
if (protocolversion is >= Protocol18Handler.MC_1_19_3_Version and < Protocol18Handler.MC_1_20_6_Version)
{
var positionSourceType = ReadNextString(cache);
switch (positionSourceType)
@ -1004,6 +1045,21 @@ namespace MinecraftClient.Protocol.Handlers
}
break;
case 44:
// 1.20.6+
if (protocolversion >= Protocol18Handler.MC_1_20_6_Version)
ReadNextItemSlot(cache, itemPalette); // minecraft:item (Item)
break;
case 99:
// 1.20.6+
if (protocolversion >= Protocol18Handler.MC_1_20_6_Version)
ReadNextVarInt(cache); // minecraft:shriek (Delay)
break;
case 105:
// 1.20.6+
if (protocolversion >= Protocol18Handler.MC_1_20_6_Version)
ReadNextVarInt(cache); // minecraft:dust_pillar (BlockState)
break;
}
}

View file

@ -103,7 +103,8 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
new ParserEmpty(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
else // 1.20.3+
else if (protocolVersion is > Protocol18Handler.MC_1_20_2_Version and < Protocol18Handler.MC_1_20_6_Version)
// 1.20.3 - 1.20.4
parser = parserId switch
{
1 => new ParserFloat(dataTypes, packetData),
@ -127,6 +128,24 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
52 => new ParserForgeEnum(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
else // 1.20.6+
parser = parserId switch
{
1 => new ParserFloat(dataTypes, packetData),
2 => new ParserDouble(dataTypes, packetData),
3 => new ParserInteger(dataTypes, packetData),
4 => new ParserLong(dataTypes, packetData),
5 => new ParserString(dataTypes, packetData),
6 => new ParserEntity(dataTypes, packetData),
30 => new ParserScoreHolder(dataTypes, packetData),
41 => new ParserTime(dataTypes, packetData),
42 => new ParserResourceOrTag(dataTypes, packetData),
43 => new ParserResourceOrTag(dataTypes, packetData),
44 => new ParserResource(dataTypes, packetData),
45 => new ParserResource(dataTypes, packetData),
52 => new ParserForgeEnum(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData),
};
}
string? suggestionsType = ((flags & 0x10) == 0x10) ? dataTypes.ReadNextString(packetData) : null;

View file

@ -123,21 +123,21 @@ namespace MinecraftClient.Protocol.Handlers
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
chunkBatchStartTime = GetNanos();
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_4_Version)
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_6_Version)
{
log.Error($"§c{Translations.extra_terrainandmovement_disabled}");
handler.SetTerrainEnabled(false);
}
if (handler.GetInventoryEnabled() &&
protocolVersion is < MC_1_8_Version or > MC_1_20_4_Version)
protocolVersion is < MC_1_8_Version or > MC_1_20_6_Version)
{
log.Error($"§c{Translations.extra_inventory_disabled}");
handler.SetInventoryEnabled(false);
}
if (handler.GetEntityHandlingEnabled() &&
protocolVersion is < MC_1_8_Version or > MC_1_20_4_Version)
protocolVersion is < MC_1_8_Version or > MC_1_20_6_Version)
{
log.Error($"§c{Translations.extra_entity_disabled}");
handler.SetEntityHandlingEnabled(false);
@ -146,8 +146,9 @@ namespace MinecraftClient.Protocol.Handlers
Block.Palette = protocolVersion switch
{
// Block palette
> MC_1_20_4_Version when handler.GetTerrainEnabled() =>
> MC_1_20_6_Version when handler.GetTerrainEnabled() =>
throw new NotImplementedException(Translations.exception_palette_block),
MC_1_20_6_Version => new Palette1206(),
>= MC_1_20_4_Version => new Palette1204(),
>= MC_1_20_Version => new Palette120(),
MC_1_19_4_Version => new Palette1194(),
@ -164,8 +165,9 @@ namespace MinecraftClient.Protocol.Handlers
entityPalette = protocolVersion switch
{
// Entity palette
> MC_1_20_4_Version when handler.GetEntityHandlingEnabled() =>
> MC_1_20_6_Version when handler.GetEntityHandlingEnabled() =>
throw new NotImplementedException(Translations.exception_palette_entity),
MC_1_20_6_Version => new EntityPalette1206(),
>= MC_1_20_4_Version => new EntityPalette1204(),
>= MC_1_20_Version => new EntityPalette120(),
MC_1_19_4_Version => new EntityPalette1194(),
@ -186,8 +188,9 @@ namespace MinecraftClient.Protocol.Handlers
itemPalette = protocolVersion switch
{
// Item palette
> MC_1_20_4_Version when handler.GetInventoryEnabled() =>
> MC_1_20_6_Version when handler.GetInventoryEnabled() =>
throw new NotImplementedException(Translations.exception_palette_item),
MC_1_20_6_Version => new ItemPalette1206(),
>= MC_1_20_4_Version => new ItemPalette1204(),
>= MC_1_20_Version => new ItemPalette120(),
MC_1_19_4_Version => new ItemPalette1194(),
@ -2499,11 +2502,38 @@ namespace MinecraftClient.Protocol.Handlers
var numberOfProperties = protocolVersion >= MC_1_17_Version
? dataTypes.ReadNextVarInt(packetData)
: dataTypes.ReadNextInt(packetData);
var attributeDictionary = new Dictionary<int, string>
{
{ 0, "generic.armor" },
{ 1, "generic.armor_toughness" },
{ 2, "generic.attack_damage" },
{ 3, "generic.attack_knockback" },
{ 4, "generic.attack_speed" },
{ 5, "generic.block_break_speed" },
{ 6, "generic.block_interaction_range" },
{ 7, "generic.entity_interaction_range" },
{ 8, "generic.fall_damage_multiplier" },
{ 9, "generic.flying_speed" },
{ 10, "generic.follow_range" },
{ 11, "generic.gravity" },
{ 12, "generic.jump_strength" },
{ 13, "generic.knockback_resistance" },
{ 14, "generic.luck" },
{ 15, "generic.max_absorption" },
{ 16, "generic.max_health" },
{ 17, "generic.movement_speed" },
{ 18, "generic.safe_fall_distance" },
{ 19, "generic.scale" },
{ 20, "zombie.spawn_reinforcements" },
{ 21, "generic.step_height" }
};
Dictionary<string, double> keys = new();
for (var i = 0; i < numberOfProperties; i++)
{
var propertyKey = dataTypes.ReadNextString(packetData);
var propertyKey = protocolVersion < MC_1_20_6_Version ? dataTypes.ReadNextString(packetData)
: attributeDictionary[dataTypes.ReadNextVarInt(packetData)];
var propertyValue2 = dataTypes.ReadNextDouble(packetData);
List<double> op0 = new();
@ -2549,7 +2579,7 @@ namespace MinecraftClient.Protocol.Handlers
// Also make a palette for field? Will be a lot of work
var healthField = protocolVersion switch
{
> MC_1_20_4_Version => throw new NotImplementedException(Translations
> MC_1_20_6_Version => throw new NotImplementedException(Translations
.exception_palette_healthfield),
// 1.17 and above
>= MC_1_17_Version => 9,