diff --git a/MinecraftClient/ChatBot.cs b/MinecraftClient/ChatBot.cs index 65a36a3c..b00e64ec 100644 --- a/MinecraftClient/ChatBot.cs +++ b/MinecraftClient/ChatBot.cs @@ -745,14 +745,14 @@ namespace MinecraftClient } /// - /// Dig block - WORK IN PROGRESS - MAY NOT WORK + /// Dig block /// - /// - /// - /// - protected void DigBlock(int status, Location location, byte face) + /// 0 to start digging, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging ) + /// Location + /// Block face + protected void DigBlock(int status, Location location, Direction blockFace) { - Handler.DigBlock(status, location, face); + Handler.DigBlock(status, location, blockFace); } /// @@ -1015,9 +1015,9 @@ namespace MinecraftClient /// /// Block location /// - protected bool SendPlaceBlock(Location location, int face) + protected bool SendPlaceBlock(Location location, Direction blockFace) { - return Handler.PlaceBlock(location, face); + return Handler.PlaceBlock(location, blockFace); } /// diff --git a/MinecraftClient/Commands/Useblock.cs b/MinecraftClient/Commands/Useblock.cs index a97b07a5..f9fb2f81 100644 --- a/MinecraftClient/Commands/Useblock.cs +++ b/MinecraftClient/Commands/Useblock.cs @@ -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; } } diff --git a/MinecraftClient/McClient.cs b/MinecraftClient/McClient.cs index a098fd87..bee01020 100644 --- a/MinecraftClient/McClient.cs +++ b/MinecraftClient/McClient.cs @@ -1015,52 +1015,22 @@ namespace MinecraftClient /// Place the block at hand in the Minecraft world /// /// Location to place block to - /// Block face + /// Block face (e.g. Direction.Down when clicking on the block below to place this block) /// TRUE if successfully placed - 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); } /// - /// 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 /// - /// - /// - /// - public bool DigBlock(int status, Location location, byte Face) + /// 0 to start digging, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging ) + /// Location of block to dig + /// Block face (e.g. Direction.Up when digging from above) + 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); } /// diff --git a/MinecraftClient/Protocol/Handlers/DataTypes.cs b/MinecraftClient/Protocol/Handlers/DataTypes.cs index b808a1f4..a33c5545 100644 --- a/MinecraftClient/Protocol/Handlers/DataTypes.cs +++ b/MinecraftClient/Protocol/Handlers/DataTypes.cs @@ -828,6 +828,25 @@ namespace MinecraftClient.Protocol.Handlers return slotData.ToArray(); } + /// + /// Get protocol block face from Direction + /// + /// Direction + /// Block face byte enum + 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()); + } + } + /// /// Easily append several byte arrays /// diff --git a/MinecraftClient/Protocol/Handlers/Protocol16.cs b/MinecraftClient/Protocol/Handlers/Protocol16.cs index b0617e0a..9c14ffec 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol16.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol16.cs @@ -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 } diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 3c9b2c06..7e35711a 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -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 packet = new List(); 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 packet = new List(); 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; } diff --git a/MinecraftClient/Protocol/IMinecraftCom.cs b/MinecraftClient/Protocol/IMinecraftCom.cs index 657ae372..b190384f 100644 --- a/MinecraftClient/Protocol/IMinecraftCom.cs +++ b/MinecraftClient/Protocol/IMinecraftCom.cs @@ -179,21 +179,27 @@ namespace MinecraftClient.Protocol /// 0: main hand, 1: off hand /// Location to place block at /// Block face - /// Cursor X - /// Cursor Y - /// Cursor Z - /// TRUE if inside block /// True if packet was successfully sent - bool SendPlayerBlockPlacement(int hand, Location location, int face, float CursorX, float CursorY, float CursorZ, bool insideBlock); + bool SendPlayerBlockPlacement(int hand, Location location, Direction face); /// /// Send player blog digging packet to the server /// - /// 0 to start diffing, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging ) + /// 0 to start digging, 1 to cancel, 2 to finish ( https://wiki.vg/Protocol#Player_Digging ) /// Location - /// Block face: 0 = bottom, 1 = top, etc (see wiki) + /// Block face + /// True if packet was succcessfully sent + bool SendPlayerDigging(int status, Location location, Direction face); + + /// + /// Change text on a sign + /// + /// Location of Sign block + /// New line 1 + /// New line 2 + /// New line 3 + /// New line 4 /// True if packet was succcessfully sent - bool SendPlayerDigging(int status, Location location, byte face); bool SendUpdateSign(Location location, string line1, string line2, string line3, string line4); } }