Allow bots to perform small teleports (#1067)

Small teleport jumps within a 4-block ranges.
May cause invalid moves and/or trigger anti-cheat plugins.
This commit is contained in:
ORelio 2020-06-14 15:41:34 +02:00
parent ab05d697ef
commit ee8bc7f308
2 changed files with 23 additions and 10 deletions

View file

@ -730,7 +730,7 @@ namespace MinecraftClient
/// </summary> /// </summary>
protected void SetSlot(int slotNum) protected void SetSlot(int slotNum)
{ {
Handler.ChangeSlot((short) slotNum); Handler.ChangeSlot((short)slotNum);
} }
/// <summary> /// <summary>
@ -757,11 +757,12 @@ namespace MinecraftClient
/// Move to the specified location /// Move to the specified location
/// </summary> /// </summary>
/// <param name="location">Location to reach</param> /// <param name="location">Location to reach</param>
/// <param name="allowUnsafe">Allow possible but unsafe locations</param> /// <param name="allowUnsafe">Allow possible but unsafe locations thay may hurt the player: lava, cactus...</param>
/// <param name="allowSmallTeleport">Allow non-vanilla small teleport instead of computing path, but may cause invalid moves and/or trigger anti-cheat plugins</param>
/// <returns>True if a path has been found</returns> /// <returns>True if a path has been found</returns>
protected bool MoveToLocation(Mapping.Location location, bool allowUnsafe = false) protected bool MoveToLocation(Mapping.Location location, bool allowUnsafe = false, bool allowSmallTeleport = false)
{ {
return Handler.MoveTo(location, allowUnsafe); return Handler.MoveTo(location, allowUnsafe, allowSmallTeleport);
} }
/// <summary> /// <summary>

View file

@ -788,18 +788,30 @@ namespace MinecraftClient
/// Move to the specified location /// Move to the specified location
/// </summary> /// </summary>
/// <param name="location">Location to reach</param> /// <param name="location">Location to reach</param>
/// <param name="allowUnsafe">Allow possible but unsafe locations</param> /// <param name="allowUnsafe">Allow possible but unsafe locations thay may hurt the player: lava, cactus...</param>
/// <param name="allowSmallTeleport">Allow non-vanilla small teleport instead of computing path, but may cause invalid moves and/or trigger anti-cheat plugins</param>
/// <returns>True if a path has been found</returns> /// <returns>True if a path has been found</returns>
public bool MoveTo(Location location, bool allowUnsafe = false) public bool MoveTo(Location location, bool allowUnsafe = false, bool allowSmallTeleport = false)
{ {
lock (locationLock) lock (locationLock)
{ {
if (allowSmallTeleport && location.DistanceSquared(this.location) <= 16)
{
// Allow small teleport within a range of 4 blocks. 1-step path to the desired location without checking anything
path = null;
steps = new Queue<Location>(new[] { location });
return true;
}
else
{
// Calculate path through pathfinding. Path contains a list of 1-block movement that will be divided into steps
if (Movement.GetAvailableMoves(world, this.location, allowUnsafe).Contains(location)) if (Movement.GetAvailableMoves(world, this.location, allowUnsafe).Contains(location))
path = new Queue<Location>(new[] { location }); path = new Queue<Location>(new[] { location });
else path = Movement.CalculatePath(world, this.location, location, allowUnsafe); else path = Movement.CalculatePath(world, this.location, location, allowUnsafe);
return path != null; return path != null;
} }
} }
}
/// <summary> /// <summary>
/// Received some text from the server /// Received some text from the server