mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2026-08-15 13:04:36 +00:00
Bugs fix for “ClickWindow“ packet
This commit is contained in:
parent
59ed18bb40
commit
86dfd60d07
5 changed files with 67 additions and 31 deletions
|
|
@ -720,7 +720,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return false; //Currently not implemented
|
||||
}
|
||||
|
||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item, Dictionary<int, Item> Items, int stateId)
|
||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item, List<Tuple<short, Item>> changedSlots, int stateId)
|
||||
{
|
||||
return false; //Currently not implemented
|
||||
}
|
||||
|
|
|
|||
|
|
@ -917,7 +917,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
short slotID = dataTypes.ReadNextShort(packetData);
|
||||
Item item = dataTypes.ReadNextItemSlot(packetData, itemPalette);
|
||||
handler.OnSetSlot(windowID, slotID, item);
|
||||
handler.OnSetSlot(windowID, slotID, item, stateId);
|
||||
}
|
||||
break;
|
||||
case PacketTypesIn.WindowConfirmation:
|
||||
|
|
@ -1967,7 +1967,7 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
catch (ObjectDisposedException) { return false; }
|
||||
}
|
||||
|
||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item, Dictionary<int, Item> items, int stateId)
|
||||
public bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item, List<Tuple<short, Item>> changedSlots, int stateId)
|
||||
{
|
||||
try
|
||||
{
|
||||
|
|
@ -2004,51 +2004,48 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
|
||||
List<byte> packet = new List<byte>();
|
||||
|
||||
log.Info("Window id: " + windowId + " - State id: " + stateId + " - Slot id: " + slotId + " - Mode: " + mode);
|
||||
log.Info("Bytes > " + (byte)windowId + " - State id: " + dataTypes.ByteArrayToString(dataTypes.GetVarInt(stateId)) + " - Slot id: " + dataTypes.ByteArrayToString(dataTypes.GetVarInt(slotId)) + " - Mode: " + dataTypes.ByteArrayToString(dataTypes.GetVarInt(mode)));
|
||||
|
||||
packet.Add((byte)windowId);
|
||||
packet.Add((byte)windowId); // Window ID
|
||||
|
||||
// 1.18+
|
||||
if (protocolversion >= MC1181Version)
|
||||
{
|
||||
packet.AddRange(dataTypes.GetVarInt(stateId));
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId));
|
||||
packet.AddRange(dataTypes.GetVarInt(stateId)); // State ID
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId)); // Slot ID
|
||||
}
|
||||
// 1.17.1
|
||||
else if (protocolversion == MC1171Version)
|
||||
{
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId));
|
||||
packet.AddRange(dataTypes.GetVarInt(stateId));
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId)); // Slot ID
|
||||
packet.AddRange(dataTypes.GetVarInt(stateId)); // State ID
|
||||
}
|
||||
// Older
|
||||
else
|
||||
{
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId));
|
||||
packet.AddRange(dataTypes.GetShort((short)slotId)); // Slot ID
|
||||
}
|
||||
|
||||
packet.Add(button);
|
||||
if (protocolversion < MC117Version) packet.AddRange(dataTypes.GetShort(actionNumber));
|
||||
packet.Add(button); // Button
|
||||
|
||||
if (protocolversion < MC117Version)
|
||||
packet.AddRange(dataTypes.GetShort(actionNumber));
|
||||
|
||||
if (protocolversion >= MC19Version)
|
||||
packet.AddRange(dataTypes.GetVarInt(mode));
|
||||
packet.AddRange(dataTypes.GetVarInt(mode)); // Mode
|
||||
else packet.Add(mode);
|
||||
|
||||
// 1.17+
|
||||
if (protocolversion >= MC117Version)
|
||||
{
|
||||
byte[] arrayOfSlots = dataTypes.GetSlotsArray(items, itemPalette);
|
||||
|
||||
log.Info("Length: " + dataTypes.ByteArrayToString(dataTypes.GetVarInt(arrayOfSlots.Length)) + " (" + arrayOfSlots.Length + ")");
|
||||
log.Info("Array: " + dataTypes.ByteArrayToString(arrayOfSlots));
|
||||
|
||||
packet.AddRange(dataTypes.GetVarInt(arrayOfSlots.Length));
|
||||
packet.AddRange(arrayOfSlots);
|
||||
packet.AddRange(dataTypes.GetVarInt(changedSlots.Count)); // Length of the array
|
||||
foreach (var slot in changedSlots)
|
||||
{
|
||||
packet.AddRange(dataTypes.GetShort(slot.Item1)); // slot ID
|
||||
packet.AddRange(dataTypes.GetItemSlot(slot.Item2, itemPalette)); // slot Data
|
||||
}
|
||||
}
|
||||
|
||||
packet.AddRange(dataTypes.GetItemSlot(item, itemPalette)); // Carried item (Clicked item)
|
||||
|
||||
log.Info("Packet data: " + dataTypes.ByteArrayToString(packet.ToArray()));
|
||||
|
||||
SendPacket(PacketTypesOut.ClickWindow, packet);
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -162,10 +162,12 @@ namespace MinecraftClient.Protocol
|
|||
/// </summary>
|
||||
/// <param name="windowId">Id of the window being clicked</param>
|
||||
/// <param name="slotId">Id of the clicked slot</param>
|
||||
/// <param name="buttom">Action to perform</param>
|
||||
/// <param name="action">Action to perform</param>
|
||||
/// <param name="item">Item in the clicked slot</param>
|
||||
/// <param name="changedSlots">Slots that have been changed in this event: List<SlotID, Changed Items> </param>
|
||||
/// <param name="stateId">Inventory's stateId</param>
|
||||
/// <returns>True if packet was successfully sent</returns>
|
||||
bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item, Dictionary<int, Item> Items, int stateId);
|
||||
bool SendWindowAction(int windowId, int slotId, WindowActionType action, Item item, List<Tuple<short, Item>> changedSlots, int stateId);
|
||||
|
||||
/// <summary>
|
||||
/// Request Creative Mode item creation into regular/survival Player Inventory
|
||||
|
|
|
|||
|
|
@ -272,7 +272,8 @@ namespace MinecraftClient.Protocol
|
|||
/// <param name="inventoryID">Window ID</param>
|
||||
/// <param name="slotID">Slot ID</param>
|
||||
/// <param name="item">Item (may be null for empty slot)</param>
|
||||
void OnSetSlot(byte inventoryID, short slotID, Item item);
|
||||
/// <param name="stateId">State ID</param>
|
||||
void OnSetSlot(byte inventoryID, short slotID, Item item, int stateId);
|
||||
|
||||
/// <summary>
|
||||
/// Called when player health or hunger changed.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue