mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Fix crafting result slot not being handled correctly
Added new ChatBot event OnInventoryUpdate
This commit is contained in:
parent
c3dd0209c8
commit
500e7f1bec
2 changed files with 21 additions and 2 deletions
|
|
@ -279,6 +279,8 @@ namespace MinecraftClient
|
||||||
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
|
/// <param name="value">he score to be displayed next to the entry. Only sent when Action does not equal 1.</param>
|
||||||
public virtual void OnUpdateScore(string entityname, byte action, string objectivename, int value) { }
|
public virtual void OnUpdateScore(string entityname, byte action, string objectivename, int value) { }
|
||||||
|
|
||||||
|
public virtual void OnInventoryUpdate(int inventoryId) { }
|
||||||
|
|
||||||
/* =================================================================== */
|
/* =================================================================== */
|
||||||
/* ToolBox - Methods below might be useful while creating your bot. */
|
/* ToolBox - Methods below might be useful while creating your bot. */
|
||||||
/* You should not need to interact with other classes of the program. */
|
/* You should not need to interact with other classes of the program. */
|
||||||
|
|
|
||||||
|
|
@ -996,6 +996,9 @@ namespace MinecraftClient
|
||||||
// Check if cursor have item (slot -1)
|
// Check if cursor have item (slot -1)
|
||||||
if (playerInventory.Items.ContainsKey(-1))
|
if (playerInventory.Items.ContainsKey(-1))
|
||||||
{
|
{
|
||||||
|
// When item on cursor and clicking slot 0, nothing will happen
|
||||||
|
if (slotId == 0) break;
|
||||||
|
|
||||||
// Check target slot also have item?
|
// Check target slot also have item?
|
||||||
if (inventory.Items.ContainsKey(slotId))
|
if (inventory.Items.ContainsKey(slotId))
|
||||||
{
|
{
|
||||||
|
|
@ -1026,6 +1029,9 @@ namespace MinecraftClient
|
||||||
// Check target slot have item?
|
// Check target slot have item?
|
||||||
if (inventory.Items.ContainsKey(slotId))
|
if (inventory.Items.ContainsKey(slotId))
|
||||||
{
|
{
|
||||||
|
// When taking item from slot 0, server will update us
|
||||||
|
if (slotId == 0) break;
|
||||||
|
|
||||||
// Put target slot item to cursor
|
// Put target slot item to cursor
|
||||||
playerInventory.Items[-1] = inventory.Items[slotId];
|
playerInventory.Items[-1] = inventory.Items[slotId];
|
||||||
inventory.Items.Remove(slotId);
|
inventory.Items.Remove(slotId);
|
||||||
|
|
@ -1036,6 +1042,9 @@ namespace MinecraftClient
|
||||||
// Check if cursor have item (slot -1)
|
// Check if cursor have item (slot -1)
|
||||||
if (playerInventory.Items.ContainsKey(-1))
|
if (playerInventory.Items.ContainsKey(-1))
|
||||||
{
|
{
|
||||||
|
// When item on cursor and clicking slot 0, nothing will happen
|
||||||
|
if (slotId == 0) break;
|
||||||
|
|
||||||
// Check target slot have item?
|
// Check target slot have item?
|
||||||
if (inventory.Items.ContainsKey(slotId))
|
if (inventory.Items.ContainsKey(slotId))
|
||||||
{
|
{
|
||||||
|
|
@ -1068,6 +1077,12 @@ namespace MinecraftClient
|
||||||
// Check target slot have item?
|
// Check target slot have item?
|
||||||
if (inventory.Items.ContainsKey(slotId))
|
if (inventory.Items.ContainsKey(slotId))
|
||||||
{
|
{
|
||||||
|
if (slotId == 0)
|
||||||
|
{
|
||||||
|
// no matter how many item in slot 0, only 1 will be taken out
|
||||||
|
// Also server will update us
|
||||||
|
break;
|
||||||
|
}
|
||||||
if (inventory.Items[slotId].Count == 1)
|
if (inventory.Items[slotId].Count == 1)
|
||||||
{
|
{
|
||||||
// Only 1 item count. Put it to cursor
|
// Only 1 item count. Put it to cursor
|
||||||
|
|
@ -1076,14 +1091,12 @@ namespace MinecraftClient
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
ConsoleIO.WriteLine("At divide item");
|
|
||||||
// Take half of the item stack to cursor
|
// Take half of the item stack to cursor
|
||||||
if (inventory.Items[slotId].Count % 2 == 0)
|
if (inventory.Items[slotId].Count % 2 == 0)
|
||||||
{
|
{
|
||||||
// Can be evenly divided
|
// Can be evenly divided
|
||||||
Item itemTmp = inventory.Items[slotId];
|
Item itemTmp = inventory.Items[slotId];
|
||||||
playerInventory.Items[-1] = new Item((int)itemTmp.Type, itemTmp.Count / 2, itemTmp.NBT);
|
playerInventory.Items[-1] = new Item((int)itemTmp.Type, itemTmp.Count / 2, itemTmp.NBT);
|
||||||
ConsoleIO.WriteLine("Item put into cursor: " + playerInventory.Items[-1].Type.ToString());
|
|
||||||
inventory.Items[slotId].Count = itemTmp.Count / 2;
|
inventory.Items[slotId].Count = itemTmp.Count / 2;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|
@ -1531,7 +1544,10 @@ namespace MinecraftClient
|
||||||
public void OnWindowItems(byte inventoryID, Dictionary<int, Inventory.Item> itemList)
|
public void OnWindowItems(byte inventoryID, Dictionary<int, Inventory.Item> itemList)
|
||||||
{
|
{
|
||||||
if (inventories.ContainsKey(inventoryID))
|
if (inventories.ContainsKey(inventoryID))
|
||||||
|
{
|
||||||
inventories[inventoryID].Items = itemList;
|
inventories[inventoryID].Items = itemList;
|
||||||
|
DispatchBotEvent(bot => bot.OnInventoryUpdate(inventoryID));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
@ -1562,6 +1578,7 @@ namespace MinecraftClient
|
||||||
else inventories[inventoryID].Items[slotID] = item;
|
else inventories[inventoryID].Items[slotID] = item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
DispatchBotEvent(bot => bot.OnInventoryUpdate(inventoryID));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue