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

@ -745,14 +745,14 @@ namespace MinecraftClient
}
/// <summary>
/// Dig block - WORK IN PROGRESS - MAY NOT WORK
/// Dig block
/// </summary>
/// <param name="status"></param>
/// <param name="location"></param>
/// <param name="face"></param>
protected void DigBlock(int status, Location location, byte face)
/// <param name="status">0 to start digging, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging )</param>
/// <param name="location">Location</param>
/// <param name="face">Block face</param>
protected void DigBlock(int status, Location location, Direction blockFace)
{
Handler.DigBlock(status, location, face);
Handler.DigBlock(status, location, blockFace);
}
/// <summary>
@ -1015,9 +1015,9 @@ namespace MinecraftClient
/// </summary>
/// <param name="location">Block location</param>
/// <returns></returns>
protected bool SendPlaceBlock(Location location, int face)
protected bool SendPlaceBlock(Location location, Direction blockFace)
{
return Handler.PlaceBlock(location, face);
return Handler.PlaceBlock(location, blockFace);
}
/// <summary>

View file

@ -22,7 +22,7 @@ namespace MinecraftClient.Commands
int x = Convert.ToInt32(args[0]);
int y = Convert.ToInt32(args[1]);
int z = Convert.ToInt32(args[2]);
handler.PlaceBlock(new Location(x, y, z), 0);
handler.PlaceBlock(new Location(x, y, z), Direction.Down);
}
else { return CMDDesc; }
}

View file

@ -1015,52 +1015,22 @@ namespace MinecraftClient
/// Place the block at hand in the Minecraft world
/// </summary>
/// <param name="location">Location to place block to</param>
/// <param name="blockface">Block face</param>
/// <param name="blockFace">Block face (e.g. Direction.Down when clicking on the block below to place this block)</param>
/// <returns>TRUE if successfully placed</returns>
public bool PlaceBlock(Location location, int blockface)
public bool PlaceBlock(Location location, Direction blockFace)
{
if (Settings.DebugMessages)
ConsoleIO.WriteLogLine(location.ToString());
Location placelocation;
if (blockface == 1)
{
placelocation = new Location(location.X, location.Y - 1, location.Z);
}
else if (blockface == 2)
{
placelocation = new Location(location.X, location.Y, location.Z + 1);
}
else if (blockface == 3)
{
placelocation = new Location(location.X, location.Y, location.Z - 1);
}
else if (blockface == 4)
{
placelocation = new Location(location.X + 1, location.Y, location.Z);
}
else if (blockface == 5)
{
placelocation = new Location(location.X - 1, location.Y, location.Z);
}
else
{
placelocation = location;
}
return handler.SendPlayerBlockPlacement(0, placelocation, blockface, 0.5f, 0.5f, 0.5f, false);
return handler.SendPlayerBlockPlacement(0, location, blockFace);
}
/// <summary>
/// Dig block - WORK IN PROGRESS - MAY NOT WORK YET
/// Dig block. This method needs to be called at least twice: Once to begin digging, then a second time to finish digging
/// </summary>
/// <param name="status"></param>
/// <param name="location"></param>
/// <param name="face"></param>
public bool DigBlock(int status, Location location, byte Face)
/// <param name="status">0 to start digging, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging )</param>
/// <param name="location">Location of block to dig</param>
/// <param name="blockFace">Block face (e.g. Direction.Up when digging from above)</param>
public bool DigBlock(int status, Location location, Direction blockFace)
{
if (Settings.DebugMessages)
ConsoleIO.WriteLogLine(location.ToString());
Location placelocation = new Location(location.X, location.Y, location.Z);
return handler.SendPlayerDigging(status, placelocation, 1);
return handler.SendPlayerDigging(status, location, blockFace);
}
/// <summary>

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;
}
@ -1407,7 +1406,7 @@ namespace MinecraftClient.Protocol.Handlers
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;
}

View file

@ -179,21 +179,27 @@ namespace MinecraftClient.Protocol
/// <param name="hand">0: main hand, 1: off hand</param>
/// <param name="location">Location to place block at</param>
/// <param name="face">Block face</param>
/// <param name="CursorX">Cursor X</param>
/// <param name="CursorY">Cursor Y</param>
/// <param name="CursorZ">Cursor Z</param>
/// <param name="insideBlock">TRUE if inside block</param>
/// <returns>True if packet was successfully sent</returns>
bool SendPlayerBlockPlacement(int hand, Location location, int face, float CursorX, float CursorY, float CursorZ, bool insideBlock);
bool SendPlayerBlockPlacement(int hand, Location location, Direction face);
/// <summary>
/// Send player blog digging packet to the server
/// </summary>
/// <param name="status">0 to start diffing, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging )</param>
/// <param name="status">0 to start digging, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging )</param>
/// <param name="location">Location</param>
/// <param name="face">Block face: 0 = bottom, 1 = top, etc (see wiki)</param>
/// <param name="face">Block face</param>
/// <returns>True if packet was succcessfully sent</returns>
bool SendPlayerDigging(int status, Location location, Direction face);
/// <summary>
/// Change text on a sign
/// </summary>
/// <param name="location">Location of Sign block</param>
/// <param name="line1">New line 1</param>
/// <param name="line2">New line 2</param>
/// <param name="line3">New line 3</param>
/// <param name="line4">New line 4</param>
/// <returns>True if packet was succcessfully sent</returns>
bool SendPlayerDigging(int status, Location location, byte face);
bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4);
}
}