Paper icon indicating copy to clipboard operation
Paper copied to clipboard

Mob Pathfinder does not work after it switches worlds

Open MCD4U opened this issue 3 years ago • 4 comments
trafficstars

Expected behavior

The mob pathfinder (more specifically using the Pathfinder interface) should be functional regardless of which world it is in.

Observed/Actual behavior

After teleporting a mob to different world (different from the one it spawned in), calling moveTo to any valid location (in the new world) will result in the mob not being able to calculate a path, and as a result won't move to that location.

Steps/models to reproduce

Spawn a mob, then call moveTo or findPath on its pathfinder to verify that it can compute paths. Then teleport the mob to a different world, and call moveTo or findPath again, the mob will not be able to compute a path and so it won't move.

Plugin and Datapack List

None

Paper version

[12:01:14 INFO]: This server is running Paper version git-Paper-163 (MC: 1.18.1) (Implementing API version 1.18.1-R0.1-SNAPSHOT) (Git: 4533821)
You are running the latest version

Other

No response

MCD4U avatar Jan 19 '22 05:01 MCD4U

Try to reproduce on 1.18.1.

If it happens, it's likely a bug in spigot. Only exposed due the fact that paper users can trigger path finding. The same behaviour should be observable on Spigot, too. The API only interacts with the pathfinder portion in NMS.

yannicklamprecht avatar Jan 19 '22 10:01 yannicklamprecht

Ok I was able to reproduce it on 1.18.1. I'm not sure how to test it on spigot since pathfinder is not exposed. I would also like to mention that normal targeting behaviour still works (i.e. setting the mob's target so that it will pathfind to the mob.)

MCD4U avatar Jan 19 '22 17:01 MCD4U

need reproduction code

You're not storing the pathfinder and trying to use the already created instance after teleporting, are you?

electronicboy avatar Jan 19 '22 17:01 electronicboy

No, I'm not storing the pathfinder. This is the code I used (it's pretty ugly):

public class LolCommand implements CommandExecutor {
    private Mob mob;
    //since I didn't want to use multiverse (for testing)
    private World otherWorld = Bukkit.createWorld(new WorldCreator("world2"));

    @Override
    public boolean onCommand(@NotNull CommandSender sender, @NotNull Command command, @NotNull String label, @NotNull String[] args) {
        if (sender instanceof Player) {
            final Player player = (Player) sender;
            if (mob == null) {
                mob = (Mob) player.getWorld().spawnEntity(player.getLocation(), EntityType.HUSK);
                return true;
            }
            if (args.length == 1 && args[0].equals("world")) {
                player.teleport(otherWorld.getSpawnLocation());
            } else if (args.length == 1 && args[0].equals("teleport")) {
                mob.teleport(player.getLocation());
            } else if (args.length == 4 && args[0].equals("move")) {
                mob.getPathfinder().moveTo(new Location(
                        player.getWorld(),
                        Double.parseDouble(args[1]),
                        Double.parseDouble(args[2]),
                        Double.parseDouble(args[3])
                ));
            }
        }
        return true;
    }
}

MCD4U avatar Jan 19 '22 19:01 MCD4U