mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +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
|
|
@ -1243,8 +1243,7 @@ namespace MinecraftClient
|
|||
if (inventories.ContainsKey(windowId) && inventories[windowId].Items.ContainsKey(slotId))
|
||||
item = inventories[windowId].Items[slotId];
|
||||
|
||||
// Inventory update must be after sending packet
|
||||
bool result = handler.SendWindowAction(windowId, slotId, action, item, inventories[windowId].Items, inventories[windowId].StateID);
|
||||
List<Tuple<short, Item>> changedSlots = new List<Tuple<short, Item>>(); // List<Slot ID, Changed Items>
|
||||
|
||||
// Update our inventory base on action type
|
||||
var inventory = GetInventory(windowId);
|
||||
|
|
@ -1295,6 +1294,8 @@ namespace MinecraftClient
|
|||
inventory.Items[slotId] = playerInventory.Items[-1];
|
||||
playerInventory.Items.Remove(-1);
|
||||
}
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
|
||||
}
|
||||
else
|
||||
{
|
||||
|
|
@ -1307,6 +1308,8 @@ namespace MinecraftClient
|
|||
// Put target slot item to cursor
|
||||
playerInventory.Items[-1] = inventory.Items[slotId];
|
||||
inventory.Items.Remove(slotId);
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -1385,6 +1388,7 @@ namespace MinecraftClient
|
|||
}
|
||||
}
|
||||
}
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
|
||||
break;
|
||||
case WindowActionType.ShiftClick:
|
||||
if (slotId == 0) break;
|
||||
|
|
@ -1412,6 +1416,7 @@ namespace MinecraftClient
|
|||
// If hotbar already have same item, will put on it first until every stack are full
|
||||
// If no more same item , will put on the first empty slot (smaller slot id)
|
||||
// If inventory full, item will not move
|
||||
int itemCount = inventory.Items[slotId].Count;
|
||||
if (slotId <= upperEndSlot)
|
||||
{
|
||||
// Clicked slot is on upper side inventory, put it to hotbar
|
||||
|
|
@ -1431,11 +1436,16 @@ namespace MinecraftClient
|
|||
// Can fit into the stack
|
||||
inventory.Items[_item.Key].Count += inventory.Items[slotId].Count;
|
||||
inventory.Items.Remove(slotId);
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)_item.Key, inventory.Items[_item.Key]));
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
|
||||
}
|
||||
else
|
||||
{
|
||||
inventory.Items[slotId].Count -= spaceLeft;
|
||||
inventory.Items[_item.Key].Count = inventory.Items[_item.Key].Type.StackCount();
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)_item.Key, inventory.Items[_item.Key]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1454,6 +1464,13 @@ namespace MinecraftClient
|
|||
var itemTmp = inventory.Items[slotId];
|
||||
inventory.Items[emptySlot] = new Item(itemTmp.Type, itemTmp.Count, itemTmp.NBT);
|
||||
inventory.Items.Remove(slotId);
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)emptySlot, inventory.Items[emptySlot]));
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
|
||||
}
|
||||
else if (inventory.Items[slotId].Count != itemCount)
|
||||
{
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1477,11 +1494,16 @@ namespace MinecraftClient
|
|||
// Can fit into the stack
|
||||
inventory.Items[_item.Key].Count += inventory.Items[slotId].Count;
|
||||
inventory.Items.Remove(slotId);
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)_item.Key, inventory.Items[_item.Key]));
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
|
||||
}
|
||||
else
|
||||
{
|
||||
inventory.Items[slotId].Count -= spaceLeft;
|
||||
inventory.Items[_item.Key].Count = inventory.Items[_item.Key].Type.StackCount();
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)_item.Key, inventory.Items[_item.Key]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1501,6 +1523,13 @@ namespace MinecraftClient
|
|||
var itemTmp = inventory.Items[slotId];
|
||||
inventory.Items[emptySlot] = new Item(itemTmp.Type, itemTmp.Count, itemTmp.NBT);
|
||||
inventory.Items.Remove(slotId);
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)emptySlot, inventory.Items[emptySlot]));
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
|
||||
}
|
||||
else if (inventory.Items[slotId].Count != itemCount)
|
||||
{
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1512,14 +1541,18 @@ namespace MinecraftClient
|
|||
|
||||
if (inventory.Items[slotId].Count <= 0)
|
||||
inventory.Items.Remove(slotId);
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, inventory.Items[slotId]));
|
||||
break;
|
||||
case WindowActionType.DropItemStack:
|
||||
inventory.Items.Remove(slotId);
|
||||
|
||||
changedSlots.Add(new Tuple<short, Item>((short)slotId, null));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
return handler.SendWindowAction(windowId, slotId, action, item, changedSlots, inventories[windowId].StateID);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -2046,8 +2079,11 @@ namespace MinecraftClient
|
|||
/// <param name="inventoryID">Window ID</param>
|
||||
/// <param name="slotID">Slot ID</param>
|
||||
/// <param name="item">Item (may be null for empty slot)</param>
|
||||
public void OnSetSlot(byte inventoryID, short slotID, Item item)
|
||||
public void OnSetSlot(byte inventoryID, short slotID, Item item, int stateId)
|
||||
{
|
||||
if (inventories.ContainsKey(inventoryID))
|
||||
inventories[inventoryID].StateID = stateId;
|
||||
|
||||
// Handle inventoryID -2 - Add item to player inventory without animation
|
||||
if (inventoryID == 254)
|
||||
inventoryID = 0;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue