Fully Implemented 1.20

This commit is contained in:
Anon 2023-06-08 19:27:28 +02:00
parent b21f40593e
commit ae7ce35cc8
14 changed files with 3313 additions and 209 deletions

View file

@ -874,10 +874,10 @@ namespace MinecraftClient.Inventory.ItemPalettes
mappings[837] = ItemType.Porkchop;
mappings[1048] = ItemType.Potato;
mappings[953] = ItemType.Potion;
mappings[1224] = ItemType.PotteryShardArcher;
mappings[1226] = ItemType.PotteryShardArmsUp;
mappings[1225] = ItemType.PotteryShardPrize;
mappings[1227] = ItemType.PotteryShardSkull;
mappings[1224] = ItemType.ArcherPotterySherd;
mappings[1226] = ItemType.ArmsUpPotterySherd;
mappings[1225] = ItemType.PrizePotterySherd;
mappings[1227] = ItemType.SkullPotterySherd;
mappings[867] = ItemType.PowderSnowBucket;
mappings[719] = ItemType.PoweredRail;
mappings[479] = ItemType.Prismarine;

File diff suppressed because it is too large Load diff

View file

@ -12,7 +12,7 @@
public enum ItemType
{
Unknown = -2, // Unsupported item type (Forge mod custom item...)
Null = -1, // Unspecified item type (Used in the network protocol)
Null = -1, // Unspecified item type (Used in the network protocol)
AcaciaBoat,
AcaciaButton,
@ -43,9 +43,12 @@
AndesiteSlab,
AndesiteStairs,
AndesiteWall,
AnglerPotterySherd,
Anvil,
Apple,
ArcherPotterySherd,
ArmorStand,
ArmsUpPotterySherd,
Arrow,
AxolotlBucket,
AxolotlSpawnEgg,
@ -120,6 +123,7 @@
BlackstoneSlab,
BlackstoneStairs,
BlackstoneWall,
BladePotterySherd,
BlastFurnace,
BlazePowder,
BlazeRod,
@ -150,6 +154,7 @@
BrainCoralBlock,
BrainCoralFan,
Bread,
BrewerPotterySherd,
BrewingStand,
Brick,
BrickSlab,
@ -178,9 +183,11 @@
Bucket,
BuddingAmethyst,
Bundle,
BurnPotterySherd,
Cactus,
Cake,
Calcite,
CalibratedSculkSensor,
CamelSpawnEgg,
Campfire,
Candle,
@ -320,6 +327,7 @@
CyanWool,
DamagedAnvil,
Dandelion,
DangerPotterySherd,
DarkOakBoat,
DarkOakButton,
DarkOakChestBoat,
@ -435,6 +443,7 @@
EndermiteSpawnEgg,
EvokerSpawnEgg,
ExperienceBottle,
ExplorerPotterySherd,
ExposedCopper,
ExposedCutCopper,
ExposedCutCopperSlab,
@ -460,6 +469,7 @@
FloweringAzalea,
FloweringAzaleaLeaves,
FoxSpawnEgg,
FriendPotterySherd,
FrogSpawnEgg,
Frogspawn,
Furnace,
@ -536,6 +546,8 @@
HangingRoots,
HayBlock,
HeartOfTheSea,
HeartPotterySherd,
HeartbreakPotterySherd,
HeavyWeightedPressurePlate,
HoglinSpawnEgg,
HoneyBlock,
@ -548,6 +560,8 @@
HornCoralBlock,
HornCoralFan,
HorseSpawnEgg,
HostArmorTrimSmithingTemplate,
HowlPotterySherd,
HuskSpawnEgg,
Ice,
InfestedChiseledStoneBricks,
@ -706,6 +720,7 @@
MelonSlice,
MilkBucket,
Minecart,
MinerPotterySherd,
MojangBannerPattern,
MooshroomSpawnEgg,
MossBlock,
@ -718,6 +733,7 @@
MossyStoneBrickStairs,
MossyStoneBrickWall,
MossyStoneBricks,
MournerPotterySherd,
Mud,
MudBrickSlab,
MudBrickStairs,
@ -738,6 +754,7 @@
MusicDiscMellohi,
MusicDiscOtherside,
MusicDiscPigstep,
MusicDiscRelic,
MusicDiscStal,
MusicDiscStrad,
MusicDiscWait,
@ -846,7 +863,10 @@
PinkTulip,
PinkWool,
Piston,
PitcherPlant,
PitcherPod,
PlayerHead,
PlentyPotterySherd,
Podzol,
PointedDripstone,
PoisonousPotato,
@ -880,10 +900,6 @@
Porkchop,
Potato,
Potion,
PotteryShardArcher,
PotteryShardArmsUp,
PotteryShardPrize,
PotteryShardSkull,
PowderSnowBucket,
PoweredRail,
Prismarine,
@ -895,6 +911,7 @@
PrismarineSlab,
PrismarineStairs,
PrismarineWall,
PrizePotterySherd,
Pufferfish,
PufferfishBucket,
PufferfishSpawnEgg,
@ -930,6 +947,7 @@
RabbitSpawnEgg,
RabbitStew,
Rail,
RaiserArmorTrimSmithingTemplate,
RavagerSpawnEgg,
RawCopper,
RawCopperBlock,
@ -996,18 +1014,23 @@
SeaPickle,
Seagrass,
SentryArmorTrimSmithingTemplate,
ShaperArmorTrimSmithingTemplate,
SheafPotterySherd,
Shears,
SheepSpawnEgg,
ShelterPotterySherd,
Shield,
Shroomlight,
ShulkerBox,
ShulkerShell,
ShulkerSpawnEgg,
SilenceArmorTrimSmithingTemplate,
SilverfishSpawnEgg,
SkeletonHorseSpawnEgg,
SkeletonSkull,
SkeletonSpawnEgg,
SkullBannerPattern,
SkullPotterySherd,
SlimeBall,
SlimeBlock,
SlimeSpawnEgg,
@ -1027,7 +1050,9 @@
SmoothSandstoneStairs,
SmoothStone,
SmoothStoneSlab,
SnifferEgg,
SnifferSpawnEgg,
SnortPotterySherd,
SnoutArmorTrimSmithingTemplate,
Snow,
SnowBlock,
@ -1111,6 +1136,7 @@
Sugar,
SugarCane,
Sunflower,
SuspiciousGravel,
SuspiciousSand,
SuspiciousStew,
SweetBerries,
@ -1187,6 +1213,7 @@
WaxedWeatheredCutCopper,
WaxedWeatheredCutCopperSlab,
WaxedWeatheredCutCopperStairs,
WayfinderArmorTrimSmithingTemplate,
WeatheredCopper,
WeatheredCutCopper,
WeatheredCutCopperSlab,

File diff suppressed because it is too large Load diff

View file

@ -16,17 +16,14 @@ public abstract class EntityMetadataPalette
public static EntityMetadataPalette GetPalette(int protocolVersion)
{
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)
return new EntityMetadataPalette1191(); // 1.13 - 1.19.2
else if (protocolVersion <= Protocol18Handler.MC_1_19_3_Version)
return new EntityMetadataPalette1193(); // 1.19.3
else if (protocolVersion <= Protocol18Handler.MC_1_19_4_Version)
return new EntityMetadataPalette1194(); // 1.19.4
else
throw new NotImplementedException();
return protocolVersion switch
{
<= Protocol18Handler.MC_1_8_Version => new EntityMetadataPalette18(), // 1.8
<= Protocol18Handler.MC_1_12_2_Version => new EntityMetadataPalette1122(), // 1.9 - 1.12.2
<= Protocol18Handler.MC_1_19_2_Version => new EntityMetadataPalette1191(), // 1.13 - 1.19.2
<= Protocol18Handler.MC_1_19_3_Version => new EntityMetadataPalette1193(), // 1.19.3
<= Protocol18Handler.MC_1_20_Version => new EntityMetadataPalette1194(), // 1.19.4 - 1.20 +
_ => throw new NotImplementedException()
};
}
}

View file

@ -0,0 +1,142 @@
using System.Collections.Generic;
namespace MinecraftClient.Mapping.EntityPalettes
{
public class EntityPalette120 : EntityPalette
{
private static readonly Dictionary<int, EntityType> mappings = new();
static EntityPalette120()
{
mappings[0] = EntityType.Allay;
mappings[1] = EntityType.AreaEffectCloud;
mappings[2] = EntityType.ArmorStand;
mappings[3] = EntityType.Arrow;
mappings[4] = EntityType.Axolotl;
mappings[5] = EntityType.Bat;
mappings[6] = EntityType.Bee;
mappings[7] = EntityType.Blaze;
mappings[8] = EntityType.BlockDisplay;
mappings[9] = EntityType.Boat;
mappings[10] = EntityType.Camel;
mappings[11] = EntityType.Cat;
mappings[12] = EntityType.CaveSpider;
mappings[13] = EntityType.ChestBoat;
mappings[14] = EntityType.ChestMinecart;
mappings[15] = EntityType.Chicken;
mappings[16] = EntityType.Cod;
mappings[17] = EntityType.CommandBlockMinecart;
mappings[18] = EntityType.Cow;
mappings[19] = EntityType.Creeper;
mappings[20] = EntityType.Dolphin;
mappings[21] = EntityType.Donkey;
mappings[22] = EntityType.DragonFireball;
mappings[23] = EntityType.Drowned;
mappings[24] = EntityType.Egg;
mappings[25] = EntityType.ElderGuardian;
mappings[26] = EntityType.EndCrystal;
mappings[27] = EntityType.EnderDragon;
mappings[28] = EntityType.EnderPearl;
mappings[29] = EntityType.Enderman;
mappings[30] = EntityType.Endermite;
mappings[31] = EntityType.Evoker;
mappings[32] = EntityType.EvokerFangs;
mappings[33] = EntityType.ExperienceBottle;
mappings[34] = EntityType.ExperienceOrb;
mappings[35] = EntityType.EyeOfEnder;
mappings[36] = EntityType.FallingBlock;
mappings[57] = EntityType.Fireball;
mappings[37] = EntityType.FireworkRocket;
mappings[123] = EntityType.FishingBobber;
mappings[38] = EntityType.Fox;
mappings[39] = EntityType.Frog;
mappings[40] = EntityType.FurnaceMinecart;
mappings[41] = EntityType.Ghast;
mappings[42] = EntityType.Giant;
mappings[43] = EntityType.GlowItemFrame;
mappings[44] = EntityType.GlowSquid;
mappings[45] = EntityType.Goat;
mappings[46] = EntityType.Guardian;
mappings[47] = EntityType.Hoglin;
mappings[48] = EntityType.HopperMinecart;
mappings[49] = EntityType.Horse;
mappings[50] = EntityType.Husk;
mappings[51] = EntityType.Illusioner;
mappings[52] = EntityType.Interaction;
mappings[53] = EntityType.IronGolem;
mappings[54] = EntityType.Item;
mappings[55] = EntityType.ItemDisplay;
mappings[56] = EntityType.ItemFrame;
mappings[58] = EntityType.LeashKnot;
mappings[59] = EntityType.LightningBolt;
mappings[60] = EntityType.Llama;
mappings[61] = EntityType.LlamaSpit;
mappings[62] = EntityType.MagmaCube;
mappings[63] = EntityType.Marker;
mappings[64] = EntityType.Minecart;
mappings[65] = EntityType.Mooshroom;
mappings[66] = EntityType.Mule;
mappings[67] = EntityType.Ocelot;
mappings[68] = EntityType.Painting;
mappings[69] = EntityType.Panda;
mappings[70] = EntityType.Parrot;
mappings[71] = EntityType.Phantom;
mappings[72] = EntityType.Pig;
mappings[73] = EntityType.Piglin;
mappings[74] = EntityType.PiglinBrute;
mappings[75] = EntityType.Pillager;
mappings[122] = EntityType.Player;
mappings[76] = EntityType.PolarBear;
mappings[77] = EntityType.Potion;
mappings[78] = EntityType.Pufferfish;
mappings[79] = EntityType.Rabbit;
mappings[80] = EntityType.Ravager;
mappings[81] = EntityType.Salmon;
mappings[82] = EntityType.Sheep;
mappings[83] = EntityType.Shulker;
mappings[84] = EntityType.ShulkerBullet;
mappings[85] = EntityType.Silverfish;
mappings[86] = EntityType.Skeleton;
mappings[87] = EntityType.SkeletonHorse;
mappings[88] = EntityType.Slime;
mappings[89] = EntityType.SmallFireball;
mappings[90] = EntityType.Sniffer;
mappings[91] = EntityType.SnowGolem;
mappings[92] = EntityType.Snowball;
mappings[93] = EntityType.SpawnerMinecart;
mappings[94] = EntityType.SpectralArrow;
mappings[95] = EntityType.Spider;
mappings[96] = EntityType.Squid;
mappings[97] = EntityType.Stray;
mappings[98] = EntityType.Strider;
mappings[99] = EntityType.Tadpole;
mappings[100] = EntityType.TextDisplay;
mappings[101] = EntityType.Tnt;
mappings[102] = EntityType.TntMinecart;
mappings[103] = EntityType.TraderLlama;
mappings[104] = EntityType.Trident;
mappings[105] = EntityType.TropicalFish;
mappings[106] = EntityType.Turtle;
mappings[107] = EntityType.Vex;
mappings[108] = EntityType.Villager;
mappings[109] = EntityType.Vindicator;
mappings[110] = EntityType.WanderingTrader;
mappings[111] = EntityType.Warden;
mappings[112] = EntityType.Witch;
mappings[113] = EntityType.Wither;
mappings[114] = EntityType.WitherSkeleton;
mappings[115] = EntityType.WitherSkull;
mappings[116] = EntityType.Wolf;
mappings[117] = EntityType.Zoglin;
mappings[118] = EntityType.Zombie;
mappings[119] = EntityType.ZombieHorse;
mappings[120] = EntityType.ZombieVillager;
mappings[121] = EntityType.ZombifiedPiglin;
}
protected override Dictionary<int, EntityType> GetDict()
{
return mappings;
}
}
}

View file

@ -165,6 +165,7 @@
Cactus,
Cake,
Calcite,
CalibratedSculkSensor,
Campfire,
Candle,
CandleCake,
@ -666,6 +667,8 @@
PinkWool,
Piston,
PistonHead,
PitcherCrop,
PitcherPlant,
PlayerHead,
PlayerWallHead,
Podzol,
@ -842,6 +845,7 @@
SmoothSandstoneStairs,
SmoothStone,
SmoothStoneSlab,
SnifferEgg,
Snow,
SnowBlock,
SoulCampfire,
@ -907,6 +911,7 @@
StructureVoid,
SugarCane,
Sunflower,
SuspiciousGravel,
SuspiciousSand,
SweetBerryBush,
TallGrass,

View file

@ -46,7 +46,7 @@ namespace MinecraftClient
public const string Version = MCHighestVersion;
public const string MCLowestVersion = "1.4.6";
public const string MCHighestVersion = "1.19.4";
public const string MCHighestVersion = "1.20";
public static readonly string? BuildInfo = null;
private static Tuple<Thread, CancellationTokenSource>? offlinePrompt = null;
@ -860,7 +860,7 @@ namespace MinecraftClient
public static Type[] GetTypesInNamespace(string nameSpace, Assembly? assembly = null)
{
if (assembly == null) { assembly = Assembly.GetExecutingAssembly(); }
return assembly.GetTypes().Where(t => String.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
return assembly.GetTypes().Where(t => string.Equals(t.Namespace, nameSpace, StringComparison.Ordinal)).ToArray();
}
/// <summary>
@ -870,7 +870,7 @@ namespace MinecraftClient
{
if (typeof(Program)
.Assembly
.GetCustomAttributes(typeof(System.Reflection.AssemblyConfigurationAttribute), false)
.GetCustomAttributes(typeof(AssemblyConfigurationAttribute), false)
.FirstOrDefault() is AssemblyConfigurationAttribute attribute)
BuildInfo = attribute.Configuration;
}

View file

@ -111,11 +111,11 @@ namespace MinecraftClient.Protocol.Handlers.PacketPalettes
{ 0x66, PacketTypesIn.NBTQueryResponse }, // (Wiki name: Tab Query)
{ 0x67, PacketTypesIn.CollectItem }, // (Wiki name: Take Item Entity)
{ 0x68, PacketTypesIn.EntityTeleport }, // (Wiki name: Teleport Entity)
{ 0x69, PacketTypesIn.Advancements }, // (Wiki name: Update Advancements)
{ 0x69, PacketTypesIn.Advancements }, // (Wiki name: Update Advancements) (Unused)
{ 0x6A, PacketTypesIn.EntityProperties }, // (Wiki name: Update Attributes)
{ 0x6B, PacketTypesIn.FeatureFlags }, // Added in 1.19.3 (Not yet clear what is the purpose of this packet)
{ 0x6C, PacketTypesIn.EntityEffect }, // Changed in 1.19 (Added "Has Factor Data" and "Factor Codec" fields) (Wiki name: Entity Effect)
{ 0x6D, PacketTypesIn.DeclareRecipes }, // (Wiki name: Update Recipes)
{ 0x6D, PacketTypesIn.DeclareRecipes }, // (Wiki name: Update Recipes) (Unused)
{ 0x6E, PacketTypesIn.Tags }, // (Wiki name: Update Tags)
};

View file

@ -46,40 +46,26 @@ namespace MinecraftClient.Protocol.Handlers
/// <returns></returns>
public PacketTypePalette GetTypeHandler(int protocol)
{
PacketTypePalette p;
if (protocol > Protocol18Handler.MC_1_19_4_Version)
throw new NotImplementedException(Translations.exception_palette_packet);
if (protocol <= Protocol18Handler.MC_1_8_Version)
p = new PacketPalette17();
else if (protocol <= Protocol18Handler.MC_1_11_2_Version)
p = new PacketPalette110();
else if (protocol <= Protocol18Handler.MC_1_12_Version)
p = new PacketPalette112();
else if (protocol <= Protocol18Handler.MC_1_12_2_Version)
p = new PacketPalette1122();
else if (protocol < Protocol18Handler.MC_1_14_Version)
p = new PacketPalette113();
else if (protocol < Protocol18Handler.MC_1_15_Version)
p = new PacketPalette114();
else if (protocol <= Protocol18Handler.MC_1_15_2_Version)
p = new PacketPalette115();
else if (protocol <= Protocol18Handler.MC_1_16_1_Version)
p = new PacketPalette116();
else if (protocol <= Protocol18Handler.MC_1_16_5_Version)
p = new PacketPalette1162();
else if (protocol <= Protocol18Handler.MC_1_17_1_Version)
p = new PacketPalette117();
else if (protocol <= Protocol18Handler.MC_1_18_2_Version)
p = new PacketPalette118();
else if (protocol <= Protocol18Handler.MC_1_19_Version)
p = new PacketPalette119();
else if (protocol <= Protocol18Handler.MC_1_19_2_Version)
p = new PacketPalette1192();
else if (protocol <= Protocol18Handler.MC_1_19_3_Version)
p = new PacketPalette1193();
else
p = new PacketPalette1194();
PacketTypePalette p = protocol switch
{
> Protocol18Handler.MC_1_20_Version => throw new NotImplementedException(Translations
.exception_palette_packet),
<= Protocol18Handler.MC_1_8_Version => new PacketPalette17(),
<= Protocol18Handler.MC_1_11_2_Version => new PacketPalette110(),
<= Protocol18Handler.MC_1_12_Version => new PacketPalette112(),
<= Protocol18Handler.MC_1_12_2_Version => new PacketPalette1122(),
< Protocol18Handler.MC_1_14_Version => new PacketPalette113(),
< Protocol18Handler.MC_1_15_Version => new PacketPalette114(),
<= Protocol18Handler.MC_1_15_2_Version => new PacketPalette115(),
<= Protocol18Handler.MC_1_16_1_Version => new PacketPalette116(),
<= Protocol18Handler.MC_1_16_5_Version => new PacketPalette1162(),
<= Protocol18Handler.MC_1_17_1_Version => new PacketPalette117(),
<= Protocol18Handler.MC_1_18_2_Version => new PacketPalette118(),
<= Protocol18Handler.MC_1_19_Version => new PacketPalette119(),
<= Protocol18Handler.MC_1_19_2_Version => new PacketPalette1192(),
<= Protocol18Handler.MC_1_19_3_Version => new PacketPalette1193(),
_ => new PacketPalette1194()
};
p.SetForgeEnabled(forgeEnabled);
return p;

View file

@ -711,7 +711,7 @@ namespace MinecraftClient.Protocol.Handlers
catch (SocketException) { return false; }
}
public bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4)
public bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4, bool isFrontText = true)
{
return false; //Currently not implemented
}

View file

@ -66,6 +66,7 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC_1_19_2_Version = 760;
internal const int MC_1_19_3_Version = 761;
internal const int MC_1_19_4_Version = 762;
internal const int MC_1_20_Version = 763;
private int compression_treshold = 0;
private int autocomplete_transaction_id = 0;
@ -113,97 +114,79 @@ namespace MinecraftClient.Protocol.Handlers
randomGen = RandomNumberGenerator.Create();
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_19_4_Version)
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_Version)
{
log.Error("§c" + Translations.extra_terrainandmovement_disabled);
handler.SetTerrainEnabled(false);
}
if (handler.GetInventoryEnabled() &&
(protocolVersion < MC_1_9_Version || protocolVersion > MC_1_19_4_Version))
protocolVersion is < MC_1_9_Version or > MC_1_20_Version)
{
log.Error("§c" + Translations.extra_inventory_disabled);
handler.SetInventoryEnabled(false);
}
if (handler.GetEntityHandlingEnabled() &&
(protocolVersion < MC_1_8_Version || protocolVersion > MC_1_19_4_Version))
protocolVersion is < MC_1_8_Version or > MC_1_20_Version)
{
log.Error("§c" + Translations.extra_entity_disabled);
handler.SetEntityHandlingEnabled(false);
}
// Block palette
if (protocolVersion > MC_1_19_4_Version && handler.GetTerrainEnabled())
throw new NotImplementedException(Translations.exception_palette_block);
Block.Palette = protocolVersion switch
{
// Block palette
> MC_1_20_Version when handler.GetTerrainEnabled() =>
throw new NotImplementedException(Translations.exception_palette_block),
MC_1_20_Version => new Palette120(),
MC_1_19_4_Version => new Palette1194(),
MC_1_19_3_Version => new Palette1193(),
>= MC_1_19_Version => new Palette119(),
>= MC_1_17_Version => new Palette117(),
>= MC_1_16_Version => new Palette116(),
>= MC_1_15_Version => new Palette115(),
>= MC_1_14_Version => new Palette114(),
>= MC_1_13_Version => new Palette113(),
_ => new Palette112()
};
if (protocolVersion >= MC_1_19_4_Version)
Block.Palette = new Palette1194();
else if (protocolVersion >= MC_1_19_3_Version)
Block.Palette = new Palette1193();
else if (protocolVersion >= MC_1_19_Version)
Block.Palette = new Palette119();
else if (protocolVersion >= MC_1_17_Version)
Block.Palette = new Palette117();
else if (protocolVersion >= MC_1_16_Version)
Block.Palette = new Palette116();
else if (protocolVersion >= MC_1_15_Version)
Block.Palette = new Palette115();
else if (protocolVersion >= MC_1_14_Version)
Block.Palette = new Palette114();
else if (protocolVersion >= MC_1_13_Version)
Block.Palette = new Palette113();
else
Block.Palette = new Palette112();
// Entity palette
if (protocolVersion > MC_1_19_4_Version && handler.GetEntityHandlingEnabled())
throw new NotImplementedException(Translations.exception_palette_entity);
if (protocolVersion >= MC_1_19_4_Version)
entityPalette = new EntityPalette1194();
else if (protocolVersion >= MC_1_19_3_Version)
entityPalette = new EntityPalette1193();
else if (protocolVersion >= MC_1_19_Version)
entityPalette = new EntityPalette119();
else if (protocolVersion >= MC_1_17_Version)
entityPalette = new EntityPalette117();
else if (protocolVersion >= MC_1_16_2_Version)
entityPalette = new EntityPalette1162();
else if (protocolVersion >= MC_1_16_Version)
entityPalette = new EntityPalette1161();
else if (protocolVersion >= MC_1_15_Version)
entityPalette = new EntityPalette115();
else if (protocolVersion >= MC_1_14_Version)
entityPalette = new EntityPalette114();
else if (protocolVersion >= MC_1_13_Version)
entityPalette = new EntityPalette113();
else if (protocolVersion >= MC_1_12_Version)
entityPalette = new EntityPalette112();
else entityPalette = new EntityPalette18();
entityPalette = protocolVersion switch
{
// Entity palette
> MC_1_20_Version when handler.GetEntityHandlingEnabled() =>
throw new NotImplementedException(Translations.exception_palette_entity),
MC_1_20_Version => new EntityPalette120(),
MC_1_19_4_Version => new EntityPalette1194(),
MC_1_19_3_Version => new EntityPalette1193(),
>= MC_1_19_Version => new EntityPalette119(),
>= MC_1_17_Version => new EntityPalette117(),
>= MC_1_16_2_Version => new EntityPalette1162(),
>= MC_1_16_Version => new EntityPalette1161(),
>= MC_1_15_Version => new EntityPalette115(),
>= MC_1_14_Version => new EntityPalette114(),
>= MC_1_13_Version => new EntityPalette113(),
>= MC_1_12_Version => new EntityPalette112(),
_ => new EntityPalette18()
};
entityMetadataPalette = EntityMetadataPalette.GetPalette(protocolVersion);
// Item palette
if (protocolVersion > MC_1_19_4_Version && handler.GetInventoryEnabled())
throw new NotImplementedException(Translations.exception_palette_item);
if (protocolVersion >= MC_1_19_4_Version)
itemPalette = new ItemPalette1194();
else if (protocolVersion >= MC_1_19_3_Version)
itemPalette = new ItemPalette1193();
else if (protocolVersion >= MC_1_19_Version)
itemPalette = new ItemPalette119();
else if (protocolVersion >= MC_1_18_1_Version)
itemPalette = new ItemPalette118();
else if (protocolVersion >= MC_1_17_Version)
itemPalette = new ItemPalette117();
else if (protocolVersion >= MC_1_16_2_Version)
itemPalette = new ItemPalette1162();
else if (protocolVersion >= MC_1_16_1_Version)
itemPalette = new ItemPalette1161();
else
itemPalette = new ItemPalette115();
itemPalette = protocolVersion switch
{
// Item palette
> MC_1_20_Version when handler.GetInventoryEnabled() =>
throw new NotImplementedException(Translations.exception_palette_item),
MC_1_20_Version => new ItemPalette120(),
MC_1_19_4_Version => new ItemPalette1194(),
MC_1_19_3_Version => new ItemPalette1193(),
>= MC_1_19_Version => new ItemPalette119(),
>= MC_1_18_1_Version => new ItemPalette118(),
>= MC_1_17_Version => new ItemPalette117(),
>= MC_1_16_2_Version => new ItemPalette1162(),
>= MC_1_16_1_Version => new ItemPalette1161(),
_ => new ItemPalette115()
};
// MessageType
// You can find it in https://wiki.vg/Protocol#Player_Chat_Message or /net/minecraft/network/message/MessageType.java
@ -523,6 +506,9 @@ namespace MinecraftClient.Protocol.Handlers
}
}
if (protocolVersion >= MC_1_20_Version)
dataTypes.ReadNextVarInt(packetData); // Portal Cooldown - 1.20 and above
break;
case PacketTypesIn.SpawnPainting: // Just skip, no need for this
return true;
@ -880,7 +866,7 @@ namespace MinecraftClient.Protocol.Handlers
dataTypes.SkipNextVarInt(packetData);
handler.OnPlayerKilled(
dataTypes.ReadNextInt(packetData),
protocolVersion >= MC_1_20_Version ? -1 : dataTypes.ReadNextInt(packetData),
ChatParser.ParseText(dataTypes.ReadNextString(packetData))
);
@ -1009,6 +995,9 @@ namespace MinecraftClient.Protocol.Handlers
}
}
if (protocolVersion >= MC_1_20_Version)
dataTypes.ReadNextVarInt(packetData); // Portal Cooldown
handler.OnRespawn();
break;
case PacketTypesIn.PlayerPositionAndLook:
@ -1103,6 +1092,7 @@ namespace MinecraftClient.Protocol.Handlers
Interlocked.Decrement(ref handler.GetWorld().chunkLoadNotCompleted);
// Block Entity data: ignored
// Trust edges: ignored (Removed in 1.20)
// Light data: ignored
}
else
@ -1359,7 +1349,10 @@ namespace MinecraftClient.Protocol.Handlers
int sectionX = (int)(chunkSection >> 42);
int sectionY = (int)((chunkSection << 44) >> 44);
int sectionZ = (int)((chunkSection << 22) >> 42);
dataTypes.ReadNextBool(packetData); // Useless boolean (Related to light update)
if(protocolVersion < MC_1_20_Version)
dataTypes.ReadNextBool(packetData); // Useless boolean (Related to light update)
int blocksSize = dataTypes.ReadNextVarInt(packetData);
for (int i = 0; i < blocksSize; i++)
{
@ -2188,22 +2181,23 @@ namespace MinecraftClient.Protocol.Handlers
dataTypes.ReadNextMetadata(packetData, itemPalette, entityMetadataPalette);
// Also make a palette for field? Will be a lot of work
int healthField; // See https://wiki.vg/Entity_metadata#Living_Entity
if (protocolVersion > MC_1_19_4_Version)
throw new NotImplementedException(Translations.exception_palette_healthfield);
else if (protocolVersion >= MC_1_17_Version) // 1.17 and above
healthField = 9;
else if (protocolVersion >= MC_1_14_Version) // 1.14 and above
healthField = 8;
else if (protocolVersion >= MC_1_10_Version) // 1.10 and above
healthField = 7;
else if (protocolVersion >= MC_1_8_Version) // 1.8 and above
healthField = 6;
else
throw new NotImplementedException(Translations.exception_palette_healthfield);
int healthField = protocolVersion switch
{
> MC_1_20_Version => throw new NotImplementedException(Translations
.exception_palette_healthfield),
// 1.17 and above
>= MC_1_17_Version => 9,
// 1.14 and above
>= MC_1_14_Version => 8,
// 1.10 and above
>= MC_1_10_Version => 7,
// 1.8 and above
>= MC_1_8_Version => 6,
_ => throw new NotImplementedException(Translations.exception_palette_healthfield)
};
if (metadata.TryGetValue(healthField, out object? healthObj) && healthObj != null &&
healthObj.GetType() == typeof(float))
if (metadata.TryGetValue(healthField, out var healthObj) && healthObj != null &&
healthObj is float)
handler.OnEntityHealth(EntityID, (float)healthObj);
handler.OnEntityMetadata(EntityID, metadata);
@ -2343,6 +2337,17 @@ namespace MinecraftClient.Protocol.Handlers
}
break;
case PacketTypesIn.OpenSignEditor:
var signLocation = dataTypes.ReadNextLocation(packetData);
var isFrontText = true;
if (protocolVersion >= MC_1_20_Version)
isFrontText = dataTypes.ReadNextBool(packetData);
// TODO: Use
break;
default:
return false; //Ignored packet
}
@ -3950,7 +3955,7 @@ namespace MinecraftClient.Protocol.Handlers
}
}
public bool SendUpdateSign(Location sign, string line1, string line2, string line3, string line4)
public bool SendUpdateSign(Location sign, string line1, string line2, string line3, string line4, bool isFrontText = true)
{
try
{
@ -3965,6 +3970,8 @@ namespace MinecraftClient.Protocol.Handlers
List<byte> packet = new();
packet.AddRange(dataTypes.GetLocation(sign));
if(protocolVersion >= MC_1_20_Version)
packet.AddRange(dataTypes.GetBool((isFrontText)));
packet.AddRange(dataTypes.GetString(line1));
packet.AddRange(dataTypes.GetString(line2));
packet.AddRange(dataTypes.GetString(line3));

View file

@ -220,7 +220,7 @@ namespace MinecraftClient.Protocol
/// <param name="location">Location</param>
/// <param name="face">Block face</param>
/// <param name="sequenceId">Sequence ID (use for synchronization)</param>
/// <returns>True if packet was succcessfully sent</returns>
/// <returns>True if packet was successfully sent</returns>
bool SendPlayerDigging(int status, Location location, Direction face, int sequenceId);
/// <summary>
@ -231,8 +231,9 @@ namespace MinecraftClient.Protocol
/// <param name="line2">New line 2</param>
/// <param name="line3">New line 3</param>
/// <param name="line4">New line 4</param>
/// <returns>True if packet was succcessfully sent</returns>
bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4);
/// <param name="isFrontText">Are we editing the front or the back of the sign. 1.20 +</param>
/// <returns>True if packet was successfully sent</returns>
bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4, bool isFrontText = true);
/// <summary>
/// Update command block

View file

@ -134,7 +134,7 @@ namespace MinecraftClient.Protocol
if (Array.IndexOf(supportedVersions_Protocol16, ProtocolVersion) > -1)
return new Protocol16Handler(Client, ProtocolVersion, Handler);
int[] supportedVersions_Protocol18 = { 4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762 };
int[] supportedVersions_Protocol18 = { 4, 5, 47, 107, 108, 109, 110, 210, 315, 316, 335, 338, 340, 393, 401, 404, 477, 480, 485, 490, 498, 573, 575, 578, 735, 736, 751, 753, 754, 755, 756, 757, 758, 759, 760, 761, 762, 763 };
if (Array.IndexOf(supportedVersions_Protocol18, ProtocolVersion) > -1)
return new Protocol18Handler(Client, ProtocolVersion, Handler, forgeInfo);
@ -317,6 +317,8 @@ namespace MinecraftClient.Protocol
return 761;
case "1.19.4":
return 762;
case "1.20":
return 763;
default:
return 0;
}
@ -325,7 +327,7 @@ namespace MinecraftClient.Protocol
{
try
{
return Int32.Parse(MCVersion, NumberStyles.Any, CultureInfo.CurrentCulture);
return int.Parse(MCVersion, NumberStyles.Any, CultureInfo.CurrentCulture);
}
catch
{
@ -342,61 +344,62 @@ namespace MinecraftClient.Protocol
/// <returns>The 1.X.X version number, or 0.0 if could not determine protocol version</returns>
public static string ProtocolVersion2MCVer(int protocol)
{
switch (protocol)
return protocol switch
{
case 22: return "1.0";
case 23: return "1.1";
case 28: return "1.2.3";
case 29: return "1.2.5";
case 39: return "1.3.2";
22 => "1.0",
23 => "1.1",
28 => "1.2.3",
29 => "1.2.5",
39 => "1.3.2",
// case 47: return "1.4.2";
case 48: return "1.4.3";
case 49: return "1.4.5";
case 51: return "1.4.6";
case 60: return "1.5.1";
case 62: return "1.5.2";
case 72: return "1.6";
case 73: return "1.6.1";
case 3: return "1.7.1";
case 4: return "1.7.2";
case 5: return "1.7.6";
case 47: return "1.8";
case 107: return "1.9";
case 108: return "1.9.1";
case 109: return "1.9.2";
case 110: return "1.9.3";
case 210: return "1.10";
case 315: return "1.11";
case 316: return "1.11.1";
case 335: return "1.12";
case 338: return "1.12.1";
case 340: return "1.12.2";
case 393: return "1.13";
case 401: return "1.13.1";
case 404: return "1.13.2";
case 477: return "1.14";
case 480: return "1.14.1";
case 485: return "1.14.2";
case 490: return "1.14.3";
case 498: return "1.14.4";
case 573: return "1.15";
case 575: return "1.15.1";
case 578: return "1.15.2";
case 735: return "1.16";
case 736: return "1.16.1";
case 751: return "1.16.2";
case 753: return "1.16.3";
case 754: return "1.16.5";
case 755: return "1.17";
case 756: return "1.17.1";
case 757: return "1.18.1";
case 758: return "1.18.2";
case 759: return "1.19";
case 760: return "1.19.2";
case 761: return "1.19.3";
case 762: return "1.19.4";
default: return "0.0";
}
48 => "1.4.3",
49 => "1.4.5",
51 => "1.4.6",
60 => "1.5.1",
62 => "1.5.2",
72 => "1.6",
73 => "1.6.1",
3 => "1.7.1",
4 => "1.7.2",
5 => "1.7.6",
47 => "1.8",
107 => "1.9",
108 => "1.9.1",
109 => "1.9.2",
110 => "1.9.3",
210 => "1.10",
315 => "1.11",
316 => "1.11.1",
335 => "1.12",
338 => "1.12.1",
340 => "1.12.2",
393 => "1.13",
401 => "1.13.1",
404 => "1.13.2",
477 => "1.14",
480 => "1.14.1",
485 => "1.14.2",
490 => "1.14.3",
498 => "1.14.4",
573 => "1.15",
575 => "1.15.1",
578 => "1.15.2",
735 => "1.16",
736 => "1.16.1",
751 => "1.16.2",
753 => "1.16.3",
754 => "1.16.5",
755 => "1.17",
756 => "1.17.1",
757 => "1.18.1",
758 => "1.18.2",
759 => "1.19",
760 => "1.19.2",
761 => "1.19.3",
762 => "1.19.4",
763 => "1.20",
_ => "0.0"
};
}
/// <summary>