Fixed entity rotations (#2596)

* Fixed entity rotations

Fixed entity yaw and pitch not changing when entity moves head.

* Update ChatBot.cs

* Update McClient.cs

* Update Protocol18.cs

* Update McClient.cs

* Finalize code style

* Fix incorrect variable type

---------

Co-authored-by: ReinforceZwei <39955851+ReinforceZwei@users.noreply.github.com>
This commit is contained in:
Domracz 2023-10-11 02:44:46 -04:00 committed by GitHub
parent c3fa413b4e
commit 1aea8d3a4e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 85 additions and 3 deletions

View file

@ -3146,6 +3146,31 @@ namespace MinecraftClient
}
}
/// <summary>
/// Called when an entity's position changed within 8 block of its previous position with rotation.
/// </summary>
/// <param name="EntityID"></param>
/// <param name="Dx"></param>
/// <param name="Dy"></param>
/// <param name="Dz"></param>
/// <param name="yaw"></param>
/// <param name="pitch"></param>
/// <param name="onGround"></param>
public void OnEntityPosition(int EntityID, Double Dx, Double Dy, Double Dz, float yaw, float pitch, bool onGround)
{
if (entities.ContainsKey(EntityID))
{
Location L = entities[EntityID].Location;
L.X += Dx;
L.Y += Dy;
L.Z += Dz;
entities[EntityID].Location = L;
entities[EntityID].Yaw = yaw;
entities[EntityID].Pitch = pitch;
DispatchBotEvent(bot => bot.OnEntityMove(entities[EntityID]));
}
}
/// <summary>
/// Called when an entity's position changed within 8 block of its previous position.
/// </summary>
@ -3165,7 +3190,23 @@ namespace MinecraftClient
entities[EntityID].Location = L;
DispatchBotEvent(bot => bot.OnEntityMove(entities[EntityID]));
}
}
/// <summary>
/// Called when an entity's rotation changed.
/// </summary>
/// <param name="EntityID"></param>
/// <param name="yaw"></param>
/// <param name="pitch"></param>
/// <param name="onGround"></param>
public void OnEntityRotation(int EntityID, float yaw, float pitch, bool onGround)
{
if (entities.ContainsKey(EntityID))
{
entities[EntityID].Yaw = yaw;
entities[EntityID].Pitch = pitch;
DispatchBotEvent(bot => bot.OnEntityRotate(entities[EntityID]));
}
}
/// <summary>

View file

@ -2117,14 +2117,28 @@ namespace MinecraftClient.Protocol.Handlers
}
byte _yaw = dataTypes.ReadNextByte(packetData);
byte _pitch = dataTypes.ReadNextByte(packetData);
float _yaw = dataTypes.ReadNextByte(packetData) * (1F / 256) * 360;
float _pitch = dataTypes.ReadNextByte(packetData) * (1F / 256) * 360;
bool OnGround = dataTypes.ReadNextBool(packetData);
DeltaX = DeltaX / (128 * 32);
DeltaY = DeltaY / (128 * 32);
DeltaZ = DeltaZ / (128 * 32);
handler.OnEntityPosition(EntityID, DeltaX, DeltaY, DeltaZ, OnGround);
handler.OnEntityPosition(EntityID, DeltaX, DeltaY, DeltaZ, _yaw, _pitch, OnGround);
}
break;
case PacketTypesIn.EntityRotation:
if (handler.GetEntityHandlingEnabled())
{
int EntityID = dataTypes.ReadNextVarInt(packetData);
float _yaw = dataTypes.ReadNextByte(packetData) * (1F / 256) * 360;
float _pitch = dataTypes.ReadNextByte(packetData)* (1F / 256) * 360;
bool OnGround = dataTypes.ReadNextBool(packetData);
handler.OnEntityRotation(EntityID, _yaw, _pitch, OnGround);
}
break;

View file

@ -259,6 +259,27 @@ namespace MinecraftClient.Protocol
/// <param name="onGround">TRUE if on ground</param>
void OnEntityPosition(int entityID, Double dx, Double dy, Double dz, bool onGround);
/// <summary>
/// Called when an entity moved and rotated
/// </summary>
/// <param name="EntityID">Entity ID</param>
/// <param name="Dx">X offset</param>
/// <param name="Dy">Y offset</param>
/// <param name="Dz">Z offset</param>
/// <param name="yaw">Yaw</param>
/// <param name="pitch">Pitch</param>
/// <param name="onGround">TRUE if on ground</param>
void OnEntityPosition(int entityID, Double dx, Double dy, Double dz, float yaw, float pitch, bool onGround);
/// <summary>
/// Called when an entity rotated
/// </summary>
/// <param name="EntityID">Entity ID</param>
/// <param name="yaw">Yaw</param>
/// <param name="pitch">Pitch</param>
/// <param name="onGround">TRUE if on ground</param>
void OnEntityRotation(int entityID, float yaw, float pitch, bool onGround);
/// <summary>
/// Called when an entity moved to fixed coordinates
/// </summary>

View file

@ -195,6 +195,12 @@ namespace MinecraftClient.Scripting
/// <param name="entity">Entity with updated location</param>
public virtual void OnEntityMove(Entity entity) { }
/// <summary>
/// Called when an entity rotates
/// </summary>
/// <param name="entity">Entity with updated rotation</param>
public virtual void OnEntityRotate(Entity entity) { }
/// <summary>
/// Called after an internal MCC command has been performed
/// </summary>