PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
9.36k stars 2.19k forks source link

A Sniffer's `Pathfinder` does not respond to any commands #10442

Open pontaoski opened 2 months ago

pontaoski commented 2 months ago

Expected behavior

Sniffer responds to pathfinding; i.e. API returns true if appropriate and Sniffer makes its way to the target

Observed/Actual behavior

Sniffer does not respond to pathfinding; API always returns false

Steps/models to reproduce

test plugin code:

public final class TestPlugin extends JavaPlugin implements Listener, CommandExecutor {
    class SnifferCommand extends Command {
        public SnifferCommand() {
            super("sniffer");
        }
        @Override
        public boolean execute(CommandSender sender, String label, String[] args) {
            var player = (Player)sender;
            var sniffer = (Sniffer)player.getWorld().spawnEntity(player.getLocation(), EntityType.SNIFFER);
            var pathfinder = sniffer.getPathfinder();
            sender.sendMessage(pathfinder.hasPath() ? "has path" : "has no path");
            var location = sniffer.getLocation();
            location.add(5, 0, 0);
            var result = pathfinder.moveTo(location);
            sender.sendMessage(result ? "could move to" : "could not move to");
            return true;
        }
    }
    @Override
    public void onEnable() {
        var snifferCommand = new SnifferCommand();
        this.getServer().getCommandMap().register("sniffer", snifferCommand);
        this.getServer().getPluginManager().registerEvents(this, this);
    }
}

run the sniffer command with adequate free space

Plugin and Datapack List

just the test plugin

Paper version

master (a6b6ecdd221b6ae7687561c84c1850aaa62473b4)

Other

No response

electronicboy commented 2 months ago

you may need to delay setting the path by a tick or two, as there's a whole bunch of state that these pathfinders rely upon which is not set until the entity is ticked; outside of that, this stuff is generally not really within our control as it's just interfacing with mojangs system