From 79d981666042de1d7b977baba7d7634af34ffd99 Mon Sep 17 00:00:00 2001 From: CraftBukkit/Spigot Date: Wed, 29 May 2024 06:56:42 +1000 Subject: [PATCH] #1406: Fix incorrect assumption of Fireball having constant speed By: DerFrZocker --- .../craftbukkit/entity/CraftFireball.java | 30 ++++++++++++------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java index 9f212ebc46..206ca3ccde 100644 --- a/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java +++ b/paper-server/src/main/java/org/bukkit/craftbukkit/entity/CraftFireball.java @@ -6,6 +6,7 @@ import org.bukkit.craftbukkit.CraftServer; import org.bukkit.entity.Fireball; import org.bukkit.projectiles.ProjectileSource; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; public class CraftFireball extends AbstractProjectile implements Fireball { public CraftFireball(CraftServer server, EntityFireball entity) { @@ -49,7 +50,7 @@ public class CraftFireball extends AbstractProjectile implements Fireball { @Override public Vector getDirection() { - return new Vector(getHandle().xPower, getHandle().yPower, getHandle().zPower); + return getAcceleration(); } @Override @@ -57,23 +58,32 @@ public class CraftFireball extends AbstractProjectile implements Fireball { Preconditions.checkArgument(direction != null, "Vector direction cannot be null"); if (direction.isZero()) { setVelocity(direction); + setAcceleration(direction); return; } - getHandle().assignPower(direction.getX(), direction.getY(), direction.getZ()); - update(); // SPIGOT-6579 + + direction = direction.clone().normalize(); + setVelocity(direction.clone().multiply(getVelocity().length())); + setAcceleration(direction.multiply(getAcceleration().length())); } @Override - public void setVelocity(Vector velocity) { - Preconditions.checkArgument(velocity != null, "Vector velocity cannot be null"); - // SPIGOT-6993: Allow power to be higher / lower than the normalized direction enforced by #setDirection(Vector) - // Note: Because of MC-80142 the fireball will stutter on the client when setting the velocity to something other than 0 or the normalized vector * 0.1 - getHandle().xPower = velocity.getX(); - getHandle().yPower = velocity.getY(); - getHandle().zPower = velocity.getZ(); + public void setAcceleration(@NotNull Vector acceleration) { + Preconditions.checkArgument(acceleration != null, "Vector acceleration cannot be null"); + // SPIGOT-6993: EntityFireball#assignPower will normalize the given values + // Note: Because of MC-80142 the fireball will stutter on the client when setting the power to something other than 0 or the normalized vector * 0.1 + getHandle().xPower = acceleration.getX(); + getHandle().yPower = acceleration.getY(); + getHandle().zPower = acceleration.getZ(); update(); // SPIGOT-6579 } + @NotNull + @Override + public Vector getAcceleration() { + return new Vector(getHandle().xPower, getHandle().yPower, getHandle().zPower); + } + @Override public EntityFireball getHandle() { return (EntityFireball) entity;