Implemented entity metadata to keep track of entity health (#1205)

* Implement entity metadata protocol handling
* Add health information for entity
* Make AutoAttack check entity health
* LivingEntity: Default health is 1.0 as per https://wiki.vg/Entity_metadata#Living_Entity
* Fix entity metadata for lower MC versions
* Fix commit  888297d (1.0f instead of 1.0)
* Add OnEntityHealth ChatBot event (Remove protocol-dependant stuff from McClient (undo part of 85c32b9))
* Remove OnEntityMetadata in favor of OnEntityHealth
Co-authored-by: ORelio <ORelio@users.noreply.github.com>
This commit is contained in:
ReinforceZwei 2020-08-15 21:32:46 +08:00 committed by GitHub
parent 526dabd1e7
commit 2c8ec4aa4a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 191 additions and 2 deletions

View file

@ -861,6 +861,16 @@ namespace MinecraftClient.Protocol.Handlers
handler.OnEntityProperties(EntityID, keys);
}
break;
case PacketIncomingType.EntityMetadata:
if (handler.GetEntityHandlingEnabled())
{
int EntityID = dataTypes.ReadNextVarInt(packetData);
Dictionary<int, object> metadata = dataTypes.ReadNextMetadata(packetData);
int healthField = protocolversion >= MC114Version ? 8 : 7; // Health is field no. 7 in 1.10+ and 8 in 1.14+
if (metadata.ContainsKey(healthField) && metadata[healthField].GetType() == typeof(float))
handler.OnEntityHealth(EntityID, (float)metadata[healthField]);
}
break;
case PacketIncomingType.TimeUpdate:
long WorldAge = dataTypes.ReadNextLong(packetData);
long TimeOfday = dataTypes.ReadNextLong(packetData);