Look command

This commit is contained in:
Stanley Powers 2019-04-09 18:01:00 -07:00 committed by ORelio
parent 468be97c27
commit 8bfdb2ab59
7 changed files with 119 additions and 17 deletions

View file

@ -635,7 +635,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendLocationUpdate(Location location, bool onGround, byte[] yawpitch)
public bool SendLocationUpdate(Location location, bool onGround, float? yaw, float? pitch)
{
return false; //Currently not implemented
}

View file

@ -618,7 +618,8 @@ namespace MinecraftClient.Protocol.Handlers
double x = readNextDouble(packetData);
double y = readNextDouble(packetData);
double z = readNextDouble(packetData);
byte[] yawpitch = readData(8, packetData);
float yaw = readNextFloat(packetData);
float pitch = readNextFloat(packetData);
byte locMask = readNextByte(packetData);
if (protocolversion >= MC18Version)
@ -627,9 +628,9 @@ namespace MinecraftClient.Protocol.Handlers
location.X = (locMask & 1 << 0) != 0 ? location.X + x : x;
location.Y = (locMask & 1 << 1) != 0 ? location.Y + y : y;
location.Z = (locMask & 1 << 2) != 0 ? location.Z + z : z;
handler.UpdateLocation(location, yawpitch);
handler.UpdateLocation(location, yaw, pitch);
}
else handler.UpdateLocation(new Location(x, y, z), yawpitch);
else handler.UpdateLocation(new Location(x, y, z), yaw, pitch);
}
if (protocolversion >= MC19Version)
@ -1407,6 +1408,17 @@ namespace MinecraftClient.Protocol.Handlers
return BitConverter.ToDouble(rawValue, 0);
}
/// <summary>
/// Read a float from a cache of bytes and remove it from the cache
/// </summary>
/// <returns>The float value</returns>
private static float readNextFloat(List<byte> cache)
{
byte[] rawValue = readData(4, cache);
Array.Reverse(rawValue); //Endianness
return BitConverter.ToSingle(rawValue, 0);
}
/// <summary>
/// Read an integer from the network
/// </summary>
@ -1507,6 +1519,19 @@ namespace MinecraftClient.Protocol.Handlers
return theDouble;
}
/// <summary>
/// Get byte array representing a float
/// </summary>
/// <param name="number">Floalt to process</param>
/// <returns>Array ready to send</returns>
private byte[] getFloat(float number)
{
byte[] theFloat = BitConverter.GetBytes(number);
Array.Reverse(theFloat); //Endianness
return theFloat;
}
/// <summary>
/// Get byte array with length information prepended to it
/// </summary>
@ -1889,18 +1914,19 @@ namespace MinecraftClient.Protocol.Handlers
/// <param name="onGround">True if the player is on the ground</param>
/// <param name="yawpitch">Yaw and pitch (optional and currently not parsed)</param>
/// <returns>True if the location update was successfully sent</returns>
public bool SendLocationUpdate(Location location, bool onGround, byte[] yawpitch = null)
public bool SendLocationUpdate(Location location, bool onGround, float? yaw = null, float? pitch = null)
{
if (Settings.TerrainAndMovements)
{
PacketOutgoingType packetType;
if (yawpitch != null && yawpitch.Length == 8)
byte[] yawpitch = new byte[0];
if (yaw != null && pitch != null)
{
yawpitch = getFloat((float)yaw).Concat(getFloat((float)pitch)).ToArray();
packetType = PacketOutgoingType.PlayerPositionAndLook;
}
else
{
yawpitch = new byte[0];
packetType = PacketOutgoingType.PlayerPosition;
}

View file

@ -72,9 +72,10 @@ namespace MinecraftClient.Protocol
/// </summary>
/// <param name="location">The new location</param>
/// <param name="onGround">True if the player is on the ground</param>
/// <param name="yawpitch">Yaw and pitch (optional and currently not parsed)</param>
/// <param name="yaw">The new yaw (optional)</param>
/// <param name="pitch">The new pitch (optional)</param>
/// <returns>True if packet was successfully sent</returns>
bool SendLocationUpdate(Location location, bool onGround, byte[] yawpitch);
bool SendLocationUpdate(Location location, bool onGround, float? yaw, float? pitch);
/// <summary>
/// Send a plugin channel packet to the server.

View file

@ -55,8 +55,9 @@ namespace MinecraftClient.Protocol
/// Called when the server sets the new location for the player
/// </summary>
/// <param name="location">New location of the player</param>
/// <param name="yawpitch">Yaw and pitch (optional and currently not parsed)</param>
void UpdateLocation(Location location, byte[] yawpitch);
/// <param name="yaw">New yaw</param>
/// <param name="pitch">New pitch</param>
void UpdateLocation(Location location, float yaw, float pitch);
/// <summary>
/// This method is called when the connection has been lost