DigBlock/PlaceBlock: Use Direction enum

Still work in progress (#1071)
This commit is contained in:
ORelio 2020-06-20 16:07:54 +02:00
parent c69e87bec3
commit 6df5076d19
7 changed files with 62 additions and 69 deletions

View file

@ -828,6 +828,25 @@ namespace MinecraftClient.Protocol.Handlers
return slotData.ToArray();
}
/// <summary>
/// Get protocol block face from Direction
/// </summary>
/// <param name="direction">Direction</param>
/// <returns>Block face byte enum</returns>
public byte GetBlockFace(Direction direction)
{
switch (direction)
{
case Direction.Down: return 0;
case Direction.Up: return 1;
case Direction.North: return 2;
case Direction.South: return 3;
case Direction.West: return 4;
case Direction.East: return 5;
default: throw new NotImplementedException("Unknown direction: " + direction.ToString());
}
}
/// <summary>
/// Easily append several byte arrays
/// </summary>

View file

@ -713,7 +713,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendPlayerBlockPlacement(int hand, Location location, int face, float CursorX, float CursorY, float CursorZ, bool insideBlock)
public bool SendPlayerBlockPlacement(int hand, Location location, Direction face)
{
return false; //Currently not implemented
}
@ -723,7 +723,7 @@ namespace MinecraftClient.Protocol.Handlers
return false; //Currently not implemented
}
public bool SendPlayerDigging(int status, Location location, byte face)
public bool SendPlayerDigging(int status, Location location, Direction face)
{
return false; //Currently not implemented
}

View file

@ -1390,15 +1390,14 @@ namespace MinecraftClient.Protocol.Handlers
catch (ObjectDisposedException) { return false; }
}
public bool SendPlayerDigging(int status, Location location, byte face)
public bool SendPlayerDigging(int status, Location location, Direction face)
{
try
{
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetVarInt(status));
packet.AddRange(dataTypes.GetLocation(location));
packet.AddRange(dataTypes.GetVarInt(face));
packet.AddRange(dataTypes.GetVarInt(dataTypes.GetBlockFace(face)));
SendPacket(PacketOutgoingType.PlayerDigging, packet);
return true;
}
@ -1406,8 +1405,8 @@ namespace MinecraftClient.Protocol.Handlers
catch (System.IO.IOException) { return false; }
catch (ObjectDisposedException) { return false; }
}
public bool SendPlayerBlockPlacement(int hand, Location location, int face, float CursorX, float CursorY, float CursorZ, bool insideBlock)
public bool SendPlayerBlockPlacement(int hand, Location location, Direction face)
{
if (protocolversion < MC114Version)
return false; // NOT IMPLEMENTED for older MC versions
@ -1416,12 +1415,11 @@ namespace MinecraftClient.Protocol.Handlers
List<byte> packet = new List<byte>();
packet.AddRange(dataTypes.GetVarInt(hand));
packet.AddRange(dataTypes.GetLocation(location));
packet.AddRange(dataTypes.GetVarInt(face));
packet.AddRange(dataTypes.GetFloat(CursorX));
packet.AddRange(dataTypes.GetFloat(CursorY));
packet.AddRange(dataTypes.GetFloat(CursorZ));
packet.Add(Convert.ToByte(insideBlock ? 1 : 0));
packet.AddRange(dataTypes.GetVarInt(dataTypes.GetBlockFace(face)));
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorX
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorY
packet.AddRange(dataTypes.GetFloat(0.5f)); // cursorZ
packet.Add(0); // insideBlock = false;
SendPacket(PacketOutgoingType.PlayerBlockPlacement, packet);
return true;
}