From 1f93fdbab57590d76c351b497da7b43a478608c5 Mon Sep 17 00:00:00 2001 From: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com> Date: Fri, 14 Aug 2020 21:22:19 +0800 Subject: [PATCH] Add health information for entity --- MinecraftClient/Mapping/Entity.cs | 7 +++++++ MinecraftClient/McClient.cs | 9 ++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/MinecraftClient/Mapping/Entity.cs b/MinecraftClient/Mapping/Entity.cs index 34ed4a3e..916bb985 100644 --- a/MinecraftClient/Mapping/Entity.cs +++ b/MinecraftClient/Mapping/Entity.cs @@ -33,6 +33,11 @@ namespace MinecraftClient.Mapping /// public Location Location; + /// + /// Health of the entity + /// + public float Health; + /// /// Create a new entity based on Entity ID, Entity Type and location /// @@ -44,6 +49,7 @@ namespace MinecraftClient.Mapping this.ID = ID; this.Type = type; this.Location = location; + this.Health = 0; } /// /// Create a new entity based on Entity ID, Entity Type, location, name and UUID @@ -60,6 +66,7 @@ namespace MinecraftClient.Mapping this.Location = location; this.UUID = uuid; this.Name = name; + this.Health = 0; } } } diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index c12c55ae..14ae10aa 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -2119,7 +2119,14 @@ namespace MinecraftClient /// Metadata public void OnEntityMetadata(int entityID, Dictionary metadata) { - + if (entities.ContainsKey(entityID)) + { + // Get health data for an entity + if (metadata.ContainsKey(8) && metadata[8].GetType() == typeof(float)) + { + entities[entityID].Health = (float)metadata[8]; + } + } } #endregion }