FakePlayer now implements NavigableEntity

This commit is contained in:
themode 2021-02-20 09:15:08 +01:00
parent a419d7eb3f
commit 721f9abc08
2 changed files with 33 additions and 5 deletions

View File

@ -86,9 +86,9 @@ public abstract class EntityCreature extends LivingEntity implements NavigableEn
@Override @Override
public void setInstance(@NotNull Instance instance) { public void setInstance(@NotNull Instance instance) {
super.setInstance(instance);
this.navigator.setPathFinder(new HydrazinePathFinder(navigator.getPathingEntity(), instance.getInstanceSpace())); this.navigator.setPathFinder(new HydrazinePathFinder(navigator.getPathingEntity(), instance.getInstanceSpace()));
super.setInstance(instance);
} }
@Override @Override

View File

@ -1,8 +1,13 @@
package net.minestom.server.entity.fakeplayer; package net.minestom.server.entity.fakeplayer;
import com.extollit.gaming.ai.path.HydrazinePathFinder;
import net.minestom.server.MinecraftServer; import net.minestom.server.MinecraftServer;
import net.minestom.server.attribute.Attributes;
import net.minestom.server.entity.Player; import net.minestom.server.entity.Player;
import net.minestom.server.entity.pathfinding.NavigableEntity;
import net.minestom.server.entity.pathfinding.Navigator;
import net.minestom.server.event.player.PlayerSpawnEvent; import net.minestom.server.event.player.PlayerSpawnEvent;
import net.minestom.server.instance.Instance;
import net.minestom.server.network.ConnectionManager; import net.minestom.server.network.ConnectionManager;
import net.minestom.server.network.player.FakePlayerConnection; import net.minestom.server.network.player.FakePlayerConnection;
import net.minestom.server.network.player.PlayerConnection; import net.minestom.server.network.player.PlayerConnection;
@ -21,13 +26,15 @@ import java.util.function.Consumer;
* You can create one using {@link #initPlayer(UUID, String, Consumer)}. Be aware that this really behave exactly like a player * You can create one using {@link #initPlayer(UUID, String, Consumer)}. Be aware that this really behave exactly like a player
* and this is a feature not a bug, you will need to check at some place if the player is a fake one or not (instanceof) if you want to change it. * and this is a feature not a bug, you will need to check at some place if the player is a fake one or not (instanceof) if you want to change it.
*/ */
public class FakePlayer extends Player { public class FakePlayer extends Player implements NavigableEntity {
private static final ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager(); private static final ConnectionManager CONNECTION_MANAGER = MinecraftServer.getConnectionManager();
private final FakePlayerOption option; private final FakePlayerOption option;
private final FakePlayerController fakePlayerController; private final FakePlayerController fakePlayerController;
private final Navigator navigator = new Navigator(this);
/** /**
* Initializes a new {@link FakePlayer} with the given {@code uuid}, {@code username} and {@code option}'s. * Initializes a new {@link FakePlayer} with the given {@code uuid}, {@code username} and {@code option}'s.
* *
@ -36,8 +43,8 @@ public class FakePlayer extends Player {
* @param option Any option for the fake player. * @param option Any option for the fake player.
*/ */
protected FakePlayer(@NotNull UUID uuid, @NotNull String username, protected FakePlayer(@NotNull UUID uuid, @NotNull String username,
@NotNull FakePlayerOption option, @NotNull FakePlayerOption option,
@Nullable Consumer<FakePlayer> spawnCallback) { @Nullable Consumer<FakePlayer> spawnCallback) {
super(uuid, username, new FakePlayerConnection()); super(uuid, username, new FakePlayerConnection());
this.option = option; this.option = option;
@ -102,6 +109,21 @@ public class FakePlayer extends Player {
return fakePlayerController; return fakePlayerController;
} }
@Override
public void update(long time) {
super.update(time);
// Path finding
this.navigator.tick(getAttributeValue(Attributes.MOVEMENT_SPEED));
}
@Override
public void setInstance(@NotNull Instance instance) {
this.navigator.setPathFinder(new HydrazinePathFinder(navigator.getPathingEntity(), instance.getInstanceSpace()));
super.setInstance(instance);
}
/** /**
* {@inheritDoc} * {@inheritDoc}
*/ */
@ -114,4 +136,10 @@ public class FakePlayer extends Player {
} }
} }
@NotNull
@Override
public Navigator getNavigator() {
return navigator;
}
} }