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

@ -788,16 +788,28 @@ namespace MinecraftClient
/// Move to the specified location
/// </summary>
/// <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>
public bool MoveTo(Location location, bool allowUnsafe = false)
public bool MoveTo(Location location, bool allowUnsafe = false, bool allowSmallTeleport = false)
{
lock (locationLock)
{
if (Movement.GetAvailableMoves(world, this.location, allowUnsafe).Contains(location))
path = new Queue<Location>(new[] { location });
else path = Movement.CalculatePath(world, this.location, location, allowUnsafe);
return path != null;
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))
path = new Queue<Location>(new[] { location });
else path = Movement.CalculatePath(world, this.location, location, allowUnsafe);
return path != null;
}
}
}