Skip to content

Commit

Permalink
Fix EntityHelper#walkTo doubling entity speed
Browse files Browse the repository at this point in the history
  • Loading branch information
tal5 committed Apr 1, 2023
1 parent 597aff5 commit 5c037c1
Showing 1 changed file with 10 additions and 12 deletions.
Expand Up @@ -289,31 +289,29 @@ public void walkTo(final LivingEntity entity, Location location, Double speed, f
if (entity == null || location == null) {
return;
}
net.minecraft.world.entity.Entity nmsEntityEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntityEntity instanceof Mob)) {
net.minecraft.world.entity.Entity nmsEntity = ((CraftEntity) entity).getHandle();
if (!(nmsEntity instanceof final Mob nmsMob)) {
return;
}
final Mob nmsEntity = (Mob) nmsEntityEntity;
final PathNavigation entityNavigation = nmsEntity.getNavigation();
final PathNavigation entityNavigation = nmsMob.getNavigation();
final Path path;
final boolean aiDisabled = !entity.hasAI();
if (aiDisabled) {
entity.setAI(true);
try {
ENTITY_ONGROUND_SETTER.invoke(nmsEntity, true);
ENTITY_ONGROUND_SETTER.invoke(nmsMob, true);
}
catch (Throwable ex) {
Debug.echoError(ex);
}
}
path = entityNavigation.createPath(location.getX(), location.getY(), location.getZ(), 1);
if (path != null) {
nmsEntity.goalSelector.enableControlFlag(Goal.Flag.MOVE);
nmsMob.goalSelector.enableControlFlag(Goal.Flag.MOVE);
entityNavigation.moveTo(path, 1D);
entityNavigation.setSpeedModifier(2D);
final double oldSpeed = nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).getBaseValue();
final double oldSpeed = nmsMob.getAttribute(Attributes.MOVEMENT_SPEED).getBaseValue();
if (speed != null) {
nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
nmsMob.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(speed);
}
new BukkitRunnable() {
@Override
Expand All @@ -325,15 +323,15 @@ public void run() {
cancel();
return;
}
if (aiDisabled && entity instanceof Wolf) {
((Wolf) entity).setAngry(false);
if (aiDisabled && entity instanceof Wolf wolf) {
wolf.setAngry(false);
}
if (entityNavigation.isDone() || path.isDone()) {
if (callback != null) {
callback.run();
}
if (speed != null) {
nmsEntity.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(oldSpeed);
nmsMob.getAttribute(Attributes.MOVEMENT_SPEED).setBaseValue(oldSpeed);
}
if (aiDisabled) {
entity.setAI(false);
Expand Down

0 comments on commit 5c037c1

Please sign in to comment.