From 48577bf0340d5d54dadffe745282f827e66f9e97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=A0=D0=BE=D0=BC=D0=B0=20=D0=94=D0=B0=D0=BD=D0=B8=D0=BB?= =?UTF-8?q?=D0=BE=D0=B2?= <35975332+Nekiplay@users.noreply.github.com> Date: Sun, 4 Jul 2021 11:26:41 +0500 Subject: [PATCH] More events (#1660) * + OnBlockBreakAnimation * + OnBlockBreakAnimation * + OnEntityAnimation * Add checks * + OnBlockChange * + OnMultiBlockChange * Fix * Fix * Fix * add summary * Fix * fix other summary --- MinecraftClient/ChatBot.cs | 21 ++++++- MinecraftClient/McClient.cs | 56 ++++++++++++++----- .../Protocol/Handlers/Protocol18.cs | 22 +++++++- .../Protocol/IMinecraftComHandler.cs | 17 +++++- 4 files changed, 97 insertions(+), 19 deletions(-) diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 551c2e7d..1e476a7c 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -115,6 +115,21 @@ namespace MinecraftClient /// public virtual void Update() { } + /// + /// Will be called every player break block in gamemode 0 + /// + /// Player + /// Block location + /// Destroy stage, maximum 255 + public virtual void OnBlockBreakAnimation(Entity entity, Location location, byte stage) { } + + /// + /// Will be called every animations of the hit and place block + /// + /// Player + /// 0 = LMB, 1 = RMB (RMB Corrent not work) + public virtual void OnEntityAnimation(Entity entity, byte animation) { } + /// /// Any text sent by the server will be sent here by MinecraftCom /// @@ -211,6 +226,7 @@ namespace MinecraftClient /// Called when an explosion occurs on the server /// /// Explosion location + /// Explosion strength /// Amount of blocks blown up public virtual void OnExplosion(Location explode, float strength, int recordcount) { } @@ -284,11 +300,11 @@ namespace MinecraftClient /// Equipment slot. 0: main hand, 1: off hand, 2–5: armor slot (2: boots, 3: leggings, 4: chestplate, 5: helmet) /// Item) public virtual void OnEntityEquipment(Entity entity, int slot, Item item) { } - + /// /// Called when an entity has effect applied /// - /// entity ID + /// entity /// effect id /// effect amplifier /// effect duration @@ -367,7 +383,6 @@ namespace MinecraftClient /// /// Entity /// The metadata of the entity - /// Ptotocol version public virtual void OnEntityMetadata(Entity entity, Dictionary metadata) { } /// diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index 8ead0f61..26b91b82 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -181,8 +181,8 @@ namespace MinecraftClient this.port = port; this.protocolversion = protocolversion; - this.Log = Settings.LogToFile - ? new FileLogLogger(Settings.ExpandVars(Settings.LogFile), Settings.PrependTimestamp) + this.Log = Settings.LogToFile + ? new FileLogLogger(Settings.ExpandVars(Settings.LogFile), Settings.PrependTimestamp) : new FilteredLogger(); Log.DebugEnabled = Settings.DebugMessages; Log.InfoEnabled = Settings.InfoMessages; @@ -975,7 +975,7 @@ namespace MinecraftClient { return inventories; } - + /// /// Get all Entities /// @@ -989,11 +989,11 @@ namespace MinecraftClient /// Get all players latency /// /// All players latency - public Dictionary GetPlayersLatency() - { - return playersLatency; + public Dictionary GetPlayersLatency() + { + return playersLatency; } - + /// /// Get client player's inventory items /// @@ -1397,7 +1397,7 @@ namespace MinecraftClient upperStartSlot = 1; upperEndSlot = 9; break; - // TODO: Define more container type here + // TODO: Define more container type here } // Cursor have item or not doesn't matter @@ -1679,7 +1679,7 @@ namespace MinecraftClient { return InvokeOnMainThread(() => handler.SelectTrade(selectedSlot)); } - + /// /// Update command block /// @@ -1926,7 +1926,7 @@ namespace MinecraftClient DispatchBotEvent(bot => bot.GetText(text)); DispatchBotEvent(bot => bot.GetText(text, json)); } - + /// /// Received a connection keep-alive from the server /// @@ -1965,7 +1965,7 @@ namespace MinecraftClient else inventories.Remove(inventoryID); } - + if (inventoryID != 0) { Log.Info(Translations.Get("extra.inventory_close", inventoryID)); @@ -2118,7 +2118,7 @@ namespace MinecraftClient entities.Add(entity.ID, entity); DispatchBotEvent(bot => bot.OnEntitySpawn(entity)); } - + /// /// Called when an entity effects /// @@ -2415,7 +2415,7 @@ namespace MinecraftClient { DispatchBotEvent(bot => bot.OnTitle(action, titletext, subtitletext, actionbartext, fadein, stay, fadeout, json)); } - + /// /// Called when coreboardObjective /// @@ -2429,7 +2429,7 @@ namespace MinecraftClient objectivevalue = ChatParser.ParseText(objectivevalue); DispatchBotEvent(bot => bot.OnScoreboardObjective(objectivename, mode, objectivevalue, type, json)); } - + /// /// Called when DisplayScoreboard /// @@ -2502,6 +2502,34 @@ namespace MinecraftClient DispatchBotEvent(bot => bot.OnTradeList(windowID, trades, villagerInfo)); } + /// + /// Will be called every player break block in gamemode 0 + /// + /// Player ID + /// Block location + /// Destroy stage, maximum 255 + public void OnBlockBreakAnimation(int entityId, Location location, byte stage) + { + if (entities.ContainsKey(entityId)) + { + Entity entity = entities[entityId]; + DispatchBotEvent(bot => bot.OnBlockBreakAnimation(entity, location, stage)); + } + } + + /// + /// Will be called every animations of the hit and place block + /// + /// Player ID + /// 0 = LMB, 1 = RMB (RMB Corrent not work) + public void OnEntityAnimation(int entityID, byte animation) + { + if (entities.ContainsKey(entityID)) + { + Entity entity = entities[entityID]; + DispatchBotEvent(bot => bot.OnEntityAnimation(entity, animation)); + } + } #endregion } } diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 124367d6..e484f718 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -628,7 +628,10 @@ namespace MinecraftClient.Protocol.Handlers byte blockMeta = dataTypes.ReadNextByte(packetData); handler.GetWorld().SetBlock(new Location(blockX, blockY, blockZ), new Block(blockId, blockMeta)); } - else handler.GetWorld().SetBlock(dataTypes.ReadNextLocation(packetData), new Block((ushort)dataTypes.ReadNextVarInt(packetData))); + else + { + handler.GetWorld().SetBlock(dataTypes.ReadNextLocation(packetData), new Block((ushort)dataTypes.ReadNextVarInt(packetData))); + } } break; case PacketTypesIn.MapChunkBulk: @@ -1112,6 +1115,23 @@ namespace MinecraftClient.Protocol.Handlers value = dataTypes.ReadNextVarInt(packetData); handler.OnUpdateScore(entityname, action3, objectivename2, value); break; + case PacketTypesIn.BlockBreakAnimation: + if (handler.GetEntityHandlingEnabled() && handler.GetTerrainEnabled()) + { + int playerId = dataTypes.ReadNextVarInt(packetData); + Location blockLocation = dataTypes.ReadNextLocation(packetData); + byte stage = dataTypes.ReadNextByte(packetData); + handler.OnBlockBreakAnimation(playerId, blockLocation, stage); + } + break; + case PacketTypesIn.EntityAnimation: + if (handler.GetEntityHandlingEnabled()) + { + int playerId2 = dataTypes.ReadNextVarInt(packetData); + byte animation = dataTypes.ReadNextByte(packetData); + handler.OnEntityAnimation(playerId2, animation); + } + break; default: return false; //Ignored packet } diff --git a/MinecraftClient/Protocol/IMinecraftComHandler.cs b/MinecraftClient/Protocol/IMinecraftComHandler.cs index 6b4072a2..107875c0 100644 --- a/MinecraftClient/Protocol/IMinecraftComHandler.cs +++ b/MinecraftClient/Protocol/IMinecraftComHandler.cs @@ -83,7 +83,22 @@ namespace MinecraftClient.Protocol /// Text received from the server /// TRUE if the text is JSON-Encoded void OnTextReceived(string text, bool isJson); - + + /// + /// Will be called every animations of the hit and place block + /// + /// Player ID + /// 0 = LMB, 1 = RMB (RMB Corrent not work) + void OnEntityAnimation(int entityID, byte animation); + + /// + /// Will be called every player break block in gamemode 0 + /// + /// Player ID + /// Block location + /// Destroy stage, maximum 255 + void OnBlockBreakAnimation(int entityID, Location location, byte stage); + /// /// This method is called when the protocol handler receives a title ///