Merge branch 'MCCTeam:master' into forge-cmds

This commit is contained in:
oldkingOK 2024-03-10 08:07:01 +08:00 committed by GitHub
commit 79910b50f7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
28 changed files with 10032 additions and 5418 deletions

View file

@ -1221,16 +1221,16 @@ public class WebSocketBot : ChatBot
} }
public override void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type, public override void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type,
string json_) string json_, int numberFormat)
{ {
SendEvent("OnScoreboardObjective", SendEvent("OnScoreboardObjective",
new { objectiveName, mode, objectiveValue, type, rawJson = json_ }); new { objectiveName, mode, objectiveValue, type, rawJson = json_, numberFormat });
} }
public override void OnUpdateScore(string entityName, int action, string objectiveName, int value) public override void OnUpdateScore(string entityName, int action, string objectiveName, string objectiveDisplayName, int value, int numberFormat)
{ {
SendEvent("OnUpdateScore", SendEvent("OnUpdateScore",
new { entityName, action, objectiveName, type = value }); new { entityName, action, objectiveName, objectiveDisplayName, type = value, numberFormat });
} }
public override void OnInventoryUpdate(int inventoryId) public override void OnInventoryUpdate(int inventoryId)

File diff suppressed because it is too large Load diff

View file

@ -154,6 +154,7 @@
BrainCoralBlock, BrainCoralBlock,
BrainCoralFan, BrainCoralFan,
Bread, Bread,
BreezeSpawnEgg,
BrewerPotterySherd, BrewerPotterySherd,
BrewingStand, BrewingStand,
Brick, Brick,
@ -228,6 +229,7 @@
ChickenSpawnEgg, ChickenSpawnEgg,
ChippedAnvil, ChippedAnvil,
ChiseledBookshelf, ChiseledBookshelf,
ChiseledCopper,
ChiseledDeepslate, ChiseledDeepslate,
ChiseledNetherBricks, ChiseledNetherBricks,
ChiseledPolishedBlackstone, ChiseledPolishedBlackstone,
@ -235,6 +237,8 @@
ChiseledRedSandstone, ChiseledRedSandstone,
ChiseledSandstone, ChiseledSandstone,
ChiseledStoneBricks, ChiseledStoneBricks,
ChiseledTuff,
ChiseledTuffBricks,
ChorusFlower, ChorusFlower,
ChorusFruit, ChorusFruit,
ChorusPlant, ChorusPlant,
@ -274,8 +278,12 @@
CookedSalmon, CookedSalmon,
Cookie, Cookie,
CopperBlock, CopperBlock,
CopperBulb,
CopperDoor,
CopperGrate,
CopperIngot, CopperIngot,
CopperOre, CopperOre,
CopperTrapdoor,
Cornflower, Cornflower,
CowSpawnEgg, CowSpawnEgg,
CrackedDeepslateBricks, CrackedDeepslateBricks,
@ -283,6 +291,7 @@
CrackedNetherBricks, CrackedNetherBricks,
CrackedPolishedBlackstoneBricks, CrackedPolishedBlackstoneBricks,
CrackedStoneBricks, CrackedStoneBricks,
Crafter,
CraftingTable, CraftingTable,
CreeperBannerPattern, CreeperBannerPattern,
CreeperHead, CreeperHead,
@ -444,7 +453,12 @@
EvokerSpawnEgg, EvokerSpawnEgg,
ExperienceBottle, ExperienceBottle,
ExplorerPotterySherd, ExplorerPotterySherd,
ExposedChiseledCopper,
ExposedCopper, ExposedCopper,
ExposedCopperBulb,
ExposedCopperDoor,
ExposedCopperGrate,
ExposedCopperTrapdoor,
ExposedCutCopper, ExposedCutCopper,
ExposedCutCopperSlab, ExposedCutCopperSlab,
ExposedCutCopperStairs, ExposedCutCopperStairs,
@ -511,7 +525,7 @@
GraniteSlab, GraniteSlab,
GraniteStairs, GraniteStairs,
GraniteWall, GraniteWall,
Grass, Grass, // 1.20.3+ renamed to ShortGrass
GrassBlock, GrassBlock,
Gravel, Gravel,
GrayBanner, GrayBanner,
@ -826,7 +840,12 @@
OrangeTulip, OrangeTulip,
OrangeWool, OrangeWool,
OxeyeDaisy, OxeyeDaisy,
OxidizedChiseledCopper,
OxidizedCopper, OxidizedCopper,
OxidizedCopperBulb,
OxidizedCopperDoor,
OxidizedCopperGrate,
OxidizedCopperTrapdoor,
OxidizedCutCopper, OxidizedCutCopper,
OxidizedCutCopperSlab, OxidizedCutCopperSlab,
OxidizedCutCopperStairs, OxidizedCutCopperStairs,
@ -895,6 +914,10 @@
PolishedGranite, PolishedGranite,
PolishedGraniteSlab, PolishedGraniteSlab,
PolishedGraniteStairs, PolishedGraniteStairs,
PolishedTuff,
PolishedTuffSlab,
PolishedTuffStairs,
PolishedTuffWall,
PoppedChorusFruit, PoppedChorusFruit,
Poppy, Poppy,
Porkchop, Porkchop,
@ -1020,6 +1043,7 @@
SheepSpawnEgg, SheepSpawnEgg,
ShelterPotterySherd, ShelterPotterySherd,
Shield, Shield,
ShortGrass,
Shroomlight, Shroomlight,
ShulkerBox, ShulkerBox,
ShulkerShell, ShulkerShell,
@ -1156,6 +1180,8 @@
TotemOfUndying, TotemOfUndying,
TraderLlamaSpawnEgg, TraderLlamaSpawnEgg,
TrappedChest, TrappedChest,
TrialKey,
TrialSpawner,
Trident, Trident,
TripwireHook, TripwireHook,
TropicalFish, TropicalFish,
@ -1165,6 +1191,13 @@
TubeCoralBlock, TubeCoralBlock,
TubeCoralFan, TubeCoralFan,
Tuff, Tuff,
TuffBrickSlab,
TuffBrickStairs,
TuffBrickWall,
TuffBricks,
TuffSlab,
TuffStairs,
TuffWall,
TurtleEgg, TurtleEgg,
TurtleHelmet, TurtleHelmet,
TurtleSpawnEgg, TurtleSpawnEgg,
@ -1197,24 +1230,49 @@
WarpedTrapdoor, WarpedTrapdoor,
WarpedWartBlock, WarpedWartBlock,
WaterBucket, WaterBucket,
WaxedChiseledCopper,
WaxedCopperBlock, WaxedCopperBlock,
WaxedCopperBulb,
WaxedCopperDoor,
WaxedCopperGrate,
WaxedCopperTrapdoor,
WaxedCutCopper, WaxedCutCopper,
WaxedCutCopperSlab, WaxedCutCopperSlab,
WaxedCutCopperStairs, WaxedCutCopperStairs,
WaxedExposedChiseledCopper,
WaxedExposedCopper, WaxedExposedCopper,
WaxedExposedCopperBulb,
WaxedExposedCopperDoor,
WaxedExposedCopperGrate,
WaxedExposedCopperTrapdoor,
WaxedExposedCutCopper, WaxedExposedCutCopper,
WaxedExposedCutCopperSlab, WaxedExposedCutCopperSlab,
WaxedExposedCutCopperStairs, WaxedExposedCutCopperStairs,
WaxedOxidizedChiseledCopper,
WaxedOxidizedCopper, WaxedOxidizedCopper,
WaxedOxidizedCopperBulb,
WaxedOxidizedCopperDoor,
WaxedOxidizedCopperGrate,
WaxedOxidizedCopperTrapdoor,
WaxedOxidizedCutCopper, WaxedOxidizedCutCopper,
WaxedOxidizedCutCopperSlab, WaxedOxidizedCutCopperSlab,
WaxedOxidizedCutCopperStairs, WaxedOxidizedCutCopperStairs,
WaxedWeatheredChiseledCopper,
WaxedWeatheredCopper, WaxedWeatheredCopper,
WaxedWeatheredCopperBulb,
WaxedWeatheredCopperDoor,
WaxedWeatheredCopperGrate,
WaxedWeatheredCopperTrapdoor,
WaxedWeatheredCutCopper, WaxedWeatheredCutCopper,
WaxedWeatheredCutCopperSlab, WaxedWeatheredCutCopperSlab,
WaxedWeatheredCutCopperStairs, WaxedWeatheredCutCopperStairs,
WayfinderArmorTrimSmithingTemplate, WayfinderArmorTrimSmithingTemplate,
WeatheredChiseledCopper,
WeatheredCopper, WeatheredCopper,
WeatheredCopperBulb,
WeatheredCopperDoor,
WeatheredCopperGrate,
WeatheredCopperTrapdoor,
WeatheredCutCopper, WeatheredCutCopper,
WeatheredCutCopperSlab, WeatheredCutCopperSlab,
WeatheredCutCopperStairs, WeatheredCutCopperStairs,

File diff suppressed because it is too large Load diff

View file

@ -22,7 +22,7 @@ public abstract class EntityMetadataPalette
<= Protocol18Handler.MC_1_12_2_Version => new EntityMetadataPalette1122(), // 1.9 - 1.12.2 <= 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_2_Version => new EntityMetadataPalette1191(), // 1.13 - 1.19.2
<= Protocol18Handler.MC_1_19_3_Version => new EntityMetadataPalette1193(), // 1.19.3 <= Protocol18Handler.MC_1_19_3_Version => new EntityMetadataPalette1193(), // 1.19.3
<= Protocol18Handler.MC_1_20_2_Version => new EntityMetadataPalette1194(), // 1.19.4 - 1.20.2 + <= Protocol18Handler.MC_1_20_4_Version => new EntityMetadataPalette1194(), // 1.19.4 - 1.20.4 +
_ => throw new NotImplementedException() _ => throw new NotImplementedException()
}; };
} }

View file

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

View file

@ -11,7 +11,10 @@ namespace MinecraftClient.Mapping.EntityPalettes
/// Generate EntityType.cs from Minecraft registries.json /// Generate EntityType.cs from Minecraft registries.json
/// </summary> /// </summary>
/// <param name="registriesJsonFile">path to registries.json</param> /// <param name="registriesJsonFile">path to registries.json</param>
/// <remarks>java -cp minecraft_server.jar net.minecraft.data.Main --reports</remarks> /// <remarks>
/// java -cp minecraft_server.jar net.minecraft.data.Main --reports</remarks>
/// For 1.18+: java -DbundlerMainClass=net.minecraft.data.Main -jar minecraft_server.jar --reports
/// </remarks>
public static void GenerateEntityTypes(string registriesJsonFile) public static void GenerateEntityTypes(string registriesJsonFile)
{ {
DataTypeGenerator.GenerateEnumWithPalette(registriesJsonFile, "minecraft:entity_type", "EntityType", "MinecraftClient.Mapping", "EntityPalette", "MinecraftClient.Mapping.EntityPalettes"); DataTypeGenerator.GenerateEnumWithPalette(registriesJsonFile, "minecraft:entity_type", "EntityType", "MinecraftClient.Mapping", "EntityPalette", "MinecraftClient.Mapping.EntityPalettes");

View file

@ -24,6 +24,7 @@
Blaze, Blaze,
BlockDisplay, BlockDisplay,
Boat, Boat,
Breeze,
Camel, Camel,
Cat, Cat,
CaveSpider, CaveSpider,
@ -128,6 +129,7 @@
Vindicator, Vindicator,
WanderingTrader, WanderingTrader,
Warden, Warden,
WindCharge,
Witch, Witch,
Wither, Wither,
WitherSkeleton, WitherSkeleton,

View file

@ -198,6 +198,7 @@
Chest, Chest,
ChippedAnvil, ChippedAnvil,
ChiseledBookshelf, ChiseledBookshelf,
ChiseledCopper,
ChiseledDeepslate, ChiseledDeepslate,
ChiseledNetherBricks, ChiseledNetherBricks,
ChiseledPolishedBlackstone, ChiseledPolishedBlackstone,
@ -205,6 +206,8 @@
ChiseledRedSandstone, ChiseledRedSandstone,
ChiseledSandstone, ChiseledSandstone,
ChiseledStoneBricks, ChiseledStoneBricks,
ChiseledTuff,
ChiseledTuffBricks,
ChorusFlower, ChorusFlower,
ChorusPlant, ChorusPlant,
Clay, Clay,
@ -226,13 +229,18 @@
Composter, Composter,
Conduit, Conduit,
CopperBlock, CopperBlock,
CopperBulb,
CopperDoor,
CopperGrate,
CopperOre, CopperOre,
CopperTrapdoor,
Cornflower, Cornflower,
CrackedDeepslateBricks, CrackedDeepslateBricks,
CrackedDeepslateTiles, CrackedDeepslateTiles,
CrackedNetherBricks, CrackedNetherBricks,
CrackedPolishedBlackstoneBricks, CrackedPolishedBlackstoneBricks,
CrackedStoneBricks, CrackedStoneBricks,
Crafter,
CraftingTable, CraftingTable,
CreeperHead, CreeperHead,
CreeperWallHead, CreeperWallHead,
@ -367,7 +375,12 @@
EndStoneBrickWall, EndStoneBrickWall,
EndStoneBricks, EndStoneBricks,
EnderChest, EnderChest,
ExposedChiseledCopper,
ExposedCopper, ExposedCopper,
ExposedCopperBulb,
ExposedCopperDoor,
ExposedCopperGrate,
ExposedCopperTrapdoor,
ExposedCutCopper, ExposedCutCopper,
ExposedCutCopperSlab, ExposedCutCopperSlab,
ExposedCutCopperStairs, ExposedCutCopperStairs,
@ -396,7 +409,7 @@
GraniteSlab, GraniteSlab,
GraniteStairs, GraniteStairs,
GraniteWall, GraniteWall,
Grass, Grass, // 1.20.3+ renamed to ShortGrass
GrassBlock, GrassBlock,
Gravel, Gravel,
GrayBanner, GrayBanner,
@ -638,7 +651,12 @@
OrangeWallBanner, OrangeWallBanner,
OrangeWool, OrangeWool,
OxeyeDaisy, OxeyeDaisy,
OxidizedChiseledCopper,
OxidizedCopper, OxidizedCopper,
OxidizedCopperBulb,
OxidizedCopperDoor,
OxidizedCopperGrate,
OxidizedCopperTrapdoor,
OxidizedCutCopper, OxidizedCutCopper,
OxidizedCutCopperSlab, OxidizedCutCopperSlab,
OxidizedCutCopperStairs, OxidizedCutCopperStairs,
@ -697,6 +715,10 @@
PolishedGranite, PolishedGranite,
PolishedGraniteSlab, PolishedGraniteSlab,
PolishedGraniteStairs, PolishedGraniteStairs,
PolishedTuff,
PolishedTuffSlab,
PolishedTuffStairs,
PolishedTuffWall,
Poppy, Poppy,
Potatoes, Potatoes,
PottedAcaciaSapling, PottedAcaciaSapling,
@ -824,6 +846,7 @@
SeaLantern, SeaLantern,
SeaPickle, SeaPickle,
Seagrass, Seagrass,
ShortGrass,
Shroomlight, Shroomlight,
ShulkerBox, ShulkerBox,
SkeletonSkull, SkeletonSkull,
@ -924,6 +947,7 @@
Torchflower, Torchflower,
TorchflowerCrop, TorchflowerCrop,
TrappedChest, TrappedChest,
TrialSpawner,
Tripwire, Tripwire,
TripwireHook, TripwireHook,
TubeCoral, TubeCoral,
@ -931,6 +955,13 @@
TubeCoralFan, TubeCoralFan,
TubeCoralWallFan, TubeCoralWallFan,
Tuff, Tuff,
TuffBrickSlab,
TuffBrickStairs,
TuffBrickWall,
TuffBricks,
TuffSlab,
TuffStairs,
TuffWall,
TurtleEgg, TurtleEgg,
TwistingVines, TwistingVines,
TwistingVinesPlant, TwistingVinesPlant,
@ -959,23 +990,48 @@
WarpedWartBlock, WarpedWartBlock,
Water, Water,
WaterCauldron, WaterCauldron,
WaxedChiseledCopper,
WaxedCopperBlock, WaxedCopperBlock,
WaxedCopperBulb,
WaxedCopperDoor,
WaxedCopperGrate,
WaxedCopperTrapdoor,
WaxedCutCopper, WaxedCutCopper,
WaxedCutCopperSlab, WaxedCutCopperSlab,
WaxedCutCopperStairs, WaxedCutCopperStairs,
WaxedExposedChiseledCopper,
WaxedExposedCopper, WaxedExposedCopper,
WaxedExposedCopperBulb,
WaxedExposedCopperDoor,
WaxedExposedCopperGrate,
WaxedExposedCopperTrapdoor,
WaxedExposedCutCopper, WaxedExposedCutCopper,
WaxedExposedCutCopperSlab, WaxedExposedCutCopperSlab,
WaxedExposedCutCopperStairs, WaxedExposedCutCopperStairs,
WaxedOxidizedChiseledCopper,
WaxedOxidizedCopper, WaxedOxidizedCopper,
WaxedOxidizedCopperBulb,
WaxedOxidizedCopperDoor,
WaxedOxidizedCopperGrate,
WaxedOxidizedCopperTrapdoor,
WaxedOxidizedCutCopper, WaxedOxidizedCutCopper,
WaxedOxidizedCutCopperSlab, WaxedOxidizedCutCopperSlab,
WaxedOxidizedCutCopperStairs, WaxedOxidizedCutCopperStairs,
WaxedWeatheredChiseledCopper,
WaxedWeatheredCopper, WaxedWeatheredCopper,
WaxedWeatheredCopperBulb,
WaxedWeatheredCopperDoor,
WaxedWeatheredCopperGrate,
WaxedWeatheredCopperTrapdoor,
WaxedWeatheredCutCopper, WaxedWeatheredCutCopper,
WaxedWeatheredCutCopperSlab, WaxedWeatheredCutCopperSlab,
WaxedWeatheredCutCopperStairs, WaxedWeatheredCutCopperStairs,
WeatheredChiseledCopper,
WeatheredCopper, WeatheredCopper,
WeatheredCopperBulb,
WeatheredCopperDoor,
WeatheredCopperGrate,
WeatheredCopperTrapdoor,
WeatheredCutCopper, WeatheredCutCopper,
WeatheredCutCopperSlab, WeatheredCutCopperSlab,
WeatheredCutCopperStairs, WeatheredCutCopperStairs,

View file

@ -3414,29 +3414,32 @@ namespace MinecraftClient
} }
/// <summary> /// <summary>
/// Called when coreboardObjective /// Called when Soreboard Objective
/// </summary> /// </summary>
/// <param name="objectivename">objective name</param> /// <param name="objectiveName">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param> /// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param> /// <param name="objectiveValue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param> /// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
public void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type) /// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
public void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type, int numberFormat)
{ {
string json = objectivevalue; var json = objectiveValue;
objectivevalue = ChatParser.ParseText(objectivevalue); objectiveValue = ChatParser.ParseText(objectiveValue);
DispatchBotEvent(bot => bot.OnScoreboardObjective(objectivename, mode, objectivevalue, type, json)); DispatchBotEvent(bot => bot.OnScoreboardObjective(objectiveName, mode, objectiveValue, type, json, numberFormat));
} }
/// <summary> /// <summary>
/// Called when DisplayScoreboard /// Called when DisplayScoreboard
/// </summary> /// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param> /// <param name="entityName">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param> /// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param> /// <param name="objectiveName">The name of the objective the score belongs to</param>
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param> /// <param name="objectiveDisplayName">The name of the objective the score belongs to, but with chat formatting</param>
public void OnUpdateScore(string entityname, int action, string objectivename, int value) /// <param name="objectiveValue">The score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
/// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
public void OnUpdateScore(string entityName, int action, string objectiveName, string objectiveDisplayName, int objectiveValue, int numberFormat)
{ {
DispatchBotEvent(bot => bot.OnUpdateScore(entityname, action, objectivename, value)); DispatchBotEvent(bot => bot.OnUpdateScore(entityName, action, objectiveName, objectiveDisplayName, objectiveValue, numberFormat));
} }
/// <summary> /// <summary>

View file

@ -46,7 +46,7 @@ namespace MinecraftClient
public const string Version = MCHighestVersion; public const string Version = MCHighestVersion;
public const string MCLowestVersion = "1.4.6"; public const string MCLowestVersion = "1.4.6";
public const string MCHighestVersion = "1.20.2"; public const string MCHighestVersion = "1.20.4";
public static readonly string? BuildInfo = null; public static readonly string? BuildInfo = null;
private static Tuple<Thread, CancellationTokenSource>? offlinePrompt = null; private static Tuple<Thread, CancellationTokenSource>? offlinePrompt = null;

View file

@ -9,6 +9,7 @@ public enum ConfigurationPacketTypesIn
Ping, Ping,
RegistryData, RegistryData,
ResourcePack, ResourcePack,
RemoveResourcePack,
FeatureFlags, FeatureFlags,
UpdateTags, UpdateTags,

View file

@ -6,6 +6,7 @@ using MinecraftClient.Inventory;
using MinecraftClient.Inventory.ItemPalettes; using MinecraftClient.Inventory.ItemPalettes;
using MinecraftClient.Mapping; using MinecraftClient.Mapping;
using MinecraftClient.Mapping.EntityPalettes; using MinecraftClient.Mapping.EntityPalettes;
using MinecraftClient.Protocol.Message;
namespace MinecraftClient.Protocol.Handlers namespace MinecraftClient.Protocol.Handlers
{ {
@ -560,19 +561,38 @@ namespace MinecraftClient.Protocol.Handlers
cache.Dequeue(); cache.Dequeue();
return nbtData; return nbtData;
} }
if (cache.Peek() != 10) // TAG_Compound var nextId = cache.Dequeue();
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
ReadNextByte(cache); // Tag type (TAG_Compound)
if (protocolversion < Protocol18Handler.MC_1_20_2_Version) if (protocolversion < Protocol18Handler.MC_1_20_2_Version)
{ {
if (nextId is not 10) // TAG_Compound
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound");
// NBT root name // NBT root name
var rootName = Encoding.ASCII.GetString(ReadData(ReadNextUShort(cache), cache)); var rootName = Encoding.ASCII.GetString(ReadData(ReadNextUShort(cache), cache));
if (!string.IsNullOrEmpty(rootName)) if (!string.IsNullOrEmpty(rootName))
nbtData[""] = rootName; nbtData[""] = rootName;
} }
// In 1.20.2 The root TAG_Compound doesn't have a name
// In 1.20.3+ The root can be TAG_Compound or TAG_String
else
{
if (nextId is not (10 or 8)) // TAG_Compound or TAG_String
throw new System.IO.InvalidDataException("Failed to decode NBT: Does not start with TAG_Compound or TAG_String");
// Read TAG_String
if(nextId is 8)
{
var byteArrayLength = ReadNextUShort(cache);
var result = Encoding.UTF8.GetString(ReadData(byteArrayLength, cache));
return new Dictionary<string, object>()
{
{ "", result }
};
}
}
} }
while (true) while (true)
@ -666,7 +686,6 @@ namespace MinecraftClient.Protocol.Handlers
? key >> 5 // 1.8 ? key >> 5 // 1.8
: ReadNextVarInt(cache); // 1.9+ : ReadNextVarInt(cache); // 1.9+
EntityMetaDataType type; EntityMetaDataType type;
try try
{ {
@ -716,11 +735,11 @@ namespace MinecraftClient.Protocol.Handlers
value = ReadNextString(cache); value = ReadNextString(cache);
break; break;
case EntityMetaDataType.Chat: // Chat case EntityMetaDataType.Chat: // Chat
value = ReadNextString(cache); value = ReadNextChat(cache);
break; break;
case EntityMetaDataType.OptionalChat: // Optional Chat case EntityMetaDataType.OptionalChat: // Optional Chat
if (ReadNextBool(cache)) if (ReadNextBool(cache))
value = ReadNextString(cache); value = ReadNextChat(cache);
break; break;
case EntityMetaDataType.Slot: // Slot case EntityMetaDataType.Slot: // Slot
value = ReadNextItemSlot(cache, itemPalette); value = ReadNextItemSlot(cache, itemPalette);
@ -844,21 +863,21 @@ namespace MinecraftClient.Protocol.Handlers
/// </summary> /// </summary>
/// <param name="cache"></param> /// <param name="cache"></param>
/// <param name="itemPalette"></param> /// <param name="itemPalette"></param>
protected void ReadParticleData(Queue<byte> cache, ItemPalette itemPalette) public void ReadParticleData(Queue<byte> cache, ItemPalette itemPalette)
{ {
if (protocolversion < Protocol18Handler.MC_1_13_Version) if (protocolversion < Protocol18Handler.MC_1_13_Version)
return; return;
int ParticleID = ReadNextVarInt(cache); var particleId = ReadNextVarInt(cache);
// Refernece: // Documentation:
// 1.19.3 - https://wiki.vg/index.php?title=Data_types&oldid=17986 // 1.19.3+ - https://wiki.vg/index.php?title=Data_types&oldid=17986
// 1.18 - https://wiki.vg/index.php?title=Data_types&oldid=17180 // 1.18 - https://wiki.vg/index.php?title=Data_types&oldid=17180
// 1.17 - https://wiki.vg/index.php?title=Data_types&oldid=16740 // 1.17 - https://wiki.vg/index.php?title=Data_types&oldid=16740
// 1.15 - https://wiki.vg/index.php?title=Data_types&oldid=15338 // 1.15 - https://wiki.vg/index.php?title=Data_types&oldid=15338
// 1.13 - https://wiki.vg/index.php?title=Data_types&oldid=14271 // 1.13 - https://wiki.vg/index.php?title=Data_types&oldid=14271
switch (ParticleID) switch (particleId)
{ {
case 2: case 2:
// 1.18 + // 1.18 +
@ -866,14 +885,12 @@ namespace MinecraftClient.Protocol.Handlers
ReadNextVarInt(cache); // Block state (minecraft:block) ReadNextVarInt(cache); // Block state (minecraft:block)
break; break;
case 3: case 3:
if (protocolversion < Protocol18Handler.MC_1_17_Version if (protocolversion is < Protocol18Handler.MC_1_17_Version or > Protocol18Handler.MC_1_17_1_Version)
|| protocolversion > Protocol18Handler.MC_1_17_1_Version)
ReadNextVarInt( 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)
break; break;
case 4: case 4:
if (protocolversion == Protocol18Handler.MC_1_17_Version if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
|| protocolversion == Protocol18Handler.MC_1_17_1_Version)
ReadNextVarInt(cache); // Block State (minecraft:block) ReadNextVarInt(cache); // Block State (minecraft:block)
break; break;
case 11: case 11:
@ -883,44 +900,38 @@ namespace MinecraftClient.Protocol.Handlers
break; break;
case 14: case 14:
// 1.15 - 1.16.5 and 1.18 - 1.19.4 // 1.15 - 1.16.5 and 1.18 - 1.19.4
if ((protocolversion >= Protocol18Handler.MC_1_15_Version && if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version or > Protocol18Handler.MC_1_17_1_Version)
protocolversion < Protocol18Handler.MC_1_17_Version)
|| protocolversion > Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache); ReadDustParticle(cache);
break; break;
case 15: case 15:
if (protocolversion == Protocol18Handler.MC_1_17_Version || switch (protocolversion)
protocolversion == Protocol18Handler.MC_1_17_1_Version)
ReadDustParticle(cache);
else
{ {
if (protocolversion > Protocol18Handler.MC_1_17_1_Version) case Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version:
ReadDustParticle(cache);
break;
case > Protocol18Handler.MC_1_17_1_Version:
ReadDustParticleColorTransition(cache); ReadDustParticleColorTransition(cache);
break;
} }
break; break;
case 16: case 16:
if (protocolversion == Protocol18Handler.MC_1_17_Version || if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
protocolversion == Protocol18Handler.MC_1_17_1_Version)
ReadDustParticleColorTransition(cache); ReadDustParticleColorTransition(cache);
break; break;
case 23: case 23:
// 1.15 - 1.16.5 // 1.15 - 1.16.5
if (protocolversion >= Protocol18Handler.MC_1_15_Version && if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version)
protocolversion < Protocol18Handler.MC_1_17_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust) ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break; break;
case 24: case 24:
// 1.18 - 1.19.2 onwards // 1.18 - 1.19.2 onwards
if (protocolversion > Protocol18Handler.MC_1_17_1_Version && if (protocolversion is > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_19_3_Version)
protocolversion < Protocol18Handler.MC_1_19_3_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust) ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break; break;
case 25: case 25:
// 1.17 - 1.17.1 and 1.19.3 onwards // 1.17 - 1.17.1 and 1.19.3 onwards
if (protocolversion == Protocol18Handler.MC_1_17_Version if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version or >= Protocol18Handler.MC_1_19_3_Version)
|| protocolversion == Protocol18Handler.MC_1_17_1_Version
|| protocolversion >= Protocol18Handler.MC_1_19_3_Version)
ReadNextVarInt(cache); // Block State (minecraft:falling_dust) ReadNextVarInt(cache); // Block State (minecraft:falling_dust)
break; break;
case 27: case 27:
@ -934,31 +945,28 @@ namespace MinecraftClient.Protocol.Handlers
break; break;
case 32: case 32:
// 1.15 - 1.16.5 // 1.15 - 1.16.5
if (protocolversion >= Protocol18Handler.MC_1_15_Version && if (protocolversion is >= Protocol18Handler.MC_1_15_Version and < Protocol18Handler.MC_1_17_Version)
protocolversion < Protocol18Handler.MC_1_17_Version)
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item) ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
break; break;
case 36: case 36:
// 1.17 - 1.17.1 switch (protocolversion)
if (protocolversion == Protocol18Handler.MC_1_17_Version ||
protocolversion == Protocol18Handler.MC_1_17_1_Version)
{ {
ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item) // 1.17 - 1.17.1
} case Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version:
else if (protocolversion > Protocol18Handler.MC_1_17_1_Version && ReadNextItemSlot(cache, itemPalette); // Item (minecraft:item)
protocolversion < Protocol18Handler.MC_1_19_3_Version) break;
{ case > Protocol18Handler.MC_1_17_1_Version and < Protocol18Handler.MC_1_19_3_Version:
// minecraft:vibration // minecraft:vibration
ReadNextLocation(cache); // Origin (Starting Position) ReadNextLocation(cache); // Origin (Starting Position)
ReadNextLocation(cache); // Desitination (Ending Position) ReadNextLocation(cache); // Destination (Ending Position)
ReadNextVarInt(cache); // Ticks ReadNextVarInt(cache); // Ticks
break;
} }
break; break;
case 37: case 37:
// minecraft:vibration // minecraft:vibration
if (protocolversion == Protocol18Handler.MC_1_17_Version if (protocolversion is Protocol18Handler.MC_1_17_Version or Protocol18Handler.MC_1_17_1_Version)
|| protocolversion == Protocol18Handler.MC_1_17_1_Version)
{ {
ReadNextDouble(cache); // Origin X ReadNextDouble(cache); // Origin X
ReadNextDouble(cache); // Origin Y ReadNextDouble(cache); // Origin Y
@ -977,15 +985,16 @@ namespace MinecraftClient.Protocol.Handlers
case 40: case 40:
if (protocolversion >= Protocol18Handler.MC_1_19_3_Version) if (protocolversion >= Protocol18Handler.MC_1_19_3_Version)
{ {
string positionSourceType = ReadNextString(cache); var positionSourceType = ReadNextString(cache);
if (positionSourceType == "minecraft:block") switch (positionSourceType)
{ {
ReadNextLocation(cache); case "minecraft:block":
} ReadNextLocation(cache);
else if (positionSourceType == "minecraft:entity") break;
{ case "minecraft:entity":
ReadNextVarInt(cache); ReadNextVarInt(cache);
ReadNextFloat(cache); ReadNextFloat(cache);
break;
} }
ReadNextVarInt(cache); ReadNextVarInt(cache);
@ -1044,6 +1053,23 @@ namespace MinecraftClient.Protocol.Handlers
maximumNumberOfTradeUses, xp, specialPrice, priceMultiplier, demand); maximumNumberOfTradeUses, xp, specialPrice, priceMultiplier, demand);
} }
public string ReadNextChat(Queue<byte> cache)
{
if (protocolversion >= Protocol18Handler.MC_1_20_4_Version)
{
// Read as NBT
var r = ReadNextNbt(cache);
var msg = ChatParser.ParseText(r);
return msg;
}
else
{
// Read as String
var json = ReadNextString(cache);
return ChatParser.ParseText(json);
}
}
/// <summary> /// <summary>
/// Build an uncompressed Named Binary Tag blob for sending over the network /// Build an uncompressed Named Binary Tag blob for sending over the network
/// </summary> /// </summary>

View file

@ -143,32 +143,18 @@ namespace MinecraftClient.Protocol.Handlers.Forge
case FMLVersion.FML3: case FMLVersion.FML3:
// Example ModInfo for Minecraft 1.18 and greater (FML3) // Example ModInfo for Minecraft 1.18 and greater (FML3)
// { // "forgeData": {
// "enforcesSecureChat": true, // "channels": [],
// "forgeData": { // "mods": [],
// "channels": [], // "truncated": false, // legacy versions see truncated lists, modern versions ignore this truncated flag (binary data has its own)
// "mods": [], // "fmlNetworkVersion": 3,
// "truncated": false, // legacy versions see truncated lists, modern versions ignore this truncated flag (binary data has its own) // "d": "ȳ\u0000\u0000ࠨ㐤獋㙖⹌ᦘ̺⸱恤䒸⡑⛧沮婙㨹牥ఈㄵচ₀沮婙㨹牥ఈㄵচ倠⹡岙㜲獥䋊㷍᭳ႇׇ஌᜘㘴娘▅筳ص䰭宛㘲、\u0000ᠸጋ囗湌夜㘲杩棐䐱ᅱ挃☥ోᤗ㌮ఀ׈䬣 坖ɍ䮌ᤘ\r\n旉䠳ዣ◆䲌㜃瑥廮ⷉࠋ䁠奚Ҵ㔱摜䂸ᅱ獳ౠᡚ㜷汥戊䂸űဓĠ嵛㖱数嫤Ǎ塰䛶ⶎᮚ㞳晲擞ᖝ″ዣ䘆ఋʂ潦令ඕ爈䖔⺁ᥚ⾹潳棤㦥ᬻ挐؅䅀㠹楬ۨ㣄উ瀀渀嬛㘼扩搢䃀熁挂♥\r\n墋㒺摬牜ࣜ䁠嘗湌孛㜴浩惂䠙熙排٥孁㒰ͮ屢Ӏ䠐⚐䷮ᣛ㊴瑳戚䢸熁匒إ஍᜚ܴ䫜巑፻ؠ䀀ㆃ牵䋨㦥ࠫ㋣䗆䂌㨈慲䫬ᖱᮓᘧ汬尚ㆰ٫屲㣄ᆉ恳ಭ川㤷፫擨妅挫♖乮塘 㖱慰\r\n囆䓩\t"
// "fmlNetworkVersion": 3, // }
// "d": "ȳ\u0000\u0000ࠨ㐤獋㙖⹌ᦘ̺⸱恤䒸⡑⛧沮婙㨹牥ఈㄵচ₀沮婙㨹牥ఈㄵচ倠⹡岙㜲獥䋊㷍᭳ႇׇ஌᜘㘴娘▅筳ص䰭宛㘲、\u0000ᠸጋ囗湌夜㘲杩棐䐱ᅱ挃☥ోᤗ㌮ఀ׈䬣 坖ɍ䮌ᤘ\r\n旉䠳ዣ◆䲌㜃瑥廮ⷉࠋ䁠奚Ҵ㔱摜䂸ᅱ獳ౠᡚ㜷汥戊䂸űဓĠ嵛㖱数嫤Ǎ塰䛶ⶎᮚ㞳晲擞ᖝ″ዣ䘆ఋʂ潦令ඕ爈䖔⺁ᥚ⾹潳棤㦥ᬻ挐؅䅀㠹楬ۨ㣄উ瀀渀嬛㘼扩搢䃀熁挂♥\r\n墋㒺摬牜ࣜ䁠嘗湌孛㜴浩惂䠙熙排٥孁㒰ͮ屢Ӏ䠐⚐䷮ᣛ㊴瑳戚䢸熁匒إ஍᜚ܴ䫜巑፻ؠ䀀ㆃ牵䋨㦥ࠫ㋣䗆䂌㨈慲䫬ᖱᮓᘧ汬尚ㆰ٫屲㣄ᆉ恳ಭ川㤷፫擨妅挫♖乮塘 㖱慰\r\n囆䓩\t"
// },
// "description": {
// "text": "A Minecraft Server"
// },
// "players": {
// "max": 100,
// "online": 0
// },
// "version": {
// "name": "1.20.1",
// "protocol": 763
// }
// }
// All buffer data are encoded and write to forgeData["d"] // 1.18 and greater, the mod list and channel list is compressed to forgeData["d"] for efficiency,
// - Here is how forge encode and decode them:
// https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/ServerStatusPing.java#L264 // https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/ServerStatusPing.java#L264
// - Here is the discussion:
// 1.18 and greater, the buffer is encoded for efficiency
// see https://github.com/MinecraftForge/MinecraftForge/pull/8169 // see https://github.com/MinecraftForge/MinecraftForge/pull/8169
string encodedData = data.Properties["d"].StringValue; string encodedData = data.Properties["d"].StringValue;
@ -176,14 +162,21 @@ namespace MinecraftClient.Protocol.Handlers.Forge
DataTypes dataTypes = new DataTypes(Protocol18Handler.MC_1_18_1_Version); DataTypes dataTypes = new DataTypes(Protocol18Handler.MC_1_18_1_Version);
// //
// [truncated][boolean] placeholder for whether we are truncating // [ Truncated ][ Bool ] // Unused
// [Mod Size][unsigned short] short so that we can replace it later in case of truncation // [ Mod Size ][ Unsigned short ]
// //
bool truncated = dataTypes.ReadNextBool(dataPackage); dataTypes.ReadNextBool(dataPackage); // truncated: boolean
var modsSize = dataTypes.ReadNextUShort(dataPackage); var modsSize = dataTypes.ReadNextUShort(dataPackage);
Dictionary<string, string> channels = new();
Dictionary<string, string> mods = new(); Dictionary<string, string> mods = new();
// Mod Array Definition:
// [ Channel Size And Version Flag ][ VarInt ] // If the value at bit Mask 0x01 is 1, The Mod Version will be ignore.
// // The one-right-shifted int is the Channel List size.
// [ Mod Id ][ String ]
// [ Mod Version ][ Optional String ] // Depends on the Flag above
// [ Channel List ][ Array ] [ Channel Name ][ String ]
// [ Channel Version ][ String ]
// [ Required On Client ][ Bool ]
for (var i = 0; i < modsSize; i++) { for (var i = 0; i < modsSize; i++) {
var channelSizeAndVersionFlag = dataTypes.ReadNextVarInt(dataPackage); var channelSizeAndVersionFlag = dataTypes.ReadNextVarInt(dataPackage);
@ -194,27 +187,24 @@ namespace MinecraftClient.Protocol.Handlers.Forge
var modId = dataTypes.ReadNextString(dataPackage); var modId = dataTypes.ReadNextString(dataPackage);
string IGNORESERVERONLY = "";// it was "OHNOES\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31\uD83D\uDE31"; string IGNORESERVERONLY = "IGNORED";
var modVersion = isIgnoreServerOnly ? IGNORESERVERONLY : dataTypes.ReadNextString(dataPackage); var modVersion = isIgnoreServerOnly ? IGNORESERVERONLY : dataTypes.ReadNextString(dataPackage);
for (var i1 = 0; i1 < channelSize; i1++) { for (var i1 = 0; i1 < channelSize; i1++) {
var channelName = dataTypes.ReadNextString(dataPackage); dataTypes.ReadNextString(dataPackage); // channelName
var channelVersion = dataTypes.ReadNextString(dataPackage); dataTypes.ReadNextString(dataPackage); // channelVersion
var requiredOnClient = dataTypes.ReadNextBool(dataPackage); dataTypes.ReadNextBool(dataPackage); // requiredOnClient
channels.Add(modId + ":" + channelName, channelVersion + ":" + requiredOnClient);
} }
mods.Add(modId, modVersion); mods.Add(modId, modVersion);
Mods.Add(new ForgeMod(modId, modVersion)); Mods.Add(new ForgeMod(modId, modVersion));
} }
var nonModChannelCount = dataTypes.ReadNextVarInt(dataPackage); // Ignore the left data, which is NonMod Channel List
for (var i = 0; i < nonModChannelCount; i++) { // [ nonMod Channel Count ][ VarInt ]
var channelName = dataTypes.ReadNextString(dataPackage); // [ nonMod Channel List ][ Array ] [ Channel Name ][ String ]
var channelVersion = dataTypes.ReadNextString(dataPackage); // [ Channel Version ][ Bool ]
var requiredOnClient = dataTypes.ReadNextBool(dataPackage); // [ Required On Client ][ Bool ]
channels.Add(channelName, channelVersion + ":" + requiredOnClient);
}
break; break;
default: default:
@ -222,10 +212,17 @@ namespace MinecraftClient.Protocol.Handlers.Forge
} }
} }
// https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/ServerStatusPing.java#L361 /// <summary>
// Decode binary data ForgeData["d"] to Queue<byte> /// Decompress binary data ForgeData["d"] (FML 3)
/// </summary>
/// <param name="encodedData">The encoded data.</param>
/// <returns>Decoded forge data Queue<byte>.</returns>
/// <para>
/// 1.18 and greater, the mod list and channel list is compressed for efficiency
/// The code below is converted from forge source code, see:
/// https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/ServerStatusPing.java#L361
/// </para>
private static Queue<byte> decodeOptimized(string encodedData) { private static Queue<byte> decodeOptimized(string encodedData) {
// Console.WriteLine("Got encoded data:" + encodedData + ", decoding...");
int size0 = encodedData[0]; int size0 = encodedData[0];
int size1 = encodedData[1]; int size1 = encodedData[1];
int size = size0 | (size1 << 15); int size = size0 | (size1 << 15);

View file

@ -73,7 +73,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
50 => new ParserForgeEnum(dataTypes, packetData), 50 => new ParserForgeEnum(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData), _ => new ParserEmpty(dataTypes, packetData),
}; };
else // 1.19.4+ else if (protocolVersion <= Protocol18Handler.MC_1_20_2_Version)// 1.19.4 - 1.20.2
parser = parserId switch parser = parserId switch
{ {
1 => new ParserFloat(dataTypes, packetData), 1 => new ParserFloat(dataTypes, packetData),
@ -103,11 +103,34 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
new ParserEmpty(dataTypes, packetData), new ParserEmpty(dataTypes, packetData),
_ => new ParserEmpty(dataTypes, packetData), _ => new ParserEmpty(dataTypes, packetData),
}; };
else // 1.20.3+
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),
8 => new ParserBlockPos(dataTypes, packetData),
9 => new ParserColumnPos(dataTypes, packetData),
10 => new ParserVec3(dataTypes, packetData),
11 => new ParserVec2(dataTypes, packetData),
18 => new ParserMessage(dataTypes, packetData),
27 => new ParserRotation(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),
_ => new ParserEmpty(dataTypes, packetData),
};
} }
string? suggestionsType = ((flags & 0x10) == 0x10) ? dataTypes.ReadNextString(packetData) : null; string? suggestionsType = ((flags & 0x10) == 0x10) ? dataTypes.ReadNextString(packetData) : null;
Nodes[i] = new(flags, childs, redirectNode, name, parser, suggestionsType); Nodes[i] = new(flags, childs, redirectNode, name, parser, suggestionsType, parserId);
} }
RootIdx = dataTypes.ReadNextVarInt(packetData); RootIdx = dataTypes.ReadNextVarInt(packetData);
@ -183,6 +206,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
public string? Name; public string? Name;
public Parser? Paser; public Parser? Paser;
public string? SuggestionsType; public string? SuggestionsType;
public int ParserId; // Added for easy debug
public CommandNode(byte Flags, public CommandNode(byte Flags,
@ -190,7 +214,8 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
int RedirectNode = -1, int RedirectNode = -1,
string? Name = null, string? Name = null,
Parser? Paser = null, Parser? Paser = null,
string? SuggestionsType = null) string? SuggestionsType = null,
int parserId = -1)
{ {
this.Flags = Flags; this.Flags = Flags;
this.Clildren = Clildren; this.Clildren = Clildren;
@ -198,6 +223,7 @@ namespace MinecraftClient.Protocol.Handlers.packet.s2c
this.Name = Name; this.Name = Name;
this.Paser = Paser; this.Paser = Paser;
this.SuggestionsType = SuggestionsType; this.SuggestionsType = SuggestionsType;
ParserId = parserId;
} }
} }

View file

@ -0,0 +1,215 @@
using System.Collections.Generic;
namespace MinecraftClient.Protocol.Handlers.PacketPalettes;
public class PacketPalette1204 : PacketTypePalette
{
private readonly Dictionary<int, PacketTypesIn> typeIn = new()
{
{ 0x00, PacketTypesIn.Bundle }, // Added in 1.19.4
{ 0x01, PacketTypesIn.SpawnEntity }, // Changed in 1.19 (Wiki name: Spawn Entity)
{ 0x02, PacketTypesIn.SpawnExperienceOrb }, // (Wiki name: Spawn Exeprience Orb)
{ 0x03, PacketTypesIn.EntityAnimation }, // (Wiki name: Entity Animation (clientbound))
{ 0x04, PacketTypesIn.Statistics }, // (Wiki name: Award Statistics)
{ 0x05, PacketTypesIn.BlockChangedAck }, // Added 1.19 (Wiki name: Acknowledge Block Change)
{ 0x06, PacketTypesIn.BlockBreakAnimation }, // (Wiki name: Set Block Destroy Stage)
{ 0x07, PacketTypesIn.BlockEntityData }, //
{ 0x08, PacketTypesIn.BlockAction }, //
{ 0x09, PacketTypesIn.BlockChange }, // (Wiki name: Block Update)
{ 0x0A, PacketTypesIn.BossBar }, //
{ 0x0B, PacketTypesIn.ServerDifficulty }, // (Wiki name: Change Difficulty)
{ 0x0C, PacketTypesIn.ChunkBatchFinished }, // Added in 1.20.2
{ 0x0D, PacketTypesIn.ChunkBatchStarted }, // Added in 1.20.2
{ 0x0E, PacketTypesIn.ChunksBiomes }, // Added in 1.19.4
{ 0x0F, PacketTypesIn.ClearTiles }, //
{ 0x10, PacketTypesIn.TabComplete }, // (Wiki name: Command Suggestions Response)
{ 0x11, PacketTypesIn.DeclareCommands }, // (Wiki name: Commands)
{ 0x12, PacketTypesIn.CloseWindow }, // (Wiki name: Close Container (clientbound))
{ 0x13, PacketTypesIn.WindowItems }, // (Wiki name: Set Container Content)
{ 0x14, PacketTypesIn.WindowProperty }, // (Wiki name: Set Container Property)
{ 0x15, PacketTypesIn.SetSlot }, // (Wiki name: Set Container Slot)
{ 0x16, PacketTypesIn.SetCooldown }, //
{ 0x17, PacketTypesIn.ChatSuggestions }, // Added in 1.19.1
{ 0x18, PacketTypesIn.PluginMessage }, // (Wiki name: Plugin Message (clientbound))
{ 0x19, PacketTypesIn.DamageEvent }, // Added in 1.19.4
{ 0x1A, PacketTypesIn.HideMessage }, // Added in 1.19.1
{ 0x1B, PacketTypesIn.Disconnect }, //
{ 0x1C, PacketTypesIn.ProfilelessChatMessage }, // Added in 1.19.3 (Wiki name: Disguised Chat Message)
{ 0x1D, PacketTypesIn.EntityStatus }, // (Wiki name: Entity Event)
{ 0x1E, PacketTypesIn.Explosion }, // Changed in 1.19 (Location fields are now Double instead of Float) (Wiki name: Explosion)
{ 0x1F, PacketTypesIn.UnloadChunk }, // (Wiki name: Forget Chunk)
{ 0x20, PacketTypesIn.ChangeGameState }, // (Wiki name: Game Event)
{ 0x21, PacketTypesIn.OpenHorseWindow }, // (Wiki name: Horse Screen Open)
{ 0x22, PacketTypesIn.HurtAnimation }, // Added in 1.19.4
{ 0x23, PacketTypesIn.InitializeWorldBorder }, //
{ 0x24, PacketTypesIn.KeepAlive }, //
{ 0x25, PacketTypesIn.ChunkData }, //
{ 0x26, PacketTypesIn.Effect }, // (Wiki name: World Event)
{ 0x27, PacketTypesIn.Particle }, // Changed in 1.19 (Wiki name: Level Particle) (No need to be implemented)
{ 0x28, PacketTypesIn.UpdateLight }, // (Wiki name: Light Update)
{ 0x29, PacketTypesIn.JoinGame }, // Changed in 1.20.2 (Wiki name: Login (play))
{ 0x2A, PacketTypesIn.MapData }, // (Wiki name: Map Item Data)
{ 0x2B, PacketTypesIn.TradeList }, // (Wiki name: Merchant Offers)
{ 0x2C, PacketTypesIn.EntityPosition }, // (Wiki name: Move Entity Position)
{ 0x2D, PacketTypesIn.EntityPositionAndRotation }, // (Wiki name: Move Entity Position and Rotation)
{ 0x2E, PacketTypesIn.EntityRotation }, // (Wiki name: Move Entity Rotation)
{ 0x2F, PacketTypesIn.VehicleMove }, // (Wiki name: Move Vehicle)
{ 0x30, PacketTypesIn.OpenBook }, //
{ 0x31, PacketTypesIn.OpenWindow }, // (Wiki name: Open Screen)
{ 0x32, PacketTypesIn.OpenSignEditor }, //
{ 0x33, PacketTypesIn.Ping }, // (Wiki name: Ping (play))
{ 0x34, PacketTypesIn.PingResponse }, // Added in 1.20.2
{ 0x35, PacketTypesIn.CraftRecipeResponse }, // (Wiki name: Place Ghost Recipe)
{ 0x36, PacketTypesIn.PlayerAbilities }, //
{ 0x37, PacketTypesIn.ChatMessage }, // Changed in 1.19 (Completely changed) (Wiki name: Player Chat Message)
{ 0x38, PacketTypesIn.EndCombatEvent }, // (Wiki name: End Combat)
{ 0x39, PacketTypesIn.EnterCombatEvent }, // (Wiki name: Enter Combat)
{ 0x3A, PacketTypesIn.DeathCombatEvent }, // (Wiki name: Combat Death)
{ 0x3B, PacketTypesIn.PlayerRemove }, // Added in 1.19.3 (Not used)
{ 0x3C, PacketTypesIn.PlayerInfo }, // Changed in 1.19 (Heavy changes)
{ 0x3D, PacketTypesIn.FacePlayer }, // (Wiki name: Player Look At)
{ 0x3E, PacketTypesIn.PlayerPositionAndLook }, // (Wiki name: Synchronize Player Position)
{ 0x3F, PacketTypesIn.UnlockRecipes }, // (Wiki name: Update Recipe Book)
{ 0x40, PacketTypesIn.DestroyEntities }, // (Wiki name: Remove Entites)
{ 0x41, PacketTypesIn.RemoveEntityEffect }, //
{ 0x42, PacketTypesIn.ResetScore }, // Added in 1.20.3
{ 0x43, PacketTypesIn.RemoveResourcePack }, // Added in 1.20.3
{ 0x44, PacketTypesIn.ResourcePackSend }, // (Wiki name: Add Resource pack (play))
{ 0x45, PacketTypesIn.Respawn }, // Changed in 1.20.2
{ 0x46, PacketTypesIn.EntityHeadLook }, // (Wiki name: Set Head Rotation)
{ 0x47, PacketTypesIn.MultiBlockChange }, // (Wiki name: Update Section Blocks)
{ 0x48, PacketTypesIn.SelectAdvancementTab }, //
{ 0x49, PacketTypesIn.ServerData }, // Added in 1.19
{ 0x4A, PacketTypesIn.ActionBar }, // (Wiki name: Set Action Bar Text)
{ 0x4B, PacketTypesIn.WorldBorderCenter }, // (Wiki name: Set Border Center)
{ 0x4C, PacketTypesIn.WorldBorderLerpSize }, //
{ 0x4D, PacketTypesIn.WorldBorderSize }, // (Wiki name: Set World Border Size)
{ 0x4E, PacketTypesIn.WorldBorderWarningDelay }, // (Wiki name: Set World Border Warning Delay)
{ 0x4F, PacketTypesIn.WorldBorderWarningReach }, // (Wiki name: Set Border Warning Distance)
{ 0x50, PacketTypesIn.Camera }, // (Wiki name: Set Camera)
{ 0x51, PacketTypesIn.HeldItemChange }, // (Wiki name: Set Held Item)
{ 0x52, PacketTypesIn.UpdateViewPosition }, // (Wiki name: Set Center Chunk)
{ 0x53, PacketTypesIn.UpdateViewDistance }, // (Wiki name: Set Render Distance)
{ 0x54, PacketTypesIn.SpawnPosition }, // (Wiki name: Set Default Spawn Position)
{ 0x55, PacketTypesIn.DisplayScoreboard }, // (Wiki name: Set Display Objective)
{ 0x56, PacketTypesIn.EntityMetadata }, // (Wiki name: Set Entity Metadata)
{ 0x57, PacketTypesIn.AttachEntity }, // (Wiki name: Link Entities)
{ 0x58, PacketTypesIn.EntityVelocity }, // (Wiki name: Set Entity Velocity)
{ 0x59, PacketTypesIn.EntityEquipment }, // (Wiki name: Set Equipment)
{ 0x5A, PacketTypesIn.SetExperience }, // Changed in 1.20.2
{ 0x5B, PacketTypesIn.UpdateHealth }, // (Wiki name: Set Health)
{ 0x5C, PacketTypesIn.ScoreboardObjective }, // (Wiki name: Update Objectives) - Changed in 1.20.3
{ 0x5D, PacketTypesIn.SetPassengers }, //
{ 0x5E, PacketTypesIn.Teams }, // (Wiki name: Update Teams)
{ 0x5F, PacketTypesIn.UpdateScore }, // (Wiki name: Update Score)
{ 0x60, PacketTypesIn.UpdateSimulationDistance }, // (Wiki name: Set Simulation Distance)
{ 0x61, PacketTypesIn.SetTitleSubTitle }, // (Wiki name: Set Subtitle Test)
{ 0x62, PacketTypesIn.TimeUpdate }, // (Wiki name: Set Time)
{ 0x63, PacketTypesIn.SetTitleText }, // (Wiki name: Set Title)
{ 0x64, PacketTypesIn.SetTitleTime }, // (Wiki name: Set Title Animation Times)
{ 0x65, PacketTypesIn.EntitySoundEffect }, // (Wiki name: Sound Entity)
{ 0x66, PacketTypesIn.SoundEffect }, // Changed in 1.19 (Added "Seed" field) (Wiki name: Sound Effect) (No need to be implemented)
{ 0x67, PacketTypesIn.StartConfiguration }, // Added in 1.20.2
{ 0x68, PacketTypesIn.StopSound }, //
{ 0x69, PacketTypesIn.SystemChat }, // Added in 1.19 (Wiki name: System Chat Message)
{ 0x6A, PacketTypesIn.PlayerListHeaderAndFooter }, // (Wiki name: Set Tab List Header And Footer)
{ 0x6B, PacketTypesIn.NBTQueryResponse }, // (Wiki name: Tag Query Response)
{ 0x6C, PacketTypesIn.CollectItem }, // (Wiki name: Pickup Item)
{ 0x6D, PacketTypesIn.EntityTeleport }, // (Wiki name: Teleport Entity)
{ 0x6E, PacketTypesIn.SetTickingState }, // Added in 1.20.3
{ 0x6F, PacketTypesIn.StepTick }, // Added in 1.20.3
{ 0x70, PacketTypesIn.Advancements }, // (Wiki name: Update Advancements) (Unused)
{ 0x71, PacketTypesIn.EntityProperties }, // (Wiki name: Update Attributes)
{ 0x72, PacketTypesIn.EntityEffect }, // Changed in 1.19 (Added "Has Factor Data" and "Factor Codec" fields) (Wiki name: Entity Effect)
{ 0x73, PacketTypesIn.DeclareRecipes }, // (Wiki name: Update Recipes) (Unused)
{ 0x74, PacketTypesIn.Tags }, // (Wiki name: Update Tags)
};
private readonly Dictionary<int, PacketTypesOut> typeOut = new()
{
{ 0x00, PacketTypesOut.TeleportConfirm }, // (Wiki name: Confirm Teleportation)
{ 0x01, PacketTypesOut.QueryBlockNBT }, // (Wiki name: Query Block Entity Tag)
{ 0x02, PacketTypesOut.SetDifficulty }, // (Wiki name: Change Difficulty)
{ 0x03, PacketTypesOut.MessageAcknowledgment }, // Added in 1.19.1
{ 0x04, PacketTypesOut.ChatCommand }, // Added in 1.19
{ 0x05, PacketTypesOut.ChatMessage }, // Changed in 1.19 (Completely changed) (Wiki name: Chat)
{ 0x06, PacketTypesOut.PlayerSession }, // Added in 1.19.3
{ 0x07, PacketTypesOut.ChunkBatchReceived }, // Added in 1.20.2
{ 0x08, PacketTypesOut.ClientStatus }, // (Wiki name: Client Command)
{ 0x09, PacketTypesOut.ClientSettings }, // (Wiki name: Client Information)
{ 0x0A, PacketTypesOut.TabComplete }, // (Wiki name: Command Suggestions Request)
{ 0x0B, PacketTypesOut.AcknowledgeConfiguration }, // Added in 1.20.2
{ 0x0C, PacketTypesOut.ClickWindowButton }, // (Wiki name: Click Container Button)
{ 0x0D, PacketTypesOut.ClickWindow }, // (Wiki name: Click Container)
{ 0x0E, PacketTypesOut.CloseWindow }, // (Wiki name: Close Container (serverbound))
{ 0x0F, PacketTypesOut.ChangeContainerSlotState }, // Added in 1.20.3
{ 0x10, PacketTypesOut.PluginMessage }, // (Wiki name: Serverbound Plugin Message)
{ 0x11, PacketTypesOut.EditBook }, //
{ 0x12, PacketTypesOut.EntityNBTRequest }, // (Wiki name: Query Entity Tag)
{ 0x13, PacketTypesOut.InteractEntity }, // (Wiki name: Interact)
{ 0x14, PacketTypesOut.GenerateStructure }, // (Wiki name: Jigsaw Generate)
{ 0x15, PacketTypesOut.KeepAlive }, // (Wiki name: Serverbound Keep Alive (play))
{ 0x16, PacketTypesOut.LockDifficulty }, //
{ 0x17, PacketTypesOut.PlayerPosition }, // (Wiki name: Move Player Position)
{ 0x18, PacketTypesOut.PlayerPositionAndRotation }, // (Wiki name: Set Player Position and Rotation)
{ 0x19, PacketTypesOut.PlayerRotation }, // (Wiki name: Set Player Rotation)
{ 0x1A, PacketTypesOut.PlayerMovement }, // (Wiki name: Set Player On Ground)
{ 0x1B, PacketTypesOut.VehicleMove }, // (Wiki name: Move Vehicle (serverbound))
{ 0x1C, PacketTypesOut.SteerBoat }, // (Wiki name: Paddle Boat)
{ 0x1D, PacketTypesOut.PickItem }, //
{ 0x1E, PacketTypesOut.PingRequest }, // Added in 1.20.2
{ 0x1F, PacketTypesOut.CraftRecipeRequest }, // (Wiki name: Place recipe)
{ 0x20, PacketTypesOut.PlayerAbilities }, //
{ 0x21, PacketTypesOut.PlayerDigging }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Player Action)
{ 0x22, PacketTypesOut.EntityAction }, // (Wiki name: Player Command)
{ 0x23, PacketTypesOut.SteerVehicle }, // (Wiki name: Player Input)
{ 0x24, PacketTypesOut.Pong }, // (Wiki name: Pong (play))
{ 0x25, PacketTypesOut.SetDisplayedRecipe }, // (Wiki name: Recipe Book Change Settings)
{ 0x26, PacketTypesOut.SetRecipeBookState }, // (Wiki name: Recipe Book Seen Recipe)
{ 0x27, PacketTypesOut.NameItem }, // (Wiki name: Rename Item)
{ 0x28, PacketTypesOut.ResourcePackStatus }, // (Wiki name: Resource Pack (serverbound))
{ 0x29, PacketTypesOut.AdvancementTab }, // (Wiki name: Seen Advancements)
{ 0x2A, PacketTypesOut.SelectTrade }, //
{ 0x2B, PacketTypesOut.SetBeaconEffect }, // Changed in 1.19 (No need to be implemented yet)
{ 0x2C, PacketTypesOut.HeldItemChange }, // (Wiki name: Set Carried Item (serverbound))
{ 0x2D, PacketTypesOut.UpdateCommandBlock }, // (Wiki name: Program Command Block)
{ 0x2E, PacketTypesOut.UpdateCommandBlockMinecart }, // (Wiki name: Program Command Block Minecart)
{ 0x2F, PacketTypesOut.CreativeInventoryAction }, // (Wiki name: Set Creative Mode Slot)
{ 0x30, PacketTypesOut.UpdateJigsawBlock }, // (Wiki name: Program Jigsaw Block)
{ 0x31, PacketTypesOut.UpdateStructureBlock }, // (Wiki name: Program Structure Block)
{ 0x32, PacketTypesOut.UpdateSign }, // (Wiki name: Update Sign)
{ 0x33, PacketTypesOut.Animation }, // (Wiki name: Swing Arm)
{ 0x34, PacketTypesOut.Spectate }, // (Wiki name: Teleport To Entity)
{ 0x35, PacketTypesOut.PlayerBlockPlacement }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Use Item On)
{ 0x36, PacketTypesOut.UseItem }, // Changed in 1.19 (Added a "Sequence" field) (Wiki name: Use Item)
};
private readonly Dictionary<int, ConfigurationPacketTypesIn> configurationTypesIn = new()
{
{ 0x00, ConfigurationPacketTypesIn.PluginMessage },
{ 0x01, ConfigurationPacketTypesIn.Disconnect },
{ 0x02, ConfigurationPacketTypesIn.FinishConfiguration },
{ 0x03, ConfigurationPacketTypesIn.KeepAlive },
{ 0x04, ConfigurationPacketTypesIn.Ping },
{ 0x05, ConfigurationPacketTypesIn.RegistryData },
{ 0x06, ConfigurationPacketTypesIn.RemoveResourcePack },
{ 0x07, ConfigurationPacketTypesIn.ResourcePack },
{ 0x08, ConfigurationPacketTypesIn.FeatureFlags },
{ 0x09, ConfigurationPacketTypesIn.UpdateTags },
};
private readonly Dictionary<int, ConfigurationPacketTypesOut> configurationTypesOut = new()
{
{ 0x00, ConfigurationPacketTypesOut.ClientInformation },
{ 0x01, ConfigurationPacketTypesOut.PluginMessage },
{ 0x02, ConfigurationPacketTypesOut.FinishConfiguration },
{ 0x03, ConfigurationPacketTypesOut.KeepAlive },
{ 0x04, ConfigurationPacketTypesOut.Pong },
{ 0x05, ConfigurationPacketTypesOut.ResourcePackResponse }
};
protected override Dictionary<int, PacketTypesIn> GetListIn() => typeIn;
protected override Dictionary<int, PacketTypesOut> GetListOut() => typeOut;
protected override Dictionary<int, ConfigurationPacketTypesIn> GetConfigurationListIn() => configurationTypesIn!;
protected override Dictionary<int, ConfigurationPacketTypesOut> GetConfigurationListOut() => configurationTypesOut!;
}

View file

@ -48,7 +48,7 @@ namespace MinecraftClient.Protocol.Handlers
{ {
PacketTypePalette p = protocol switch PacketTypePalette p = protocol switch
{ {
> Protocol18Handler.MC_1_20_2_Version => throw new NotImplementedException(Translations > Protocol18Handler.MC_1_20_4_Version => throw new NotImplementedException(Translations
.exception_palette_packet), .exception_palette_packet),
<= Protocol18Handler.MC_1_8_Version => new PacketPalette17(), <= Protocol18Handler.MC_1_8_Version => new PacketPalette17(),
<= Protocol18Handler.MC_1_11_2_Version => new PacketPalette110(), <= Protocol18Handler.MC_1_11_2_Version => new PacketPalette110(),
@ -64,8 +64,9 @@ namespace MinecraftClient.Protocol.Handlers
<= Protocol18Handler.MC_1_19_Version => new PacketPalette119(), <= Protocol18Handler.MC_1_19_Version => new PacketPalette119(),
<= Protocol18Handler.MC_1_19_2_Version => new PacketPalette1192(), <= Protocol18Handler.MC_1_19_2_Version => new PacketPalette1192(),
<= Protocol18Handler.MC_1_19_3_Version => new PacketPalette1193(), <= Protocol18Handler.MC_1_19_3_Version => new PacketPalette1193(),
< Protocol18Handler.MC_1_20_2_Version => new PacketPalette1194(), <= Protocol18Handler.MC_1_19_4_Version => new PacketPalette1194(),
_ => new PacketPalette1202() <= Protocol18Handler.MC_1_20_2_Version => new PacketPalette1202(),
_ => new PacketPalette1204()
}; };
p.SetForgeEnabled(forgeEnabled); p.SetForgeEnabled(forgeEnabled);

View file

@ -1,7 +1,7 @@
namespace MinecraftClient.Protocol.Handlers namespace MinecraftClient.Protocol.Handlers
{ {
/// <summary> /// <summary>
/// Incomming packet types /// Incoming packet types
/// </summary> /// </summary>
public enum PacketTypesIn public enum PacketTypesIn
{ {
@ -84,6 +84,8 @@
PluginMessage, // PluginMessage, //
ProfilelessChatMessage, // Added in 1.19.3 ProfilelessChatMessage, // Added in 1.19.3
RemoveEntityEffect, // RemoveEntityEffect, //
RemoveResourcePack, // Added in 1.20.3
ResetScore, // Added in 1.20.3
ResourcePackSend, // ResourcePackSend, //
Respawn, // Respawn, //
ScoreboardObjective, // ScoreboardObjective, //
@ -96,6 +98,8 @@
SetExperience, // SetExperience, //
SetPassengers, // SetPassengers, //
SetSlot, // SetSlot, //
SetTickingState, // Added in 1.20.3
StepTick, // Added in 1.20.3
SetTitleSubTitle, // SetTitleSubTitle, //
SetTitleText, // SetTitleText, //
SetTitleTime, // SetTitleTime, //

View file

@ -8,6 +8,7 @@
AcknowledgeConfiguration, // Added in 1.20.2 AcknowledgeConfiguration, // Added in 1.20.2
AdvancementTab, // AdvancementTab, //
Animation, // Animation, //
ChangeContainerSlotState, // Added in 1.20.3
ChatCommand, // Added in 1.19 ChatCommand, // Added in 1.19
ChatMessage, // ChatMessage, //
ChatPreview, // Added in 1.19 ChatPreview, // Added in 1.19

View file

@ -69,6 +69,7 @@ namespace MinecraftClient.Protocol.Handlers
internal const int MC_1_19_4_Version = 762; internal const int MC_1_19_4_Version = 762;
internal const int MC_1_20_Version = 763; internal const int MC_1_20_Version = 763;
internal const int MC_1_20_2_Version = 764; internal const int MC_1_20_2_Version = 764;
internal const int MC_1_20_4_Version = 765;
private int compression_treshold = 0; private int compression_treshold = 0;
private int autocomplete_transaction_id = 0; private int autocomplete_transaction_id = 0;
@ -120,21 +121,21 @@ namespace MinecraftClient.Protocol.Handlers
lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5); lastSeenMessagesCollector = protocolVersion >= MC_1_19_3_Version ? new(20) : new(5);
chunkBatchStartTime = GetNanos(); chunkBatchStartTime = GetNanos();
if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_2_Version) if (handler.GetTerrainEnabled() && protocolVersion > MC_1_20_4_Version)
{ {
log.Error($"§c{Translations.extra_terrainandmovement_disabled}"); log.Error($"§c{Translations.extra_terrainandmovement_disabled}");
handler.SetTerrainEnabled(false); handler.SetTerrainEnabled(false);
} }
if (handler.GetInventoryEnabled() && if (handler.GetInventoryEnabled() &&
protocolVersion is < MC_1_9_Version or > MC_1_20_2_Version) protocolVersion is < MC_1_9_Version or > MC_1_20_4_Version)
{ {
log.Error($"§c{Translations.extra_inventory_disabled}"); log.Error($"§c{Translations.extra_inventory_disabled}");
handler.SetInventoryEnabled(false); handler.SetInventoryEnabled(false);
} }
if (handler.GetEntityHandlingEnabled() && if (handler.GetEntityHandlingEnabled() &&
protocolVersion is < MC_1_8_Version or > MC_1_20_2_Version) protocolVersion is < MC_1_8_Version or > MC_1_20_4_Version)
{ {
log.Error($"§c{Translations.extra_entity_disabled}"); log.Error($"§c{Translations.extra_entity_disabled}");
handler.SetEntityHandlingEnabled(false); handler.SetEntityHandlingEnabled(false);
@ -143,8 +144,9 @@ namespace MinecraftClient.Protocol.Handlers
Block.Palette = protocolVersion switch Block.Palette = protocolVersion switch
{ {
// Block palette // Block palette
> MC_1_20_2_Version when handler.GetTerrainEnabled() => > MC_1_20_4_Version when handler.GetTerrainEnabled() =>
throw new NotImplementedException(Translations.exception_palette_block), throw new NotImplementedException(Translations.exception_palette_block),
>= MC_1_20_4_Version => new Palette1204(),
>= MC_1_20_Version => new Palette120(), >= MC_1_20_Version => new Palette120(),
MC_1_19_4_Version => new Palette1194(), MC_1_19_4_Version => new Palette1194(),
MC_1_19_3_Version => new Palette1193(), MC_1_19_3_Version => new Palette1193(),
@ -160,8 +162,9 @@ namespace MinecraftClient.Protocol.Handlers
entityPalette = protocolVersion switch entityPalette = protocolVersion switch
{ {
// Entity palette // Entity palette
> MC_1_20_2_Version when handler.GetEntityHandlingEnabled() => > MC_1_20_4_Version when handler.GetEntityHandlingEnabled() =>
throw new NotImplementedException(Translations.exception_palette_entity), throw new NotImplementedException(Translations.exception_palette_entity),
>= MC_1_20_4_Version => new EntityPalette1204(),
>= MC_1_20_Version => new EntityPalette120(), >= MC_1_20_Version => new EntityPalette120(),
MC_1_19_4_Version => new EntityPalette1194(), MC_1_19_4_Version => new EntityPalette1194(),
MC_1_19_3_Version => new EntityPalette1193(), MC_1_19_3_Version => new EntityPalette1193(),
@ -181,8 +184,9 @@ namespace MinecraftClient.Protocol.Handlers
itemPalette = protocolVersion switch itemPalette = protocolVersion switch
{ {
// Item palette // Item palette
> MC_1_20_2_Version when handler.GetInventoryEnabled() => > MC_1_20_4_Version when handler.GetInventoryEnabled() =>
throw new NotImplementedException(Translations.exception_palette_item), throw new NotImplementedException(Translations.exception_palette_item),
>= MC_1_20_4_Version => new ItemPalette1204(),
>= MC_1_20_Version => new ItemPalette120(), >= MC_1_20_Version => new ItemPalette120(),
MC_1_19_4_Version => new ItemPalette1194(), MC_1_19_4_Version => new ItemPalette1194(),
MC_1_19_3_Version => new ItemPalette1193(), MC_1_19_3_Version => new ItemPalette1193(),
@ -397,18 +401,18 @@ namespace MinecraftClient.Protocol.Handlers
{ {
case ConfigurationPacketTypesIn.Disconnect: case ConfigurationPacketTypesIn.Disconnect:
handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick, handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick,
ChatParser.ParseText(dataTypes.ReadNextString(packetData))); dataTypes.ReadNextChat(packetData));
return false; return false;
case ConfigurationPacketTypesIn.FinishConfiguration: case ConfigurationPacketTypesIn.FinishConfiguration:
currentState = CurrentState.Play; currentState = CurrentState.Play;
SendPacket(ConfigurationPacketTypesOut.FinishConfiguration, new List<byte>()); SendPacket(ConfigurationPacketTypesOut.FinishConfiguration, new List<byte>());
break; break;
case ConfigurationPacketTypesIn.KeepAlive: case ConfigurationPacketTypesIn.KeepAlive:
SendPacket(ConfigurationPacketTypesOut.KeepAlive, packetData); SendPacket(ConfigurationPacketTypesOut.KeepAlive, packetData);
break; break;
case ConfigurationPacketTypesIn.Ping: case ConfigurationPacketTypesIn.Ping:
SendPacket(ConfigurationPacketTypesOut.Pong, packetData); SendPacket(ConfigurationPacketTypesOut.Pong, packetData);
break; break;
@ -421,29 +425,14 @@ namespace MinecraftClient.Protocol.Handlers
World.StoreDimensionList(registryCodec); World.StoreDimensionList(registryCodec);
break; break;
case ConfigurationPacketTypesIn.RemoveResourcePack:
if (dataTypes.ReadNextBool(packetData)) // Has UUID
dataTypes.ReadNextUUID(packetData); // UUID
break;
case ConfigurationPacketTypesIn.ResourcePack: case ConfigurationPacketTypesIn.ResourcePack:
var url = dataTypes.ReadNextString(packetData); HandleResourcePackPacket(packetData);
var hash = dataTypes.ReadNextString(packetData);
dataTypes.ReadNextBool(packetData); // Forced
var hasPromptMessage =
dataTypes.ReadNextBool(packetData);
if (hasPromptMessage)
dataTypes.SkipNextString(packetData);
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") &&
hash.Length != 40) // Some server may have null hash value
break;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader = Array.Empty<byte>();
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
dataTypes.ConcatBytes(responseHeader, DataTypes.GetVarInt(3))); // Accepted pack
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
dataTypes.ConcatBytes(responseHeader,
DataTypes.GetVarInt(0))); // Successfully loaded
break; break;
// Ignore other packets at this stage // Ignore other packets at this stage
@ -480,6 +469,54 @@ namespace MinecraftClient.Protocol.Handlers
return true; return true;
} }
public void HandleResourcePackPacket(Queue<byte> packetData)
{
var uuid = Guid.Empty;
if (protocolVersion >= MC_1_20_4_Version)
uuid = dataTypes.ReadNextUUID(packetData);
var url = dataTypes.ReadNextString(packetData);
var hash = dataTypes.ReadNextString(packetData);
if (protocolVersion >= MC_1_17_Version)
{
dataTypes.ReadNextBool(packetData); // Forced
if (dataTypes.ReadNextBool(packetData)) // Has Prompt Message
dataTypes.ReadNextChat(packetData); // Prompt Message
}
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") &&
hash.Length != 40) // Some server may have null hash value
return;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader =
protocolVersion < MC_1_10_Version // After 1.10, the MC does not include resource pack hash in responses
? dataTypes.ConcatBytes(DataTypes.GetVarInt(hash.Length), Encoding.UTF8.GetBytes(hash))
: Array.Empty<byte>();
var basePacketData = protocolVersion >= MC_1_20_4_Version && uuid != Guid.Empty
? dataTypes.ConcatBytes(responseHeader, DataTypes.GetUUID(uuid))
: responseHeader;
var acceptedResourcePackData = dataTypes.ConcatBytes(basePacketData, DataTypes.GetVarInt(3));
var loadedResourcePackData = dataTypes.ConcatBytes(basePacketData, DataTypes.GetVarInt(0));
if (currentState == CurrentState.Configuration)
{
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse, acceptedResourcePackData); // Accepted
SendPacket(ConfigurationPacketTypesOut.ResourcePackResponse,
loadedResourcePackData); // Successfully loaded
}
else
{
SendPacket(PacketTypesOut.ResourcePackStatus, acceptedResourcePackData); // Accepted
SendPacket(PacketTypesOut.ResourcePackStatus, loadedResourcePackData); // Successfully loaded
}
}
private bool HandlePlayPackets(int packetId, Queue<byte> packetData) private bool HandlePlayPackets(int packetId, Queue<byte> packetData)
{ {
switch (packetPalette.GetIncomingTypeById(packetId)) switch (packetPalette.GetIncomingTypeById(packetId))
@ -886,7 +923,7 @@ namespace MinecraftClient.Protocol.Handlers
// Other // Other
var unsignedChatContent = dataTypes.ReadNextBool(packetData) var unsignedChatContent = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextString(packetData) ? dataTypes.ReadNextChat(packetData)
: null; : null;
var filterType = (MessageFilterType)dataTypes.ReadNextVarInt(packetData); var filterType = (MessageFilterType)dataTypes.ReadNextVarInt(packetData);
@ -897,26 +934,17 @@ namespace MinecraftClient.Protocol.Handlers
// Network Target // Network Target
// net.minecraft.network.message.MessageType.Serialized#write // net.minecraft.network.message.MessageType.Serialized#write
var chatTypeId = dataTypes.ReadNextVarInt(packetData); var chatTypeId = dataTypes.ReadNextVarInt(packetData);
var chatName = dataTypes.ReadNextString(packetData); var chatName = dataTypes.ReadNextChat(packetData);
var targetName = dataTypes.ReadNextBool(packetData) var targetName = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextString(packetData) ? dataTypes.ReadNextChat(packetData)
: null; : null;
var messageTypeEnum = var messageTypeEnum =
ChatParser.ChatId2Type!.GetValueOrDefault(chatTypeId, ChatParser.MessageType.CHAT); ChatParser.ChatId2Type!.GetValueOrDefault(chatTypeId, ChatParser.MessageType.CHAT);
var chatInfo = //var chatInfo = Json.ParseJson(targetName ?? chatName).Properties;
Json.ParseJson(targetName ?? chatName).Properties; var senderDisplayName = chatName;
var senderDisplayName = chatInfo != null && chatInfo.Count > 0 string? senderTeamName = targetName;
? (chatInfo.ContainsKey("insertion") ? chatInfo["insertion"] : chatInfo["text"])
.StringValue
: "";
string? senderTeamName = null;
if (targetName != null &&
messageTypeEnum is ChatParser.MessageType.TEAM_MSG_COMMAND_INCOMING
or ChatParser.MessageType.TEAM_MSG_COMMAND_OUTGOING)
senderTeamName = Json.ParseJson(targetName).Properties["with"].DataArray[0]
.Properties["text"].StringValue;
if (string.IsNullOrWhiteSpace(senderDisplayName)) if (string.IsNullOrWhiteSpace(senderDisplayName))
{ {
@ -924,7 +952,7 @@ namespace MinecraftClient.Protocol.Handlers
if (player != null && (player.DisplayName != null || player.Name != null) && if (player != null && (player.DisplayName != null || player.Name != null) &&
string.IsNullOrWhiteSpace(senderDisplayName)) string.IsNullOrWhiteSpace(senderDisplayName))
{ {
senderDisplayName = ChatParser.ParseText(player.DisplayName ?? player.Name); senderDisplayName = player.DisplayName ?? player.Name;
if (string.IsNullOrWhiteSpace(senderDisplayName)) if (string.IsNullOrWhiteSpace(senderDisplayName))
senderDisplayName = player.DisplayName ?? player.Name; senderDisplayName = player.DisplayName ?? player.Name;
else else
@ -989,7 +1017,7 @@ namespace MinecraftClient.Protocol.Handlers
$"HideMessage was not processed! (SigLen={hideMessageSignature.Length})"); $"HideMessage was not processed! (SigLen={hideMessageSignature.Length})");
break; break;
case PacketTypesIn.SystemChat: case PacketTypesIn.SystemChat:
var systemMessage = dataTypes.ReadNextString(packetData); var systemMessage = dataTypes.ReadNextChat(packetData);
if (protocolVersion >= MC_1_19_3_Version) if (protocolVersion >= MC_1_19_3_Version)
{ {
@ -1005,7 +1033,7 @@ namespace MinecraftClient.Protocol.Handlers
break; break;
} }
handler.OnTextReceived(new(systemMessage, null, true, -1, Guid.Empty, true)); handler.OnTextReceived(new(systemMessage, null, false, -1, Guid.Empty, true));
} }
else else
{ {
@ -1017,15 +1045,15 @@ namespace MinecraftClient.Protocol.Handlers
break; break;
case PacketTypesIn.ProfilelessChatMessage: case PacketTypesIn.ProfilelessChatMessage:
var message_ = dataTypes.ReadNextString(packetData); var message_ = dataTypes.ReadNextChat(packetData);
var messageType_ = dataTypes.ReadNextVarInt(packetData); var messageType_ = dataTypes.ReadNextVarInt(packetData);
var messageName = dataTypes.ReadNextString(packetData); var messageName = dataTypes.ReadNextChat(packetData);
var targetName_ = dataTypes.ReadNextBool(packetData) var targetName_ = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextString(packetData) ? dataTypes.ReadNextChat(packetData)
: null; : null;
ChatMessage profilelessChat = new(message_, targetName_ ?? messageName, true, messageType_, ChatMessage profilelessChat = new(message_, targetName_ ?? messageName, false, messageType_,
Guid.Empty, true); Guid.Empty, true);
profilelessChat.isSenderJson = true; profilelessChat.isSenderJson = false;
handler.OnTextReceived(profilelessChat); handler.OnTextReceived(profilelessChat);
break; break;
case PacketTypesIn.CombatEvent: case PacketTypesIn.CombatEvent:
@ -1051,7 +1079,7 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnPlayerKilled( handler.OnPlayerKilled(
protocolVersion >= MC_1_20_Version ? -1 : dataTypes.ReadNextInt(packetData), protocolVersion >= MC_1_20_Version ? -1 : dataTypes.ReadNextInt(packetData),
ChatParser.ParseText(dataTypes.ReadNextString(packetData)) ChatParser.ParseText(dataTypes.ReadNextChat(packetData))
); );
break; break;
@ -1450,7 +1478,7 @@ namespace MinecraftClient.Protocol.Handlers
if (dataTypes.ReadNextBool(packetData)) // Has Display Name? if (dataTypes.ReadNextBool(packetData)) // Has Display Name?
mapIcon.DisplayName = mapIcon.DisplayName =
ChatParser.ParseText(dataTypes.ReadNextString(packetData)); ChatParser.ParseText(dataTypes.ReadNextChat(packetData));
} }
icons.Add(mapIcon); icons.Add(mapIcon);
@ -1638,18 +1666,26 @@ namespace MinecraftClient.Protocol.Handlers
hasMotd = dataTypes.ReadNextBool(packetData); hasMotd = dataTypes.ReadNextBool(packetData);
if (hasMotd) if (hasMotd)
motd = ChatParser.ParseText(dataTypes.ReadNextString(packetData)); motd = ChatParser.ParseText(dataTypes.ReadNextChat(packetData));
} }
else else
{ {
hasMotd = true; hasMotd = true;
motd = ChatParser.ParseText(dataTypes.ReadNextString(packetData)); motd = ChatParser.ParseText(dataTypes.ReadNextChat(packetData));
} }
var iconBase64 = "-"; var iconBase64 = "-";
var hasIcon = dataTypes.ReadNextBool(packetData); var hasIcon = dataTypes.ReadNextBool(packetData);
if (hasIcon) if (hasIcon)
iconBase64 = dataTypes.ReadNextString(packetData); {
if (protocolVersion < MC_1_20_2_Version)
iconBase64 = dataTypes.ReadNextString(packetData);
else
{
var pngData = dataTypes.ReadNextByteArray(packetData);
iconBase64 = Convert.ToBase64String(pngData);
}
}
var previewsChat = false; var previewsChat = false;
if (protocolVersion < MC_1_19_3_Version) if (protocolVersion < MC_1_19_3_Version)
@ -1849,7 +1885,7 @@ namespace MinecraftClient.Protocol.Handlers
// Actions bit 5: update display name // Actions bit 5: update display name
if ((actionBitset & 1 << 5) <= 0) continue; if ((actionBitset & 1 << 5) <= 0) continue;
player.DisplayName = dataTypes.ReadNextBool(packetData) player.DisplayName = dataTypes.ReadNextBool(packetData)
? dataTypes.ReadNextString(packetData) ? dataTypes.ReadNextChat(packetData)
: null; : null;
} }
} }
@ -1995,7 +2031,7 @@ namespace MinecraftClient.Protocol.Handlers
// Skip optional tooltip for each tab-complete resul`t // Skip optional tooltip for each tab-complete resul`t
if (dataTypes.ReadNextBool(packetData)) if (dataTypes.ReadNextBool(packetData))
dataTypes.SkipNextString(packetData); dataTypes.ReadNextChat(packetData);
} }
handler.OnAutoCompleteDone(oldTransactionId, autocompleteResult); handler.OnAutoCompleteDone(oldTransactionId, autocompleteResult);
@ -2009,7 +2045,7 @@ namespace MinecraftClient.Protocol.Handlers
return pForge.HandlePluginMessage(channel, packetData, ref currentDimension); return pForge.HandlePluginMessage(channel, packetData, ref currentDimension);
case PacketTypesIn.Disconnect: case PacketTypesIn.Disconnect:
handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick, handler.OnConnectionLost(ChatBot.DisconnectReason.InGameKick,
ChatParser.ParseText(dataTypes.ReadNextString(packetData))); ChatParser.ParseText(dataTypes.ReadNextChat(packetData)));
return false; return false;
case PacketTypesIn.SetCompression: case PacketTypesIn.SetCompression:
if (protocolVersion is >= MC_1_8_Version and < MC_1_9_Version) if (protocolVersion is >= MC_1_8_Version and < MC_1_9_Version)
@ -2026,7 +2062,7 @@ namespace MinecraftClient.Protocol.Handlers
.ToUpper(); .ToUpper();
var inventoryType = var inventoryType =
(ContainerTypeOld)Enum.Parse(typeof(ContainerTypeOld), type); (ContainerTypeOld)Enum.Parse(typeof(ContainerTypeOld), type);
var title = dataTypes.ReadNextString(packetData); var title = dataTypes.ReadNextChat(packetData);
var slots = dataTypes.ReadNextByte(packetData); var slots = dataTypes.ReadNextByte(packetData);
Container inventory = new(windowId, inventoryType, ChatParser.ParseText(title)); Container inventory = new(windowId, inventoryType, ChatParser.ParseText(title));
handler.OnInventoryOpen(windowId, inventory); handler.OnInventoryOpen(windowId, inventory);
@ -2036,7 +2072,7 @@ namespace MinecraftClient.Protocol.Handlers
// MC 1.14 or greater // MC 1.14 or greater
var windowId = dataTypes.ReadNextVarInt(packetData); var windowId = dataTypes.ReadNextVarInt(packetData);
var windowType = dataTypes.ReadNextVarInt(packetData); var windowType = dataTypes.ReadNextVarInt(packetData);
var title = dataTypes.ReadNextString(packetData); var title = dataTypes.ReadNextChat(packetData);
Container inventory = new(windowId, windowType, ChatParser.ParseText(title)); Container inventory = new(windowId, windowType, ChatParser.ParseText(title));
handler.OnInventoryOpen(windowId, inventory); handler.OnInventoryOpen(windowId, inventory);
} }
@ -2120,34 +2156,18 @@ namespace MinecraftClient.Protocol.Handlers
} }
break; break;
case PacketTypesIn.RemoveResourcePack:
if (dataTypes.ReadNextBool(packetData)) // Has UUID
dataTypes.ReadNextUUID(packetData); // UUID
break;
case PacketTypesIn.ResourcePackSend: case PacketTypesIn.ResourcePackSend:
var url = dataTypes.ReadNextString(packetData); HandleResourcePackPacket(packetData);
var hash = dataTypes.ReadNextString(packetData); break;
var forced = true; // Assume forced for MC 1.16 and below case PacketTypesIn.ResetScore:
if (protocolVersion >= MC_1_17_Version) dataTypes.ReadNextString(packetData); // Entity Name
{ if (dataTypes.ReadNextBool(packetData)) // Has Objective Name
forced = dataTypes.ReadNextBool(packetData); dataTypes.ReadNextString(packetData); // Objective Name
var hasPromptMessage =
dataTypes.ReadNextBool(packetData); // Has Prompt Message (Boolean) - 1.17 and above
if (hasPromptMessage)
dataTypes.SkipNextString(
packetData); // Prompt Message (Optional Chat) - 1.17 and above
}
// Some server plugins may send invalid resource packs to probe the client and we need to ignore them (issue #1056)
if (!url.StartsWith("http") && hash.Length != 40) // Some server may have null hash value
break;
//Send back "accepted" and "successfully loaded" responses for plugins or server config making use of resource pack mandatory
var responseHeader = Array.Empty<byte>();
if (protocolVersion <
MC_1_10_Version) //MC 1.10 does not include resource pack hash in responses
responseHeader = dataTypes.ConcatBytes(DataTypes.GetVarInt(hash.Length),
Encoding.UTF8.GetBytes(hash));
SendPacket(PacketTypesOut.ResourcePackStatus,
dataTypes.ConcatBytes(responseHeader, DataTypes.GetVarInt(3))); // Accepted pack
SendPacket(PacketTypesOut.ResourcePackStatus,
dataTypes.ConcatBytes(responseHeader, DataTypes.GetVarInt(0))); // Successfully loaded
break; break;
case PacketTypesIn.SpawnEntity: case PacketTypesIn.SpawnEntity:
if (handler.GetEntityHandlingEnabled()) if (handler.GetEntityHandlingEnabled())
@ -2396,7 +2416,7 @@ namespace MinecraftClient.Protocol.Handlers
// Also make a palette for field? Will be a lot of work // Also make a palette for field? Will be a lot of work
var healthField = protocolVersion switch var healthField = protocolVersion switch
{ {
> MC_1_20_2_Version => throw new NotImplementedException(Translations > MC_1_20_4_Version => throw new NotImplementedException(Translations
.exception_palette_healthfield), .exception_palette_healthfield),
// 1.17 and above // 1.17 and above
>= MC_1_17_Version => 9, >= MC_1_17_Version => 9,
@ -2482,15 +2502,29 @@ namespace MinecraftClient.Protocol.Handlers
var explosionStrength = dataTypes.ReadNextFloat(packetData); var explosionStrength = dataTypes.ReadNextFloat(packetData);
var explosionBlockCount = protocolVersion >= MC_1_17_Version var explosionBlockCount = protocolVersion >= MC_1_17_Version
? dataTypes.ReadNextVarInt(packetData) ? dataTypes.ReadNextVarInt(packetData)
: dataTypes.ReadNextInt(packetData); : dataTypes.ReadNextInt(packetData); // Record count
// Records
for (var i = 0; i < explosionBlockCount; i++) for (var i = 0; i < explosionBlockCount; i++)
dataTypes.ReadData(3, packetData); dataTypes.ReadData(3, packetData);
// Maybe use in the future when the physics are implemented // Maybe use in the future when the physics are implemented
var playerVelocityX = dataTypes.ReadNextFloat(packetData); dataTypes.ReadNextFloat(packetData); // Player Motion X
var playerVelocityY = dataTypes.ReadNextFloat(packetData); dataTypes.ReadNextFloat(packetData); // Player Motion Y
var playerVelocityZ = dataTypes.ReadNextFloat(packetData); dataTypes.ReadNextFloat(packetData); // Player Motion Z
if (protocolVersion >= MC_1_20_4_Version)
{
dataTypes.ReadNextVarInt(packetData); // Block Interaction
dataTypes.ReadParticleData(packetData, itemPalette); // Small Explosion Particles
dataTypes.ReadParticleData(packetData, itemPalette); // Large Explosion Particles
// Explosion Sound
dataTypes.ReadNextString(packetData); // Sound Name
var hasFixedRange = dataTypes.ReadNextBool(packetData);
if (hasFixedRange)
dataTypes.ReadNextFloat(packetData); // Range
}
handler.OnExplosion(explosionLocation, explosionStrength, explosionBlockCount); handler.OnExplosion(explosionLocation, explosionStrength, explosionBlockCount);
break; break;
@ -2498,30 +2532,63 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnHeldItemChange(dataTypes.ReadNextByte(packetData)); // Slot handler.OnHeldItemChange(dataTypes.ReadNextByte(packetData)); // Slot
break; break;
case PacketTypesIn.ScoreboardObjective: case PacketTypesIn.ScoreboardObjective:
var objectiveName2 = dataTypes.ReadNextString(packetData); var objectiveName = dataTypes.ReadNextString(packetData);
var mode = dataTypes.ReadNextByte(packetData); var mode = dataTypes.ReadNextByte(packetData);
var objectiveValue = string.Empty; var objectiveValue = string.Empty;
var type2 = -1; var objectiveType = -1;
var numberFormat = 0;
if (mode is 0 or 2) if (mode is 0 or 2)
{ {
objectiveValue = dataTypes.ReadNextString(packetData); objectiveValue = dataTypes.ReadNextChat(packetData);
type2 = dataTypes.ReadNextVarInt(packetData); objectiveType = dataTypes.ReadNextVarInt(packetData);
if (protocolVersion >= MC_1_20_4_Version)
{
if (dataTypes.ReadNextBool(packetData)) // Has Number Format
numberFormat = dataTypes.ReadNextVarInt(packetData); // Number Format
}
} }
handler.OnScoreboardObjective(objectiveName2, mode, objectiveValue, type2); handler.OnScoreboardObjective(objectiveName, mode, objectiveValue, objectiveType, numberFormat);
break; break;
case PacketTypesIn.UpdateScore: case PacketTypesIn.UpdateScore:
var entityName = dataTypes.ReadNextString(packetData); var entityName = dataTypes.ReadNextString(packetData);
var action3 = protocolVersion >= MC_1_18_2_Version
? dataTypes.ReadNextVarInt(packetData) var action3 = 0;
: dataTypes.ReadNextByte(packetData);
var objectiveName3 = string.Empty; var objectiveName3 = string.Empty;
var value = -1; var objectiveValue2 = -1;
if (action3 != 1 || protocolVersion >= MC_1_8_Version) var objectiveDisplayName3 = string.Empty;
objectiveName3 = dataTypes.ReadNextString(packetData); var numberFormat2 = 0;
if (action3 != 1)
value = dataTypes.ReadNextVarInt(packetData); if (protocolVersion >= MC_1_20_4_Version)
handler.OnUpdateScore(entityName, action3, objectiveName3, value); {
objectiveName3 = dataTypes.ReadNextString(packetData); // Objective Name
objectiveValue2 = dataTypes.ReadNextVarInt(packetData); // Value
if (dataTypes.ReadNextBool(packetData)) // Has Display Name
objectiveDisplayName3 =
ChatParser.ParseText(dataTypes.ReadNextString(packetData)); // Has Display Name
if (dataTypes.ReadNextBool(packetData)) // Has Number Format
numberFormat2 = dataTypes.ReadNextVarInt(packetData); // Number Format
}
else
{
action3 = protocolVersion >= MC_1_18_2_Version
? dataTypes.ReadNextVarInt(packetData)
: dataTypes.ReadNextByte(packetData);
if (action3 != 1 || protocolVersion >= MC_1_8_Version)
objectiveName3 = dataTypes.ReadNextString(packetData);
if (action3 != 1)
objectiveValue2 = dataTypes.ReadNextVarInt(packetData);
}
handler.OnUpdateScore(entityName, action3, objectiveName3, objectiveDisplayName3, objectiveValue2,
numberFormat2);
break; break;
case PacketTypesIn.BlockChangedAck: case PacketTypesIn.BlockChangedAck:
handler.OnBlockChangeAck(dataTypes.ReadNextVarInt(packetData)); handler.OnBlockChangeAck(dataTypes.ReadNextVarInt(packetData));
@ -2567,6 +2634,11 @@ namespace MinecraftClient.Protocol.Handlers
break;*/ break;*/
case PacketTypesIn.SetTickingState:
dataTypes.ReadNextFloat(packetData);
dataTypes.ReadNextBool(packetData);
break;
default: default:
return false; //Ignored packet return false; //Ignored packet
} }
@ -2635,7 +2707,7 @@ namespace MinecraftClient.Protocol.Handlers
{ {
SendPacket(packetPalette.GetOutgoingIdByType(packet), packetData); SendPacket(packetPalette.GetOutgoingIdByType(packet), packetData);
} }
/// <summary> /// <summary>
/// Send a configuration packet to the server. Packet ID, compression, and encryption will be handled automatically. /// Send a configuration packet to the server. Packet ID, compression, and encryption will be handled automatically.
/// </summary> /// </summary>
@ -4176,7 +4248,7 @@ namespace MinecraftClient.Protocol.Handlers
} }
} }
public bool SendAnimation(int animation, int playerid) public bool SendAnimation(int animation, int playerId)
{ {
try try
{ {
@ -4187,7 +4259,7 @@ namespace MinecraftClient.Protocol.Handlers
switch (protocolVersion) switch (protocolVersion)
{ {
case < MC_1_8_Version: case < MC_1_8_Version:
packet.AddRange(DataTypes.GetInt(playerid)); packet.AddRange(DataTypes.GetInt(playerId));
packet.Add(1); // Swing arm packet.Add(1); // Swing arm
break; break;
case < MC_1_9_Version: case < MC_1_9_Version:
@ -4424,10 +4496,8 @@ namespace MinecraftClient.Protocol.Handlers
return false; return false;
} }
} }
else
{ return false;
return false;
}
} }
public bool SendRenameItem(string itemName) public bool SendRenameItem(string itemName)

View file

@ -417,21 +417,13 @@ namespace MinecraftClient.Protocol.Handlers
case 5: case 5:
// FML 3 // FML 3
// Server Config: FMLHandshakeMessages.java > S2CModData > decode() // Server Config: FMLHandshakeMessages.java > S2CModData > decode()
// [ Size ][ VarInt ]
// [ Mod Data List ][ Array ] [ Mod Id ][ String ]
// [ Display Name ][ String ]
// [ Version ][ String ]
// //
// We're ignoring this packet in MCC // We're ignoring this packet in MCC
/*
// Uncomment this code block if needed
var size = dataTypes.ReadNextVarInt(packetData);
Dictionary<string, string> modsData = new();
for (int i = 0; i < size; i++)
{
var modId = dataTypes.ReadNextString(packetData);
var displayName = dataTypes.ReadNextString(packetData);
var version = dataTypes.ReadNextString(packetData);
modsData.Add(modId, displayName + ":" + version);
}
*/
if (Settings.Config.Logging.DebugMessages) if (Settings.Config.Logging.DebugMessages)
{ {
ConsoleIO.WriteLineFormatted("§8" + "Received FML3 Server Mod Data List"); ConsoleIO.WriteLineFormatted("§8" + "Received FML3 Server Mod Data List");
@ -441,20 +433,11 @@ namespace MinecraftClient.Protocol.Handlers
case 6: case 6:
// FML 3 // FML 3
// Server Config: FMLHandshakeMessages.java > S2CChannelMismatchData > decode() // Server Config: FMLHandshakeMessages.java > S2CChannelMismatchData > decode()
// // [ Size ][ VarInt ]
// [ Mismatched Mod List ][ Array ] [ Mod Id ][ String ]
// [ Version ][ String ]
// We're ignoring this packet in MCC // We're ignoring this packet in MCC
/*
// Uncomment this code block if needed
Dictionary<string, string> mismatchedMods = new();
var size0 = dataTypes.ReadNextVarInt(packetData);
for (int i = 0; i < size0; i++)
{
var modId = dataTypes.ReadNextString(packetData);
var version = dataTypes.ReadNextString(packetData);
mismatchedMods.Add(modId, version);
}
*/
if (Settings.Config.Logging.DebugMessages) if (Settings.Config.Logging.DebugMessages)
{ {
ConsoleIO.WriteLineFormatted("§8" + "Received FML3 Server Mismatched Mods List"); ConsoleIO.WriteLineFormatted("§8" + "Received FML3 Server Mismatched Mods List");
@ -523,15 +506,15 @@ namespace MinecraftClient.Protocol.Handlers
/// </summary> /// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param> /// <param name="protocolVersion">Minecraft protocol version</param>
/// <returns>ForgeInfo item stating that Forge is enabled</returns> /// <returns>ForgeInfo item stating that Forge is enabled</returns>
/// <para>
/// 1.18 change the fml version to 3
/// https://github.com/MinecraftForge/MinecraftForge/commit/997d8e0aa28b831edcd712e59a96181d3b2117d4
/// </para>
public static ForgeInfo ServerForceForge(int protocolVersion) public static ForgeInfo ServerForceForge(int protocolVersion)
{ {
if (ServerMayForceForge(protocolVersion)) if (ServerMayForceForge(protocolVersion))
{ {
// 1.17 is still FML2 if (protocolVersion >= ProtocolHandler.MCVer2ProtocolVersion("1.18"))
// https://github.com/MinecraftForge/MinecraftForge/blob/50b5414033de82f46be23201db50484f36c37d4f/src/main/java/net/minecraftforge/fmllegacy/network/FMLNetworkConstants.java#L37C29-L37C42
// 1.18 change the constant FMLNETVERSION to 3
// https://github.com/MinecraftForge/MinecraftForge/blob/cb12df41e13da576b781be695f80728b9594c25f/src/main/java/net/minecraftforge/network/NetworkConstants.java#L28
if (protocolVersion > ProtocolHandler.MCVer2ProtocolVersion("1.18"))
{ {
return new ForgeInfo(FMLVersion.FML3); return new ForgeInfo(FMLVersion.FML3);
} }

View file

@ -430,22 +430,25 @@ namespace MinecraftClient.Protocol
void OnEntityEffect(int entityid, Effects effect, int amplifier, int duration, byte flags, bool hasFactorData, Dictionary<String, object>? factorCodec); void OnEntityEffect(int entityid, Effects effect, int amplifier, int duration, byte flags, bool hasFactorData, Dictionary<String, object>? factorCodec);
/// <summary> /// <summary>
/// Called when coreboardObjective /// Called when Soreboard Objective
/// </summary> /// </summary>
/// <param name="objectivename">objective name</param> /// <param name="objectiveName">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param> /// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param> /// <param name="objectiveValue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param> /// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type); /// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type, int numberFormat);
/// <summary> /// <summary>
/// Called when DisplayScoreboard /// Called when DisplayScoreboard
/// </summary> /// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param> /// <param name="entityName">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param> /// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param> /// <param name="objectiveName">The name of the objective the score belongs to</param>
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param> /// <param name="objectiveDisplayName">The name of the objective the score belongs to, but with chat formatting</param>
void OnUpdateScore(string entityname, int action, string objectivename, int value); /// <param name="objectiveValue">The score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
/// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
void OnUpdateScore(string entityName, int action, string objectiveName, string objectiveDisplayName, int objectiveValue, int numberFormat);
/// <summary> /// <summary>
/// Called when the client received the Tab Header and Footer /// Called when the client received the Tab Header and Footer

View file

@ -34,11 +34,12 @@ namespace MinecraftClient.Protocol.Message
public static void ReadChatType(Dictionary<string, object> registryCodec) public static void ReadChatType(Dictionary<string, object> registryCodec)
{ {
Dictionary<int, MessageType> chatTypeDictionary = ChatId2Type ?? new(); Dictionary<int, MessageType> chatTypeDictionary = ChatId2Type ?? new();
var chatTypeListNbt = (object[])(((Dictionary<string, object>)registryCodec["minecraft:chat_type"])["value"]); var chatTypeListNbt =
(object[])(((Dictionary<string, object>)registryCodec["minecraft:chat_type"])["value"]);
foreach (var (chatName, chatId) in from Dictionary<string, object> chatTypeNbt in chatTypeListNbt foreach (var (chatName, chatId) in from Dictionary<string, object> chatTypeNbt in chatTypeListNbt
let chatName = (string)chatTypeNbt["name"] let chatName = (string)chatTypeNbt["name"]
let chatId = (int)chatTypeNbt["id"] let chatId = (int)chatTypeNbt["id"]
select (chatName, chatId)) select (chatName, chatId))
{ {
chatTypeDictionary[chatId] = chatName switch chatTypeDictionary[chatId] = chatName switch
{ {
@ -52,6 +53,7 @@ namespace MinecraftClient.Protocol.Message
_ => MessageType.CHAT, _ => MessageType.CHAT,
}; };
} }
ChatId2Type = chatTypeDictionary; ChatId2Type = chatTypeDictionary;
} }
@ -66,6 +68,11 @@ namespace MinecraftClient.Protocol.Message
return JSONData2String(Json.ParseJson(json), "", links); return JSONData2String(Json.ParseJson(json), "", links);
} }
public static string ParseText(Dictionary<string, object> nbt)
{
return NbtToString(nbt);
}
/// <summary> /// <summary>
/// The main function to convert text from MC 1.9+ JSON to MC 1.5.2 formatted text /// The main function to convert text from MC 1.9+ JSON to MC 1.5.2 formatted text
/// </summary> /// </summary>
@ -142,6 +149,7 @@ namespace MinecraftClient.Protocol.Message
default: default:
goto case MessageType.CHAT; goto case MessageType.CHAT;
} }
return text; return text;
} }
@ -193,7 +201,14 @@ namespace MinecraftClient.Protocol.Message
/// Initialize translation rules. /// Initialize translation rules.
/// Necessary for properly printing some chat messages. /// Necessary for properly printing some chat messages.
/// </summary> /// </summary>
public static void InitTranslations() { if (!RulesInitialized) { InitRules(); RulesInitialized = true; } } public static void InitTranslations()
{
if (!RulesInitialized)
{
InitRules();
RulesInitialized = true;
}
}
/// <summary> /// <summary>
/// Internal rule initialization method. Looks for local rule file or download it from Mojang asset servers. /// Internal rule initialization method. Looks for local rule file or download it from Mojang asset servers.
@ -202,7 +217,9 @@ namespace MinecraftClient.Protocol.Message
{ {
if (Config.Main.Advanced.Language == "en_us") if (Config.Main.Advanced.Language == "en_us")
{ {
TranslationRules = JsonSerializer.Deserialize<Dictionary<string, string>>((byte[])MinecraftAssets.ResourceManager.GetObject("en_us.json")!)!; TranslationRules =
JsonSerializer.Deserialize<Dictionary<string, string>>(
(byte[])MinecraftAssets.ResourceManager.GetObject("en_us.json")!)!;
return; return;
} }
@ -217,13 +234,19 @@ namespace MinecraftClient.Protocol.Message
{ {
try try
{ {
TranslationRules = JsonSerializer.Deserialize<Dictionary<string, string>>(File.OpenRead(languageFilePath))!; TranslationRules =
JsonSerializer.Deserialize<Dictionary<string, string>>(File.OpenRead(languageFilePath))!;
}
catch (IOException)
{
}
catch (JsonException)
{
} }
catch (IOException) { }
catch (JsonException) { }
} }
if (TranslationRules.TryGetValue("Version", out string? version) && version == Settings.TranslationsFile_Version) if (TranslationRules.TryGetValue("Version", out string? version) &&
version == Settings.TranslationsFile_Version)
{ {
if (Config.Logging.DebugMessages) if (Config.Logging.DebugMessages)
ConsoleIO.WriteLineFormatted(Translations.chat_loaded, acceptnewlines: true); ConsoleIO.WriteLineFormatted(Translations.chat_loaded, acceptnewlines: true);
@ -231,32 +254,39 @@ namespace MinecraftClient.Protocol.Message
} }
// Try downloading language file from Mojang's servers? // Try downloading language file from Mojang's servers?
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.chat_download, Config.Main.Advanced.Language)); ConsoleIO.WriteLineFormatted(
"§8" + string.Format(Translations.chat_download, Config.Main.Advanced.Language));
HttpClient httpClient = new(); HttpClient httpClient = new();
try try
{ {
Task<string> fetch_index = httpClient.GetStringAsync(TranslationsFile_Website_Index); Task<string> fetch_index = httpClient.GetStringAsync(TranslationsFile_Website_Index);
fetch_index.Wait(); fetch_index.Wait();
Match match = Regex.Match(fetch_index.Result, $"minecraft/lang/{Config.Main.Advanced.Language}.json" + @""":\s\{""hash"":\s""([\d\w]{40})"""); Match match = Regex.Match(fetch_index.Result,
$"minecraft/lang/{Config.Main.Advanced.Language}.json" + @""":\s\{""hash"":\s""([\d\w]{40})""");
fetch_index.Dispose(); fetch_index.Dispose();
if (match.Success && match.Groups.Count == 2) if (match.Success && match.Groups.Count == 2)
{ {
string hash = match.Groups[1].Value; string hash = match.Groups[1].Value;
string translation_file_location = TranslationsFile_Website_Download + '/' + hash[..2] + '/' + hash; string translation_file_location = TranslationsFile_Website_Download + '/' + hash[..2] + '/' + hash;
if (Config.Logging.DebugMessages) if (Config.Logging.DebugMessages)
ConsoleIO.WriteLineFormatted(string.Format(Translations.chat_request, translation_file_location)); ConsoleIO.WriteLineFormatted(
string.Format(Translations.chat_request, translation_file_location));
Task<Dictionary<string, string>?> fetckFileTask = httpClient.GetFromJsonAsync<Dictionary<string, string>>(translation_file_location); Task<Dictionary<string, string>?> fetckFileTask =
httpClient.GetFromJsonAsync<Dictionary<string, string>>(translation_file_location);
fetckFileTask.Wait(); fetckFileTask.Wait();
if (fetckFileTask.Result != null && fetckFileTask.Result.Count > 0) if (fetckFileTask.Result != null && fetckFileTask.Result.Count > 0)
{ {
TranslationRules = fetckFileTask.Result; TranslationRules = fetckFileTask.Result;
TranslationRules["Version"] = TranslationsFile_Version; TranslationRules["Version"] = TranslationsFile_Version;
File.WriteAllText(languageFilePath, JsonSerializer.Serialize(TranslationRules, typeof(Dictionary<string, string>)), Encoding.UTF8); File.WriteAllText(languageFilePath,
JsonSerializer.Serialize(TranslationRules, typeof(Dictionary<string, string>)),
Encoding.UTF8);
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.chat_done, languageFilePath)); ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.chat_done, languageFilePath));
return; return;
} }
fetckFileTask.Dispose(); fetckFileTask.Dispose();
} }
else else
@ -270,7 +300,8 @@ namespace MinecraftClient.Protocol.Message
} }
catch (IOException) catch (IOException)
{ {
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.chat_save_fail, languageFilePath), acceptnewlines: true); ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.chat_save_fail, languageFilePath),
acceptnewlines: true);
} }
catch (Exception e) catch (Exception e)
{ {
@ -284,7 +315,9 @@ namespace MinecraftClient.Protocol.Message
httpClient.Dispose(); httpClient.Dispose();
} }
TranslationRules = JsonSerializer.Deserialize<Dictionary<string, string>>((byte[])MinecraftAssets.ResourceManager.GetObject("en_us.json")!)!; TranslationRules =
JsonSerializer.Deserialize<Dictionary<string, string>>(
(byte[])MinecraftAssets.ResourceManager.GetObject("en_us.json")!)!;
ConsoleIO.WriteLine(Translations.chat_use_default); ConsoleIO.WriteLine(Translations.chat_use_default);
} }
@ -305,7 +338,12 @@ namespace MinecraftClient.Protocol.Message
/// <returns>Returns the formatted text according to the given data</returns> /// <returns>Returns the formatted text according to the given data</returns>
private static string TranslateString(string rulename, List<string> using_data) private static string TranslateString(string rulename, List<string> using_data)
{ {
if (!RulesInitialized) { InitRules(); RulesInitialized = true; } if (!RulesInitialized)
{
InitRules();
RulesInitialized = true;
}
if (TranslationRules.ContainsKey(rulename)) if (TranslationRules.ContainsKey(rulename))
{ {
int using_idx = 0; int using_idx = 0;
@ -329,8 +367,8 @@ namespace MinecraftClient.Protocol.Message
//Using specified string or int with %1$s, %2$s... //Using specified string or int with %1$s, %2$s...
else if (char.IsDigit(rule[i + 1]) else if (char.IsDigit(rule[i + 1])
&& i + 3 < rule.Length && rule[i + 2] == '$' && i + 3 < rule.Length && rule[i + 2] == '$'
&& (rule[i + 3] == 's' || rule[i + 3] == 'd')) && (rule[i + 3] == 's' || rule[i + 3] == 'd'))
{ {
int specified_idx = rule[i + 1] - '1'; int specified_idx = rule[i + 1] - '1';
if (using_data.Count > specified_idx) if (using_data.Count > specified_idx)
@ -342,8 +380,10 @@ namespace MinecraftClient.Protocol.Message
} }
} }
} }
result.Append(rule[i]); result.Append(rule[i]);
} }
return result.ToString(); return result.ToString();
} }
else return "[" + rulename + "] " + string.Join(" ", using_data); else return "[" + rulename + "] " + string.Join(" ", using_data);
@ -366,6 +406,7 @@ namespace MinecraftClient.Protocol.Message
{ {
colorcode = Color2tag(JSONData2String(data.Properties["color"], "", links)); colorcode = Color2tag(JSONData2String(data.Properties["color"], "", links));
} }
if (data.Properties.ContainsKey("clickEvent") && links != null) if (data.Properties.ContainsKey("clickEvent") && links != null)
{ {
Json.JSONData clickEvent = data.Properties["clickEvent"]; Json.JSONData clickEvent = data.Properties["clickEvent"];
@ -377,12 +418,14 @@ namespace MinecraftClient.Protocol.Message
links.Add(clickEvent.Properties["value"].StringValue); links.Add(clickEvent.Properties["value"].StringValue);
} }
} }
if (data.Properties.ContainsKey("extra")) if (data.Properties.ContainsKey("extra"))
{ {
Json.JSONData[] extras = data.Properties["extra"].DataArray.ToArray(); Json.JSONData[] extras = data.Properties["extra"].DataArray.ToArray();
foreach (Json.JSONData item in extras) foreach (Json.JSONData item in extras)
extra_result = extra_result + JSONData2String(item, colorcode, links) + "§r"; extra_result = extra_result + JSONData2String(item, colorcode, links) + "§r";
} }
if (data.Properties.ContainsKey("text")) if (data.Properties.ContainsKey("text"))
{ {
return colorcode + JSONData2String(data.Properties["text"], colorcode, links) + extra_result; return colorcode + JSONData2String(data.Properties["text"], colorcode, links) + extra_result;
@ -400,7 +443,10 @@ namespace MinecraftClient.Protocol.Message
using_data.Add(JSONData2String(array[i], colorcode, links)); using_data.Add(JSONData2String(array[i], colorcode, links));
} }
} }
return colorcode + TranslateString(JSONData2String(data.Properties["translate"], "", links), using_data) + extra_result;
return colorcode +
TranslateString(JSONData2String(data.Properties["translate"], "", links), using_data) +
extra_result;
} }
else return extra_result; else return extra_result;
@ -410,6 +456,7 @@ namespace MinecraftClient.Protocol.Message
{ {
result += JSONData2String(item, colorcode, links); result += JSONData2String(item, colorcode, links);
} }
return result; return result;
case Json.JSONData.DataType.String: case Json.JSONData.DataType.String:
@ -418,5 +465,90 @@ namespace MinecraftClient.Protocol.Message
return ""; return "";
} }
private static string NbtToString(Dictionary<string, object> nbt)
{
if (nbt.Count == 1 && nbt.TryGetValue("", out object? rootMessage))
{
// Nameless root tag
return (string)rootMessage;
}
string message = string.Empty;
string colorCode = string.Empty;
StringBuilder extraBuilder = new StringBuilder();
foreach (var kvp in nbt)
{
string key = kvp.Key;
object value = kvp.Value;
switch (key)
{
case "text":
{
message = (string)value;
}
break;
case "extra":
{
object[] extras = (object[])value;
for (var i = 0; i < extras.Length; i++)
{
var extraDict = extras[i] switch
{
int => new Dictionary<string, object> { { "text", $"{extras[i]}" } },
string => new Dictionary<string, object>
{
{ "text", (string)extras[i] }
},
_ => (Dictionary<string, object>)extras[i]
};
extraBuilder.Append(NbtToString(extraDict) + "§r");
}
}
break;
case "translate":
{
if (nbt.TryGetValue("translate", out object translate))
{
var translateKey = (string)translate;
List<string> translateString = new();
if (nbt.TryGetValue("with", out object withComponent))
{
var withs = (object[])withComponent;
for (var i = 0; i < withs.Length; i++)
{
var withDict = withs[i] switch
{
int => new Dictionary<string, object> { { "text", $"{withs[i]}" } },
string => new Dictionary<string, object>
{
{ "text", (string)withs[i] }
},
_ => (Dictionary<string, object>)withs[i]
};
translateString.Add(NbtToString(withDict));
}
}
message = TranslateString(translateKey, translateString);
}
}
break;
case "color":
{
if (nbt.TryGetValue("color", out object color))
{
colorCode = Color2tag((string)color);
}
}
break;
}
}
return colorCode + message + extraBuilder.ToString();
}
} }
} }

View file

@ -5,7 +5,6 @@ using System.Text;
using MinecraftClient.Protocol.Handlers; using MinecraftClient.Protocol.Handlers;
using MinecraftClient.Protocol.Message; using MinecraftClient.Protocol.Message;
using static MinecraftClient.Protocol.Message.LastSeenMessageList; using static MinecraftClient.Protocol.Message.LastSeenMessageList;
using Newtonsoft.Json.Linq;
namespace MinecraftClient.Protocol.ProfileKey namespace MinecraftClient.Protocol.ProfileKey
{ {
@ -20,7 +19,8 @@ namespace MinecraftClient.Protocol.ProfileKey
ProxiedWebRequest.Response? response = null; ProxiedWebRequest.Response? response = null;
try try
{ {
if (!isYggdrasil) { if (!isYggdrasil)
{
var request = new ProxiedWebRequest(certificates) var request = new ProxiedWebRequest(certificates)
{ {
Accept = "application/json" Accept = "application/json"
@ -37,8 +37,7 @@ namespace MinecraftClient.Protocol.ProfileKey
// see https://github.com/yushijinhun/authlib-injector/blob/da910956eaa30d2f6c2c457222d188aeb53b0d1f/src/main/java/moe/yushi/authlibinjector/httpd/ProfileKeyFilter.java#L49 // see https://github.com/yushijinhun/authlib-injector/blob/da910956eaa30d2f6c2c457222d188aeb53b0d1f/src/main/java/moe/yushi/authlibinjector/httpd/ProfileKeyFilter.java#L49
// POST to "https://api.minecraftservices.com/player/certificates" with authlib-injector will get a dummy response // POST to "https://api.minecraftservices.com/player/certificates" with authlib-injector will get a dummy response
string jsonString = isYggdrasil ? MakeDummyResponse() : response!.Body; Json.JSONData json = isYggdrasil ? MakeDummyResponse() : Json.ParseJson(response!.Body);
Json.JSONData json = Json.ParseJson(jsonString);
// Error here // Error here
PublicKey publicKey = new(pemKey: json.Properties["keyPair"].Properties["publicKey"].StringValue, PublicKey publicKey = new(pemKey: json.Properties["keyPair"].Properties["publicKey"].StringValue,
sig: json.Properties["publicKeySignature"].StringValue, sig: json.Properties["publicKeySignature"].StringValue,
@ -236,7 +235,7 @@ namespace MinecraftClient.Protocol.ProfileKey
return sb.ToString(); return sb.ToString();
} }
public static string MakeDummyResponse() public static Json.JSONData MakeDummyResponse()
{ {
RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048); RSACryptoServiceProvider rsa = new RSACryptoServiceProvider(2048);
var mimePublicKey = Convert.ToBase64String(rsa.ExportSubjectPublicKeyInfo()); var mimePublicKey = Convert.ToBase64String(rsa.ExportSubjectPublicKeyInfo());
@ -246,19 +245,19 @@ namespace MinecraftClient.Protocol.ProfileKey
DateTime now = DateTime.UtcNow; DateTime now = DateTime.UtcNow;
DateTime expiresAt = now.AddHours(48); DateTime expiresAt = now.AddHours(48);
DateTime refreshedAfter = now.AddHours(36); DateTime refreshedAfter = now.AddHours(36);
JObject response = new JObject(); Json.JSONData response = new(Json.JSONData.DataType.Object);
JObject keyPairObj = new JObject Json.JSONData keyPairObj = new(Json.JSONData.DataType.Object);
{ keyPairObj.Properties["privateKey"] = new(Json.JSONData.DataType.String){ StringValue = privateKeyPEM };
{ "privateKey", privateKeyPEM }, keyPairObj.Properties["publicKey"] = new(Json.JSONData.DataType.String){ StringValue = publicKeyPEM };
{ "publicKey", publicKeyPEM }
}; response.Properties["keyPair"] = keyPairObj;
response.Add("keyPair", keyPairObj); response.Properties["publicKeySignature"] = new(Json.JSONData.DataType.String){ StringValue = "AA==" };
response.Add("publicKeySignature", "AA=="); response.Properties["publicKeySignatureV2"] = new(Json.JSONData.DataType.String){ StringValue = "AA==" };
response.Add("publicKeySignatureV2", "AA==");
string format = "yyyy-MM-ddTHH:mm:ss.ffffffZ"; string format = "yyyy-MM-ddTHH:mm:ss.ffffffZ";
response.Add("expiresAt", expiresAt.ToString(format)); response.Properties["expiresAt"] = new(Json.JSONData.DataType.String){ StringValue = expiresAt.ToString(format) };
response.Add("refreshedAfter", refreshedAfter.ToString(format)); response.Properties["refreshedAfter"] = new(Json.JSONData.DataType.String){ StringValue = refreshedAfter.ToString(format) };
return response.ToString();
return response;
} }
} }
} }

View file

@ -12,7 +12,6 @@ using MinecraftClient.Protocol.Handlers;
using MinecraftClient.Protocol.Handlers.Forge; using MinecraftClient.Protocol.Handlers.Forge;
using MinecraftClient.Protocol.Session; using MinecraftClient.Protocol.Session;
using MinecraftClient.Proxy; using MinecraftClient.Proxy;
using static MinecraftClient.Protocol.Microsoft;
using static MinecraftClient.Settings; using static MinecraftClient.Settings;
using static MinecraftClient.Settings.MainConfigHealper.MainConfig.GeneralConfig; using static MinecraftClient.Settings.MainConfigHealper.MainConfig.GeneralConfig;
@ -43,32 +42,39 @@ namespace MinecraftClient.Protocol
if (!String.IsNullOrEmpty(domain) && domain.Any(c => char.IsLetter(c))) if (!String.IsNullOrEmpty(domain) && domain.Any(c => char.IsLetter(c)))
{ {
AutoTimeout.Perform(() => AutoTimeout.Perform(() =>
{
try
{ {
ConsoleIO.WriteLine(string.Format(Translations.mcc_resolve, domainVal)); try
var lookupClient = new LookupClient();
var response = lookupClient.Query(new DnsQuestion($"_minecraft._tcp.{domainVal}", QueryType.SRV));
if (response.HasError != true && response.Answers.SrvRecords().Any())
{ {
//Order SRV records by priority and weight, then randomly ConsoleIO.WriteLine(string.Format(Translations.mcc_resolve, domainVal));
var result = response.Answers.SrvRecords() var lookupClient = new LookupClient();
.OrderBy(record => record.Priority) var response =
.ThenByDescending(record => record.Weight) lookupClient.Query(new DnsQuestion($"_minecraft._tcp.{domainVal}", QueryType.SRV));
.ThenBy(record => Guid.NewGuid()) if (response.HasError != true && response.Answers.SrvRecords().Any())
.First(); {
string target = result.Target.Value.Trim('.'); //Order SRV records by priority and weight, then randomly
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_found, target, result.Port, domainVal)); var result = response.Answers.SrvRecords()
domainVal = target; .OrderBy(record => record.Priority)
portVal = result.Port; .ThenByDescending(record => record.Weight)
foundService = true; .ThenBy(record => Guid.NewGuid())
.First();
string target = result.Target.Value.Trim('.');
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_found, target,
result.Port, domainVal));
domainVal = target;
portVal = result.Port;
foundService = true;
}
} }
} catch (Exception e)
catch (Exception e) {
{ ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_not_found, domainVal,
ConsoleIO.WriteLineFormatted("§8" + string.Format(Translations.mcc_not_found, domainVal, e.GetType().FullName, e.Message)); e.GetType().FullName, e.Message));
} }
}, TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords == MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast ? 10 : 30)); },
TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords ==
MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast
? 10
: 30));
} }
domain = domainVal; domain = domainVal;
@ -83,28 +89,34 @@ namespace MinecraftClient.Protocol
/// <param name="serverPort">Server Port to ping</param> /// <param name="serverPort">Server Port to ping</param>
/// <param name="protocolversion">Will contain protocol version, if ping successful</param> /// <param name="protocolversion">Will contain protocol version, if ping successful</param>
/// <returns>TRUE if ping was successful</returns> /// <returns>TRUE if ping was successful</returns>
public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion, ref ForgeInfo? forgeInfo) public static bool GetServerInfo(string serverIP, ushort serverPort, ref int protocolversion,
ref ForgeInfo? forgeInfo)
{ {
bool success = false; bool success = false;
int protocolversionTmp = 0; int protocolversionTmp = 0;
ForgeInfo? forgeInfoTmp = null; ForgeInfo? forgeInfoTmp = null;
if (AutoTimeout.Perform(() => if (AutoTimeout.Perform(() =>
{
try
{
if (Protocol18Handler.DoPing(serverIP, serverPort, ref protocolversionTmp, ref forgeInfoTmp)
|| Protocol16Handler.DoPing(serverIP, serverPort, ref protocolversionTmp))
{ {
success = true; try
} {
else if (Protocol18Handler.DoPing(serverIP, serverPort, ref protocolversionTmp, ref forgeInfoTmp)
ConsoleIO.WriteLineFormatted("§8" + Translations.error_unexpect_response, acceptnewlines: true); || Protocol16Handler.DoPing(serverIP, serverPort, ref protocolversionTmp))
} {
catch (Exception e) success = true;
{ }
ConsoleIO.WriteLineFormatted(String.Format("§8{0}: {1}", e.GetType().FullName, e.Message)); else
} ConsoleIO.WriteLineFormatted("§8" + Translations.error_unexpect_response,
}, TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords == MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast ? 10 : 30))) acceptnewlines: true);
}
catch (Exception e)
{
ConsoleIO.WriteLineFormatted(string.Format("§8{0}: {1}", e.GetType().FullName, e.Message));
}
},
TimeSpan.FromSeconds(Config.Main.Advanced.ResolveSrvRecords ==
MainConfigHealper.MainConfig.AdvancedConfig.ResolveSrvRecordType.fast
? 10
: 30)))
{ {
if (protocolversion != 0 && protocolversion != protocolversionTmp) if (protocolversion != 0 && protocolversion != protocolversionTmp)
ConsoleIO.WriteLineFormatted("§8" + Translations.error_version_different, acceptnewlines: true); ConsoleIO.WriteLineFormatted("§8" + Translations.error_version_different, acceptnewlines: true);
@ -125,23 +137,29 @@ namespace MinecraftClient.Protocol
/// <summary> /// <summary>
/// Get a protocol handler for the specified Minecraft version /// Get a protocol handler for the specified Minecraft version
/// </summary> /// </summary>
/// <param name="Client">Tcp Client connected to the server</param> /// <param name="client">Tcp Client connected to the server</param>
/// <param name="ProtocolVersion">Protocol version to handle</param> /// <param name="protocolVersion">Protocol version to handle</param>
/// <param name="Handler">Handler with the appropriate callbacks</param> /// <param name="forgeInfo">Forge info</param>
/// <param name="handler">Handler with the appropriate callbacks</param>
/// <returns></returns> /// <returns></returns>
public static IMinecraftCom GetProtocolHandler(TcpClient Client, int ProtocolVersion, ForgeInfo? forgeInfo, IMinecraftComHandler Handler) public static IMinecraftCom GetProtocolHandler(TcpClient client, int protocolVersion, ForgeInfo? forgeInfo,
IMinecraftComHandler handler)
{ {
int[] supportedVersions_Protocol16 = { 51, 60, 61, 72, 73, 74, 78 }; int[] suppoertedVersionsProtocol16 = { 51, 60, 61, 72, 73, 74, 78 };
if (Array.IndexOf(supportedVersions_Protocol16, ProtocolVersion) > -1) if (Array.IndexOf(suppoertedVersionsProtocol16, protocolVersion) > -1)
return new Protocol16Handler(Client, ProtocolVersion, Handler); 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, 763, 764}; int[] suppoertedVersionsProtocol18 =
{
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, 764, 765
};
if (Array.IndexOf(supportedVersions_Protocol18, ProtocolVersion) > -1) if (Array.IndexOf(suppoertedVersionsProtocol18, protocolVersion) > -1)
return new Protocol18Handler(Client, ProtocolVersion, Handler, forgeInfo); return new Protocol18Handler(client, protocolVersion, handler, forgeInfo);
throw new NotSupportedException(string.Format(Translations.exception_version_unsupport, ProtocolVersion)); throw new NotSupportedException(string.Format(Translations.exception_version_unsupport, protocolVersion));
} }
/// <summary> /// <summary>
@ -149,11 +167,11 @@ namespace MinecraftClient.Protocol
/// </summary> /// </summary>
/// <param name="MCVersion">The Minecraft version number</param> /// <param name="MCVersion">The Minecraft version number</param>
/// <returns>The protocol version number or 0 if could not determine protocol version: error, unknown, not supported</returns> /// <returns>The protocol version number or 0 if could not determine protocol version: error, unknown, not supported</returns>
public static int MCVer2ProtocolVersion(string MCVersion) public static int MCVer2ProtocolVersion(string mcVersion)
{ {
if (MCVersion.Contains('.')) if (mcVersion.Contains('.'))
{ {
switch (MCVersion.Split(' ')[0].Trim()) switch (mcVersion.Split(' ')[0].Trim())
{ {
case "1.0": case "1.0":
case "1.0.0": case "1.0.0":
@ -324,20 +342,21 @@ namespace MinecraftClient.Protocol
return 763; return 763;
case "1.20.2": case "1.20.2":
return 764; return 764;
case "1.20.3":
case "1.20.4":
return 765;
default: default:
return 0; return 0;
} }
} }
else
try
{ {
try return int.Parse(mcVersion, NumberStyles.Any, CultureInfo.CurrentCulture);
{ }
return int.Parse(MCVersion, NumberStyles.Any, CultureInfo.CurrentCulture); catch
} {
catch return 0;
{
return 0;
}
} }
} }
@ -404,6 +423,7 @@ namespace MinecraftClient.Protocol
762 => "1.19.4", 762 => "1.19.4",
763 => "1.20", 763 => "1.20",
764 => "1.20.2", 764 => "1.20.2",
765 => "1.20.4",
_ => "0.0" _ => "0.0"
}; };
} }
@ -411,7 +431,7 @@ namespace MinecraftClient.Protocol
/// <summary> /// <summary>
/// Check if we can force-enable Forge support for a Minecraft version without using server Ping /// Check if we can force-enable Forge support for a Minecraft version without using server Ping
/// </summary> /// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param> /// <param name="protocol">Minecraft protocol version</param>
/// <returns>TRUE if we can force-enable Forge support without using server Ping</returns> /// <returns>TRUE if we can force-enable Forge support without using server Ping</returns>
public static bool ProtocolMayForceForge(int protocol) public static bool ProtocolMayForceForge(int protocol)
{ {
@ -421,15 +441,35 @@ namespace MinecraftClient.Protocol
/// <summary> /// <summary>
/// Server Info: Consider Forge to be enabled regardless of server Ping /// Server Info: Consider Forge to be enabled regardless of server Ping
/// </summary> /// </summary>
/// <param name="protocolVersion">Minecraft protocol version</param> /// <param name="protocol">Minecraft protocol version</param>
/// <returns>ForgeInfo item stating that Forge is enabled</returns> /// <returns>ForgeInfo item stating that Forge is enabled</returns>
public static ForgeInfo ProtocolForceForge(int protocol) public static ForgeInfo ProtocolForceForge(int protocol)
{ {
return Protocol18Forge.ServerForceForge(protocol); return Protocol18Forge.ServerForceForge(protocol);
} }
public enum LoginResult { OtherError, ServiceUnavailable, SSLError, Success, WrongPassword, AccountMigrated, NotPremium, LoginRequired, InvalidToken, InvalidResponse, NullError, UserCancel, WrongSelection }; public enum LoginResult
public enum AccountType { Mojang, Microsoft }; {
OtherError,
ServiceUnavailable,
SSLError,
Success,
WrongPassword,
AccountMigrated,
NotPremium,
LoginRequired,
InvalidToken,
InvalidResponse,
NullError,
UserCancel,
WrongSelection
};
public enum AccountType
{
Mojang,
Microsoft
};
/// <summary> /// <summary>
/// Allows to login to a premium Minecraft account using the Yggdrasil authentication scheme. /// Allows to login to a premium Minecraft account using the Yggdrasil authentication scheme.
@ -455,7 +495,9 @@ namespace MinecraftClient.Protocol
{ {
return YggdrasiLogin(user, pass, out session); return YggdrasiLogin(user, pass, out session);
} }
else throw new InvalidOperationException("Account type must be Mojang or Microsoft or valid authlib 3rd Servers!"); else
throw new InvalidOperationException(
"Account type must be Mojang or Microsoft or valid authlib 3rd Servers!");
} }
/// <summary> /// <summary>
@ -472,8 +514,10 @@ namespace MinecraftClient.Protocol
try try
{ {
string result = ""; string result = "";
string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) + "\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }"; string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" +
int code = DoHTTPSPost("authserver.mojang.com",443, "/authenticate", json_request, ref result); JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) +
"\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }";
int code = DoHTTPSPost("authserver.mojang.com", 443, "/authenticate", json_request, ref result);
if (code == 200) if (code == 200)
{ {
if (result.Contains("availableProfiles\":[]}")) if (result.Contains("availableProfiles\":[]}"))
@ -490,7 +534,8 @@ namespace MinecraftClient.Protocol
{ {
session.ID = loginResponse.Properties["accessToken"].StringValue; session.ID = loginResponse.Properties["accessToken"].StringValue;
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue; session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"].StringValue; session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"]
.StringValue;
return LoginResult.Success; return LoginResult.Success;
} }
else return LoginResult.InvalidResponse; else return LoginResult.InvalidResponse;
@ -520,6 +565,7 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§8" + e.ToString()); ConsoleIO.WriteLineFormatted("§8" + e.ToString());
} }
return LoginResult.SSLError; return LoginResult.SSLError;
} }
catch (System.IO.IOException e) catch (System.IO.IOException e)
@ -528,6 +574,7 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§8" + e.ToString()); ConsoleIO.WriteLineFormatted("§8" + e.ToString());
} }
if (e.Message.Contains("authentication")) if (e.Message.Contains("authentication"))
{ {
return LoginResult.SSLError; return LoginResult.SSLError;
@ -540,18 +587,23 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§8" + e.ToString()); ConsoleIO.WriteLineFormatted("§8" + e.ToString());
} }
return LoginResult.OtherError; return LoginResult.OtherError;
} }
} }
private static LoginResult YggdrasiLogin(string user, string pass, out SessionToken session)
private static LoginResult YggdrasiLogin(string user, string pass, out SessionToken session)
{ {
session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") }; session = new SessionToken() { ClientID = Guid.NewGuid().ToString().Replace("-", "") };
try try
{ {
string result = ""; string result = "";
string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" + JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) + "\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }"; string json_request = "{\"agent\": { \"name\": \"Minecraft\", \"version\": 1 }, \"username\": \"" +
int code = DoHTTPSPost(Config.Main.General.AuthServer.Host,Config.Main.General.AuthServer.Port, "/api/yggdrasil/authserver/authenticate", json_request, ref result); JsonEncode(user) + "\", \"password\": \"" + JsonEncode(pass) +
"\", \"clientToken\": \"" + JsonEncode(session.ClientID) + "\" }";
int code = DoHTTPSPost(Config.Main.General.AuthServer.Host, Config.Main.General.AuthServer.Port,
"/api/yggdrasil/authserver/authenticate", json_request, ref result);
if (code == 200) if (code == 200)
{ {
if (result.Contains("availableProfiles\":[]}")) if (result.Contains("availableProfiles\":[]}"))
@ -568,36 +620,43 @@ namespace MinecraftClient.Protocol
&& loginResponse.Properties["selectedProfile"].Properties.ContainsKey("id") && loginResponse.Properties["selectedProfile"].Properties.ContainsKey("id")
&& loginResponse.Properties["selectedProfile"].Properties.ContainsKey("name")) && loginResponse.Properties["selectedProfile"].Properties.ContainsKey("name"))
{ {
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue; session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"]
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"].StringValue; .StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"]
.StringValue;
return LoginResult.Success; return LoginResult.Success;
} }
else else
{ {
string availableProfiles = ""; string availableProfiles = "";
foreach (Json.JSONData profile in loginResponse.Properties["availableProfiles"].DataArray) foreach (Json.JSONData profile in loginResponse.Properties["availableProfiles"]
.DataArray)
{ {
availableProfiles += " " + profile.Properties["name"].StringValue; availableProfiles += " " + profile.Properties["name"].StringValue;
} }
ConsoleIO.WriteLine(Translations.mcc_avaliable_profiles + availableProfiles); ConsoleIO.WriteLine(Translations.mcc_avaliable_profiles + availableProfiles);
ConsoleIO.WriteLine(Translations.mcc_select_profile); ConsoleIO.WriteLine(Translations.mcc_select_profile);
string selectedProfileName = ConsoleIO.ReadLine(); string selectedProfileName = ConsoleIO.ReadLine();
ConsoleIO.WriteLine(Translations.mcc_selected_profile + " " + selectedProfileName); ConsoleIO.WriteLine(Translations.mcc_selected_profile + " " + selectedProfileName);
Json.JSONData? selectedProfile = null; Json.JSONData? selectedProfile = null;
foreach (Json.JSONData profile in loginResponse.Properties["availableProfiles"].DataArray) foreach (Json.JSONData profile in loginResponse.Properties["availableProfiles"]
.DataArray)
{ {
selectedProfile = profile.Properties["name"].StringValue == selectedProfileName ? profile : selectedProfile; selectedProfile = profile.Properties["name"].StringValue == selectedProfileName
? profile
: selectedProfile;
} }
if (selectedProfile != null) if (selectedProfile != null)
{ {
session.PlayerID = selectedProfile.Properties["id"].StringValue; session.PlayerID = selectedProfile.Properties["id"].StringValue;
session.PlayerName = selectedProfile.Properties["name"].StringValue; session.PlayerName = selectedProfile.Properties["name"].StringValue;
SessionToken currentsession = session; SessionToken currentsession = session;
return GetNewYggdrasilToken(currentsession, out session); return GetNewYggdrasilToken(currentsession, out session);
} }
else else
{ {
return LoginResult.WrongSelection; return LoginResult.WrongSelection;
} }
@ -630,6 +689,7 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§8" + e.ToString()); ConsoleIO.WriteLineFormatted("§8" + e.ToString());
} }
return LoginResult.SSLError; return LoginResult.SSLError;
} }
catch (System.IO.IOException e) catch (System.IO.IOException e)
@ -638,6 +698,7 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§8" + e.ToString()); ConsoleIO.WriteLineFormatted("§8" + e.ToString());
} }
if (e.Message.Contains("authentication")) if (e.Message.Contains("authentication"))
{ {
return LoginResult.SSLError; return LoginResult.SSLError;
@ -650,9 +711,11 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§8" + e.ToString()); ConsoleIO.WriteLineFormatted("§8" + e.ToString());
} }
return LoginResult.OtherError; return LoginResult.OtherError;
} }
} }
/// <summary> /// <summary>
/// Sign-in to Microsoft Account without using browser. Only works if 2FA is disabled. /// Sign-in to Microsoft Account without using browser. Only works if 2FA is disabled.
/// Might not work well in some rare cases. /// Might not work well in some rare cases.
@ -678,6 +741,7 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace); ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
} }
return LoginResult.WrongPassword; // Might not always be wrong password return LoginResult.WrongPassword; // Might not always be wrong password
} }
} }
@ -748,6 +812,7 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§c" + e.StackTrace); ConsoleIO.WriteLineFormatted("§c" + e.StackTrace);
} }
return LoginResult.WrongPassword; // Might not always be wrong password return LoginResult.WrongPassword; // Might not always be wrong password
} }
} }
@ -761,13 +826,15 @@ namespace MinecraftClient.Protocol
{ {
var payload = JwtPayloadDecode.GetPayload(session.ID); var payload = JwtPayloadDecode.GetPayload(session.ID);
var json = Json.ParseJson(payload); var json = Json.ParseJson(payload);
var expTimestamp = long.Parse(json.Properties["exp"].StringValue, NumberStyles.Any, CultureInfo.CurrentCulture); var expTimestamp = long.Parse(json.Properties["exp"].StringValue, NumberStyles.Any,
CultureInfo.CurrentCulture);
var now = DateTime.Now; var now = DateTime.Now;
var tokenExp = UnixTimeStampToDateTime(expTimestamp); var tokenExp = UnixTimeStampToDateTime(expTimestamp);
if (Settings.Config.Logging.DebugMessages) if (Settings.Config.Logging.DebugMessages)
{ {
ConsoleIO.WriteLine("Access token expiration time is " + tokenExp.ToString()); ConsoleIO.WriteLine("Access token expiration time is " + tokenExp.ToString());
} }
if (now < tokenExp) if (now < tokenExp)
{ {
// Still valid // Still valid
@ -792,8 +859,11 @@ namespace MinecraftClient.Protocol
try try
{ {
string result = ""; string result = "";
string json_request = "{ \"accessToken\": \"" + JsonEncode(currentsession.ID) + "\", \"clientToken\": \"" + JsonEncode(currentsession.ClientID) + "\", \"selectedProfile\": { \"id\": \"" + JsonEncode(currentsession.PlayerID) + "\", \"name\": \"" + JsonEncode(currentsession.PlayerName) + "\" } }"; string json_request = "{ \"accessToken\": \"" + JsonEncode(currentsession.ID) +
int code = DoHTTPSPost("authserver.mojang.com",443, "/refresh", json_request, ref result); "\", \"clientToken\": \"" + JsonEncode(currentsession.ClientID) +
"\", \"selectedProfile\": { \"id\": \"" + JsonEncode(currentsession.PlayerID) +
"\", \"name\": \"" + JsonEncode(currentsession.PlayerName) + "\" } }";
int code = DoHTTPSPost("authserver.mojang.com", 443, "/refresh", json_request, ref result);
if (code == 200) if (code == 200)
{ {
if (result == null) if (result == null)
@ -810,7 +880,8 @@ namespace MinecraftClient.Protocol
{ {
session.ID = loginResponse.Properties["accessToken"].StringValue; session.ID = loginResponse.Properties["accessToken"].StringValue;
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue; session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"].StringValue; session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"]
.StringValue;
return LoginResult.Success; return LoginResult.Success;
} }
else return LoginResult.InvalidResponse; else return LoginResult.InvalidResponse;
@ -838,8 +909,12 @@ namespace MinecraftClient.Protocol
try try
{ {
string result = ""; string result = "";
string json_request = "{ \"accessToken\": \"" + JsonEncode(currentsession.ID) + "\", \"clientToken\": \"" + JsonEncode(currentsession.ClientID) + "\", \"selectedProfile\": { \"id\": \"" + JsonEncode(currentsession.PlayerID) + "\", \"name\": \"" + JsonEncode(currentsession.PlayerName) + "\" } }"; string json_request = "{ \"accessToken\": \"" + JsonEncode(currentsession.ID) +
int code = DoHTTPSPost(Config.Main.General.AuthServer.Host, Config.Main.General.AuthServer.Port, "/api/yggdrasil/authserver/refresh", json_request, ref result); "\", \"clientToken\": \"" + JsonEncode(currentsession.ClientID) +
"\", \"selectedProfile\": { \"id\": \"" + JsonEncode(currentsession.PlayerID) +
"\", \"name\": \"" + JsonEncode(currentsession.PlayerName) + "\" } }";
int code = DoHTTPSPost(Config.Main.General.AuthServer.Host, Config.Main.General.AuthServer.Port,
"/api/yggdrasil/authserver/refresh", json_request, ref result);
if (code == 200) if (code == 200)
{ {
if (result == null) if (result == null)
@ -856,7 +931,8 @@ namespace MinecraftClient.Protocol
{ {
session.ID = loginResponse.Properties["accessToken"].StringValue; session.ID = loginResponse.Properties["accessToken"].StringValue;
session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue; session.PlayerID = loginResponse.Properties["selectedProfile"].Properties["id"].StringValue;
session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"].StringValue; session.PlayerName = loginResponse.Properties["selectedProfile"].Properties["name"]
.StringValue;
return LoginResult.Success; return LoginResult.Success;
} }
else return LoginResult.InvalidResponse; else return LoginResult.InvalidResponse;
@ -891,15 +967,23 @@ namespace MinecraftClient.Protocol
try try
{ {
string result = ""; string result = "";
string json_request = "{\"accessToken\":\"" + accesstoken + "\",\"selectedProfile\":\"" + uuid + "\",\"serverId\":\"" + serverhash + "\"}"; string json_request = "{\"accessToken\":\"" + accesstoken + "\",\"selectedProfile\":\"" + uuid +
string host = type == LoginType.yggdrasil ? Config.Main.General.AuthServer.Host : "sessionserver.mojang.com"; "\",\"serverId\":\"" + serverhash + "\"}";
string host = type == LoginType.yggdrasil
? Config.Main.General.AuthServer.Host
: "sessionserver.mojang.com";
int port = type == LoginType.yggdrasil ? Config.Main.General.AuthServer.Port : 443; int port = type == LoginType.yggdrasil ? Config.Main.General.AuthServer.Port : 443;
string endpoint = type == LoginType.yggdrasil ? "/api/yggdrasil/sessionserver/session/minecraft/join" : "/session/minecraft/join"; string endpoint = type == LoginType.yggdrasil
? "/api/yggdrasil/sessionserver/session/minecraft/join"
: "/session/minecraft/join";
int code = DoHTTPSPost(host, port, endpoint, json_request, ref result); int code = DoHTTPSPost(host, port, endpoint, json_request, ref result);
return (code >= 200 && code < 300); return (code >= 200 && code < 300);
} }
catch { return false; } catch
{
return false;
}
} }
/// <summary> /// <summary>
@ -915,8 +999,9 @@ namespace MinecraftClient.Protocol
try try
{ {
string result = ""; string result = "";
string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username, Program.MCHighestVersion); string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username,
DoHTTPSGet("pc.realms.minecraft.net", 443,"/worlds", cookies, ref result); Program.MCHighestVersion);
DoHTTPSGet("pc.realms.minecraft.net", 443, "/worlds", cookies, ref result);
Json.JSONData realmsWorlds = Json.ParseJson(result); Json.JSONData realmsWorlds = Json.ParseJson(result);
if (realmsWorlds.Properties.ContainsKey("servers") if (realmsWorlds.Properties.ContainsKey("servers")
&& realmsWorlds.Properties["servers"].Type == Json.JSONData.DataType.Array && realmsWorlds.Properties["servers"].Type == Json.JSONData.DataType.Array
@ -942,6 +1027,7 @@ namespace MinecraftClient.Protocol
} }
} }
} }
if (availableWorlds.Count > 0) if (availableWorlds.Count > 0)
{ {
ConsoleIO.WriteLine(Translations.mcc_realms_available); ConsoleIO.WriteLine(Translations.mcc_realms_available);
@ -950,7 +1036,6 @@ namespace MinecraftClient.Protocol
ConsoleIO.WriteLine(Translations.mcc_realms_join); ConsoleIO.WriteLine(Translations.mcc_realms_join);
} }
} }
} }
catch (Exception e) catch (Exception e)
{ {
@ -960,6 +1045,7 @@ namespace MinecraftClient.Protocol
ConsoleIO.WriteLineFormatted("§8" + e.StackTrace); ConsoleIO.WriteLineFormatted("§8" + e.StackTrace);
} }
} }
return realmsWorldsResult; return realmsWorldsResult;
} }
@ -971,13 +1057,16 @@ namespace MinecraftClient.Protocol
/// <param name="uuid">Player UUID</param> /// <param name="uuid">Player UUID</param>
/// <param name="accesstoken">Access token</param> /// <param name="accesstoken">Access token</param>
/// <returns>Server address (host:port) or empty string if failure</returns> /// <returns>Server address (host:port) or empty string if failure</returns>
public static string GetRealmsWorldServerAddress(string worldId, string username, string uuid, string accesstoken) public static string GetRealmsWorldServerAddress(string worldId, string username, string uuid,
string accesstoken)
{ {
try try
{ {
string result = ""; string result = "";
string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username, Program.MCHighestVersion); string cookies = String.Format("sid=token:{0}:{1};user={2};version={3}", accesstoken, uuid, username,
int statusCode = DoHTTPSGet("pc.realms.minecraft.net",443, "/worlds/v1/" + worldId + "/join/pc", cookies, ref result); Program.MCHighestVersion);
int statusCode = DoHTTPSGet("pc.realms.minecraft.net", 443, "/worlds/v1/" + worldId + "/join/pc",
cookies, ref result);
if (statusCode == 200) if (statusCode == 200)
{ {
Json.JSONData serverAddress = Json.ParseJson(result); Json.JSONData serverAddress = Json.ParseJson(result);
@ -1002,6 +1091,7 @@ namespace MinecraftClient.Protocol
{ {
ConsoleIO.WriteLineFormatted("§8" + e.StackTrace); ConsoleIO.WriteLineFormatted("§8" + e.StackTrace);
} }
return ""; return "";
} }
} }
@ -1014,7 +1104,7 @@ namespace MinecraftClient.Protocol
/// <param name="cookies">Cookies for making the request</param> /// <param name="cookies">Cookies for making the request</param>
/// <param name="result">Request result</param> /// <param name="result">Request result</param>
/// <returns>HTTP Status code</returns> /// <returns>HTTP Status code</returns>
private static int DoHTTPSGet(string host,int port, string endpoint, string cookies, ref string result) private static int DoHTTPSGet(string host, int port, string endpoint, string cookies, ref string result)
{ {
List<String> http_request = new() List<String> http_request = new()
{ {
@ -1029,7 +1119,7 @@ namespace MinecraftClient.Protocol
"", "",
"" ""
}; };
return DoHTTPSRequest(http_request, host,port, ref result); return DoHTTPSRequest(http_request, host, port, ref result);
} }
/// <summary> /// <summary>
@ -1053,7 +1143,7 @@ namespace MinecraftClient.Protocol
"", "",
request request
}; };
return DoHTTPSRequest(http_request, host,port, ref result); return DoHTTPSRequest(http_request, host, port, ref result);
} }
/// <summary> /// <summary>
@ -1064,7 +1154,7 @@ namespace MinecraftClient.Protocol
/// <param name="host">Host to connect to</param> /// <param name="host">Host to connect to</param>
/// <param name="result">Request result</param> /// <param name="result">Request result</param>
/// <returns>HTTP Status code</returns> /// <returns>HTTP Status code</returns>
private static int DoHTTPSRequest(List<string> headers, string host,int port, ref string result) private static int DoHTTPSRequest(List<string> headers, string host, int port, ref string result)
{ {
string? postResult = null; string? postResult = null;
int statusCode = 520; int statusCode = 520;
@ -1078,7 +1168,8 @@ namespace MinecraftClient.Protocol
TcpClient client = ProxyHandler.NewTcpClient(host, port, true); TcpClient client = ProxyHandler.NewTcpClient(host, port, true);
SslStream stream = new(client.GetStream()); SslStream stream = new(client.GetStream());
stream.AuthenticateAsClient(host, null, SslProtocols.Tls12, true); // Enable TLS 1.2. Hotfix for #1780 stream.AuthenticateAsClient(host, null, SslProtocols.Tls12,
true); // Enable TLS 1.2. Hotfix for #1780
if (Settings.Config.Logging.DebugMessages) if (Settings.Config.Logging.DebugMessages)
foreach (string line in headers) foreach (string line in headers)
@ -1098,12 +1189,12 @@ namespace MinecraftClient.Protocol
if (raw_result.StartsWith("HTTP/1.1")) if (raw_result.StartsWith("HTTP/1.1"))
{ {
statusCode = int.Parse(raw_result.Split(' ')[1], NumberStyles.Any, CultureInfo.CurrentCulture); statusCode = int.Parse(raw_result.Split(' ')[1], NumberStyles.Any, CultureInfo.CurrentCulture);
if (statusCode != 204) if (statusCode != 204)
{ {
var splited = raw_result[(raw_result.IndexOf("\r\n\r\n") + 4)..].Split("\r\n"); var splited = raw_result[(raw_result.IndexOf("\r\n\r\n") + 4)..].Split("\r\n");
postResult = splited[1] + splited[3]; postResult = splited[1] + splited[3];
} }
else else
{ {
postResult = "No Content"; postResult = "No Content";
} }
@ -1165,4 +1256,4 @@ namespace MinecraftClient.Protocol
return dateTime; return dateTime;
} }
} }
} }

File diff suppressed because it is too large Load diff

View file

@ -332,20 +332,23 @@ namespace MinecraftClient.Scripting
/// <summary> /// <summary>
/// Called when a scoreboard objective updated /// Called when a scoreboard objective updated
/// </summary> /// </summary>
/// <param name="objectivename">objective name</param> /// <param name="objectiveName">objective name</param>
/// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param> /// <param name="mode">0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.</param>
/// <param name="objectivevalue">Only if mode is 0 or 2. The text to be displayed for the score</param> /// <param name="objectiveValue">Only if mode is 0 or 2. The text to be displayed for the score</param>
/// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param> /// <param name="type">Only if mode is 0 or 2. 0 = "integer", 1 = "hearts".</param>
public virtual void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type, string json) { } /// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
public virtual void OnScoreboardObjective(string objectiveName, byte mode, string objectiveValue, int type, string json, int numberFormat) { }
/// <summary> /// <summary>
/// Called when a scoreboard updated /// Called when a scoreboard updated
/// </summary> /// </summary>
/// <param name="entityname">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param> /// <param name="entityName">The entity whose score this is. For players, this is their username; for other entities, it is their UUID.</param>
/// <param name="action">0 to create/update an item. 1 to remove an item.</param> /// <param name="action">0 to create/update an item. 1 to remove an item.</param>
/// <param name="objectivename">The name of the objective the score belongs to</param> /// <param name="objectiveName">The name of the objective the score belongs to</param>
/// <param name="objectiveDisplayName">The name of the objective the score belongs to, but with chat formatting</param>
/// <param name="value">The score to be displayed next to the entry. Only sent when Action does not equal 1.</param> /// <param name="value">The score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
public virtual void OnUpdateScore(string entityname, int action, string objectivename, int value) { } /// <param name="numberFormat">Number format: 0 - blank, 1 - styled, 2 - fixed</param>
public virtual void OnUpdateScore(string entityName, int action, string objectiveName, string objectiveDisplayName, int value, int numberFormat) { }
/// <summary> /// <summary>
/// Called when the client received the Tab Header and Footer /// Called when the client received the Tab Header and Footer

View file

@ -18,6 +18,6 @@ features:
- title: Automation - title: Automation
details: Create bots to do automated tasks details: Create bots to do automated tasks
- title: Supported Versions - title: Supported Versions
details: 1.4 - 1.20.1 details: 1.4 - 1.20.4
footer: Made by MCC Team with ❤️ footer: Made by MCC Team with ❤️
--- ---