mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
feat: add recipe book command support
Agent-Logs-Url: https://github.com/MCCTeam/Minecraft-Console-Client/sessions/00c8527f-5755-43c1-8916-8d571d28860b Co-authored-by: milutinke <441903+milutinke@users.noreply.github.com>
This commit is contained in:
parent
3a28634592
commit
d5308ba8c6
8 changed files with 407 additions and 0 deletions
|
|
@ -3116,8 +3116,17 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
break;
|
||||
|
||||
case PacketTypesIn.UnlockRecipes:
|
||||
if (protocolVersion >= MC_1_13_Version)
|
||||
HandleUnlockRecipes(packetData);
|
||||
break;
|
||||
|
||||
case PacketTypesIn.RecipeBookAdd:
|
||||
HandleRecipeBookAdd(packetData);
|
||||
break;
|
||||
case PacketTypesIn.RecipeBookRemove:
|
||||
handler.OnRecipeBookRemove(ReadRecipeBookRecipeIds(packetData));
|
||||
break;
|
||||
case PacketTypesIn.RecipeBookSettings:
|
||||
break;
|
||||
|
||||
|
|
@ -3128,6 +3137,63 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return true; //Packet processed
|
||||
}
|
||||
|
||||
private void HandleUnlockRecipes(Queue<byte> packetData)
|
||||
{
|
||||
int action = dataTypes.ReadNextVarInt(packetData);
|
||||
SkipRecipeBookSettings(packetData);
|
||||
|
||||
string[] recipeIds = ReadRecipeBookRecipeIds(packetData);
|
||||
|
||||
switch (action)
|
||||
{
|
||||
case 0:
|
||||
handler.OnRecipeBookAdd(recipeIds, replace: true);
|
||||
_ = ReadRecipeBookRecipeIds(packetData);
|
||||
break;
|
||||
case 1:
|
||||
case 3:
|
||||
handler.OnRecipeBookAdd(recipeIds, replace: false);
|
||||
break;
|
||||
case 2:
|
||||
handler.OnRecipeBookRemove(recipeIds);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void HandleRecipeBookAdd(Queue<byte> packetData)
|
||||
{
|
||||
int entryCount = dataTypes.ReadNextVarInt(packetData);
|
||||
string[] recipeIds = new string[entryCount];
|
||||
|
||||
for (int i = 0; i < entryCount; i++)
|
||||
{
|
||||
recipeIds[i] = dataTypes.ReadNextString(packetData);
|
||||
_ = dataTypes.ReadNextBool(packetData); // notification
|
||||
_ = dataTypes.ReadNextBool(packetData); // highlight
|
||||
}
|
||||
|
||||
bool replace = dataTypes.ReadNextBool(packetData);
|
||||
handler.OnRecipeBookAdd(recipeIds, replace);
|
||||
}
|
||||
|
||||
private string[] ReadRecipeBookRecipeIds(Queue<byte> packetData)
|
||||
{
|
||||
int recipeCount = dataTypes.ReadNextVarInt(packetData);
|
||||
string[] recipeIds = new string[recipeCount];
|
||||
|
||||
for (int i = 0; i < recipeCount; i++)
|
||||
recipeIds[i] = dataTypes.ReadNextString(packetData);
|
||||
|
||||
return recipeIds;
|
||||
}
|
||||
|
||||
private void SkipRecipeBookSettings(Queue<byte> packetData)
|
||||
{
|
||||
int boolCount = protocolVersion >= MC_1_14_Version ? 8 : 4;
|
||||
for (int i = 0; i < boolCount; i++)
|
||||
_ = dataTypes.ReadNextBool(packetData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start the updating thread. Should be called after login success.
|
||||
/// </summary>
|
||||
|
|
@ -5018,6 +5084,34 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
}
|
||||
}
|
||||
|
||||
public bool SendPlaceRecipe(int windowId, string recipeId, bool makeAll)
|
||||
{
|
||||
try
|
||||
{
|
||||
List<byte> packet = new();
|
||||
if (protocolVersion < MC_1_13_Version)
|
||||
return false;
|
||||
|
||||
packet.AddRange(DataTypes.GetVarInt(windowId));
|
||||
packet.AddRange(dataTypes.GetString(recipeId));
|
||||
packet.AddRange(dataTypes.GetBool(makeAll));
|
||||
SendPacket(PacketTypesOut.CraftRecipeRequest, packet);
|
||||
return true;
|
||||
}
|
||||
catch (SocketException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (System.IO.IOException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
catch (ObjectDisposedException)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool SendAnimation(int animation, int playerId)
|
||||
{
|
||||
try
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue