mirror of
https://github.com/MCCTeam/Minecraft-Console-Client
synced 2025-10-14 21:22:49 +00:00
Add basic location handling
- Retrieve player location from the server - Send back player location from the server - Requires that a specific setting is enabled - Should allow items to be picked up by the player - May also trigger some anti chead plugins
This commit is contained in:
parent
5654871a57
commit
72bd485e67
11 changed files with 319 additions and 17 deletions
|
|
@ -8,6 +8,7 @@ using MinecraftClient.Crypto;
|
|||
using MinecraftClient.Proxy;
|
||||
using System.Security.Cryptography;
|
||||
using MinecraftClient.Protocol.Handlers.Forge;
|
||||
using MinecraftClient.Mapping;
|
||||
|
||||
namespace MinecraftClient.Protocol.Handlers
|
||||
{
|
||||
|
|
@ -162,6 +163,23 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
catch (IndexOutOfRangeException) { /* No message type */ }
|
||||
handler.OnTextReceived(ChatParser.ParseText(message));
|
||||
break;
|
||||
case 0x08:
|
||||
if (Settings.TerrainAndMovements)
|
||||
{
|
||||
double x = readNextDouble(ref packetData);
|
||||
double y = readNextDouble(ref packetData);
|
||||
double z = readNextDouble(ref packetData);
|
||||
|
||||
byte locMask = readNextByte(ref packetData);
|
||||
Location location = handler.GetCurrentLocation();
|
||||
|
||||
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);
|
||||
}
|
||||
break;
|
||||
case 0x38: //Player List update
|
||||
if (protocolversion >= MC18Version)
|
||||
{
|
||||
|
|
@ -509,6 +527,18 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return readData(len, ref cache);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read a double from a cache of bytes and remove it from the cache
|
||||
/// </summary>
|
||||
/// <returns>The double value</returns>
|
||||
|
||||
private static double readNextDouble(ref byte[] cache)
|
||||
{
|
||||
byte[] rawValue = readData(8, ref cache);
|
||||
Array.Reverse(rawValue); //Endianness
|
||||
return BitConverter.ToDouble(rawValue, 0);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read an integer from the network
|
||||
/// </summary>
|
||||
|
|
@ -602,6 +632,19 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return bytes.ToArray();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get byte array representing a double
|
||||
/// </summary>
|
||||
/// <param name="array">Array to process</param>
|
||||
/// <returns>Array ready to send</returns>
|
||||
|
||||
private byte[] getDouble(double number)
|
||||
{
|
||||
byte[] theDouble = BitConverter.GetBytes(number);
|
||||
Array.Reverse(theDouble); //Endianness
|
||||
return theDouble;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Get byte array with length information prepended to it
|
||||
/// </summary>
|
||||
|
|
@ -931,6 +974,29 @@ namespace MinecraftClient.Protocol.Handlers
|
|||
return SendPluginChannelPacket("MC|Brand", getString(brandInfo));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a location update to the server
|
||||
/// </summary>
|
||||
/// <param name="location">The new location of the player</param>
|
||||
/// <param name="onGround">True if the player is on the ground</param>
|
||||
/// <returns>True if the location update was successfully sent</returns>
|
||||
|
||||
public bool SendLocationUpdate(Location location, bool onGround)
|
||||
{
|
||||
if (Settings.TerrainAndMovements)
|
||||
{
|
||||
try
|
||||
{
|
||||
SendPacket(0x04, concatBytes(
|
||||
getDouble(location.X), getDouble(location.X), getDouble(location.X),
|
||||
new byte[] { onGround ? (byte)1 : (byte)0 }));
|
||||
return true;
|
||||
}
|
||||
catch (SocketException) { return false; }
|
||||
}
|
||||
else return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Send a plugin channel packet (0x17) to the server, compression and encryption will be handled automatically
|
||||
/// </summary>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue