diff --git a/MinecraftClient/Commands/Look.cs b/MinecraftClient/Commands/Look.cs index 77c79e6b..7845c77b 100644 --- a/MinecraftClient/Commands/Look.cs +++ b/MinecraftClient/Commands/Look.cs @@ -9,7 +9,7 @@ namespace MinecraftClient.Commands public class Look : Command { public override string CMDName { get { return "look"; } } - public override string CMDDesc { get { return "look : look direction or at block."; } } + public override string CMDDesc { get { return "look : look at direction or coordinates."; } } public override string Run(McTcpClient handler, string command) { @@ -31,18 +31,18 @@ namespace MinecraftClient.Commands default: return "Unknown direction '" + dirStr + "'."; } - handler.LookAtDirection(direction); + handler.UpdateLocation(handler.GetCurrentLocation(), direction); return "Looking " + dirStr; } else if (args.Length == 2) { try { - float yaw = Single.Parse(args[0]), - pitch = Single.Parse(args[1]); + float yaw = Single.Parse(args[0]); + float pitch = Single.Parse(args[1]); - handler.LookAtAngle(yaw, pitch); - return $"Looking at YAW: {yaw} PITCH: {pitch}"; + handler.UpdateLocation(handler.GetCurrentLocation(), yaw, pitch); + return String.Format("Looking at YAW: {0} PITCH: {1}", yaw.ToString("0.00"), pitch.ToString("0.00")); } catch (FormatException) { return CMDDesc; } } @@ -50,14 +50,14 @@ namespace MinecraftClient.Commands { try { - int x = int.Parse(args[0]), - y = int.Parse(args[1]), - z = int.Parse(args[2]); + int x = int.Parse(args[0]); + int y = int.Parse(args[1]); + int z = int.Parse(args[2]); - Location block = new Location(x, y, z); - handler.LookAtBlock(block); + Location block = new Location(x, y, z); + handler.UpdateLocation(handler.GetCurrentLocation(), block); - return "Looking at " + block; + return "Looking at " + block; } catch (FormatException) { return CMDDesc; } diff --git a/MinecraftClient/McTcpClient.cs b/MinecraftClient/McTcpClient.cs index 8732c7e1..b7a15413 100644 --- a/MinecraftClient/McTcpClient.cs +++ b/MinecraftClient/McTcpClient.cs @@ -412,7 +412,8 @@ namespace MinecraftClient /// or if a ChatBot whishes to update the player's location. /// /// The new location - /// If true, the location is relative to the current location + /// Yaw to look at + /// Pitch to look at public void UpdateLocation(Location location, float yaw, float pitch) { this.yaw = yaw; @@ -421,42 +422,37 @@ namespace MinecraftClient } /// - /// Look at specified block + /// Called when the server sends a new player location, + /// or if a ChatBot whishes to update the player's location. /// - /// The block to look at - public void LookAtBlock(Location block) + /// The new location + /// Block coordinates to look at + public void UpdateLocation(Location location, Location lookAtLocation) { - double dx = block.X - (location.X - 0.5), - dy = block.Y - (location.Y + 1), - dz = block.Z - (location.Z - 0.5); + double dx = lookAtLocation.X - (location.X - 0.5); + double dy = lookAtLocation.Y - (location.Y + 1); + double dz = lookAtLocation.Z - (location.Z - 0.5); double r = Math.Sqrt(dx * dx + dy * dy + dz * dz); - float yaw = Convert.ToSingle(-Math.Atan2(dx, dz) / Math.PI * 180), - pitch = Convert.ToSingle(-Math.Asin(dy / r) / Math.PI * 180); + float yaw = Convert.ToSingle(-Math.Atan2(dx, dz) / Math.PI * 180); + float pitch = Convert.ToSingle(-Math.Asin(dy / r) / Math.PI * 180); if (yaw < 0) yaw += 360; UpdateLocation(location, yaw, pitch); } /// - /// Look at specified angle + /// Called when the server sends a new player location, + /// or if a ChatBot whishes to update the player's location. /// - /// The yaw to look at - /// The pitch to look at - public void LookAtAngle(float yaw, float pitch) + /// The new location + /// Direction to look at + public void UpdateLocation(Location location, Direction direction) { - UpdateLocation(location, yaw, pitch); - } + float yaw = 0; + float pitch = 0; - /// - /// Look in specified direction - /// - /// The direction too look in - public void LookAtDirection(Direction direction) - { - float yaw = 0, - pitch = 0; switch (direction) { case Direction.Up: @@ -479,6 +475,7 @@ namespace MinecraftClient default: throw new ArgumentException("Unknown direction", "direction"); } + UpdateLocation(location, yaw, pitch); } @@ -600,13 +597,24 @@ namespace MinecraftClient if (yaw == null || pitch == null) { if (steps != null && steps.Count > 0) + { location = steps.Dequeue(); + } else if (path != null && path.Count > 0) - steps = Movement.Move2Steps(location, path.Dequeue(), ref motionY); - else location = Movement.HandleGravity(world, location, ref motionY); + { + Location next = path.Dequeue(); + steps = Movement.Move2Steps(location, next, ref motionY); + UpdateLocation(location, next); // Update yaw and pitch to look at next step + } + else + { + location = Movement.HandleGravity(world, location, ref motionY); + } } handler.SendLocationUpdate(location, Movement.IsOnGround(world, location), yaw, pitch); } + // First 2 updates must be player position AND look, and player must not move (to conform with vanilla) + // Once yaw and pitch have been sent, switch back to location-only updates (without yaw and pitch) yaw = null; pitch = null; } diff --git a/MinecraftClient/Protocol/Handlers/Protocol18.cs b/MinecraftClient/Protocol/Handlers/Protocol18.cs index 778801c1..a9c42996 100644 --- a/MinecraftClient/Protocol/Handlers/Protocol18.cs +++ b/MinecraftClient/Protocol/Handlers/Protocol18.cs @@ -13,7 +13,7 @@ using MinecraftClient.Mapping; namespace MinecraftClient.Protocol.Handlers { /// - /// Implementation for Minecraft 1.7.X, 1.8.X, 1.9.X, 1.10.X Protocols + /// Implementation for Minecraft 1.7.X+ Protocols /// class Protocol18Handler : IMinecraftCom { @@ -1912,24 +1912,21 @@ namespace MinecraftClient.Protocol.Handlers /// /// The new location of the player /// True if the player is on the ground - /// The new yaw of the player - /// The new pitch of the player + /// Optional new yaw for updating player look + /// Optional new pitch for updating player look /// True if the location update was successfully sent public bool SendLocationUpdate(Location location, bool onGround, float? yaw = null, float? pitch = null) { if (Settings.TerrainAndMovements) { - PacketOutgoingType packetType; byte[] yawpitch = new byte[0]; - if (yaw != null && pitch != null) + PacketOutgoingType packetType = PacketOutgoingType.PlayerPosition; + + if (yaw.HasValue && pitch.HasValue) { - yawpitch = concatBytes(getFloat((float)yaw), getFloat((float)pitch)); + yawpitch = concatBytes(getFloat(yaw.Value), getFloat(pitch.Value)); packetType = PacketOutgoingType.PlayerPositionAndLook; } - else - { - packetType = PacketOutgoingType.PlayerPosition; - } try { diff --git a/MinecraftClient/config/README.txt b/MinecraftClient/config/README.txt index 8f5d693b..0293f250 100644 --- a/MinecraftClient/config/README.txt +++ b/MinecraftClient/config/README.txt @@ -1,6 +1,6 @@ -================================================================================= - Minecraft Client v1.9.0 for Minecraft 1.4.6 to 1.9.0 - By ORelio & Contributors -================================================================================= +================================================================================== + Minecraft Client v1.13.0 for Minecraft 1.4.6 to 1.13.0 - By ORelio & Contributors +================================================================================== Thanks for dowloading Minecraft Console Client! @@ -70,6 +70,7 @@ In scripts and remote control, no slash is needed to perform the command. - set varname=value : set a value which can be used as %varname% in further commands - wait