From f2816c3feefa99d0d01077e28de6d72bcafda574 Mon Sep 17 00:00:00 2001
From: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com>
Date: Tue, 7 Jul 2020 13:21:55 +0800
Subject: [PATCH] Add inventory related ChatBot event
Added OnInventoryOpen and OnInventoryClose
Updated some method summary
---
MinecraftClient/ChatBot.cs | 32 ++++++++++++++++++++++++--------
MinecraftClient/McClient.cs | 9 +++++++--
2 files changed, 31 insertions(+), 10 deletions(-)
diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs
index f8c6d82a..f0dca0e6 100644
--- a/MinecraftClient/ChatBot.cs
+++ b/MinecraftClient/ChatBot.cs
@@ -222,7 +222,7 @@ namespace MinecraftClient
public virtual void OnLatencyUpdate(string playername, Guid uuid, int latency) { }
///
- /// Called map data
+ /// Called when a map was updated
///
///
///
@@ -232,7 +232,7 @@ namespace MinecraftClient
public virtual void OnMapData(int mapid, byte scale, bool trackingposition, bool locked, int iconcount) { }
///
- /// Received some Title from the server
+ /// Called when received a title from the server
/// 0 = set title, 1 = set subtitle, 3 = set action bar, 4 = set times and display, 4 = hide, 5 = reset
/// title text
/// suntitle text
@@ -244,7 +244,7 @@ namespace MinecraftClient
public virtual void OnTitle(int action, string titletext, string subtitletext, string actionbartext, int fadein, int stay, int fadeout, string json) { }
///
- /// Called on Entity Equipment
+ /// Called when an entity equipped
///
/// Entity
/// Equipment slot. 0: main hand, 1: off hand, 2–5: armor slot (2: boots, 3: leggings, 4: chestplate, 5: helmet)
@@ -252,7 +252,7 @@ namespace MinecraftClient
public virtual void OnEntityEquipment(Entity entity, int slot, Item item) { }
///
- /// Called when the Entity use effects
+ /// Called when an entity has effect applied
///
/// entity ID
/// effect id
@@ -260,9 +260,9 @@ namespace MinecraftClient
/// effect duration
/// effect flags
public virtual void OnEntityEffect(Entity entity, Effects effect, int amplifier, int duration, byte flags) { }
-
+
///
- /// Called when coreboardObjective
+ /// Called when a scoreboard objective updated
///
/// objective name
/// 0 to create the scoreboard. 1 to remove the scoreboard. 2 to update the display text.
@@ -271,16 +271,32 @@ namespace MinecraftClient
public virtual void OnScoreboardObjective(string objectivename, byte mode, string objectivevalue, int type, string json) { }
///
- /// Called when DisplayScoreboard
+ /// Called when a scoreboard updated
///
/// The entity whose score this is. For players, this is their username; for other entities, it is their UUID.
/// 0 to create/update an item. 1 to remove an item.
/// The name of the objective the score belongs to
- /// he score to be displayed next to the entry. Only sent when Action does not equal 1.
+ /// The score to be displayed next to the entry. Only sent when Action does not equal 1.
public virtual void OnUpdateScore(string entityname, byte action, string objectivename, int value) { }
+ ///
+ /// Called when an inventory/container was updated by server
+ ///
+ ///
public virtual void OnInventoryUpdate(int inventoryId) { }
+ ///
+ /// Called when a container was opened
+ ///
+ ///
+ public virtual void OnInventoryOpen(int inventoryId) { }
+
+ ///
+ /// Called when a container was closed
+ ///
+ ///
+ public virtual void OnInventoryClose(int inventoryId) { }
+
/* =================================================================== */
/* ToolBox - Methods below might be useful while creating your bot. */
/* You should not need to interact with other classes of the program. */
diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs
index 13b78eb3..220ccf3b 100644
--- a/MinecraftClient/McClient.cs
+++ b/MinecraftClient/McClient.cs
@@ -1511,7 +1511,8 @@ namespace MinecraftClient
///
/// When an inventory is opened
///
- /// Location to reach
+ /// The inventory
+ /// Inventory ID
public void OnInventoryOpen(int inventoryID, Container inventory)
{
inventories[inventoryID] = inventory;
@@ -1520,20 +1521,24 @@ namespace MinecraftClient
{
ConsoleIO.WriteLogLine("Inventory # " + inventoryID + " opened: " + inventory.Title);
ConsoleIO.WriteLogLine("Use /inventory to interact with it.");
+ DispatchBotEvent(bot => bot.OnInventoryOpen(inventoryID));
}
}
///
/// When an inventory is close
///
- /// Location to reach
+ /// Inventory ID
public void OnInventoryClose(int inventoryID)
{
if (inventories.ContainsKey(inventoryID))
inventories.Remove(inventoryID);
if (inventoryID != 0)
+ {
ConsoleIO.WriteLogLine("Inventory # " + inventoryID + " closed.");
+ DispatchBotEvent(bot => bot.OnInventoryClose(inventoryID));
+ }
}
///