mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-02 17:32:03 +01:00
#1406: Fix incorrect assumption of Fireball having constant speed
By: DerFrZocker <derrieple@gmail.com>
This commit is contained in:
parent
4691102616
commit
79d9816660
1 changed files with 20 additions and 10 deletions
|
@ -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;
|
||||
|
|
Loading…
Reference in a new issue