mirror of
https://github.com/PaperMC/Paper.git
synced 2025-01-03 23:07:40 +01:00
Configurable projectile relative velocity
This patch adds an option "disable relative projectile velocity", which, when enabled, will cause projectiles to ignore the shooter's current velocity, like they did in Minecraft 1.8 and prior. If a player is falling, for example, their shooting range will be drastically reduced, as a downwards velocity is applied to the projectile. This prevents players from saving themselves from falling off floating islands, for example, as a thrown ender pearl will not make it back to the island, while it would have in 1.8. While this could easily be done with plugins, too, there are multiple problems: P1) If multiple plugins cancel the velocity by subtracting the shooter's velocity from the projectile's velocity, the projectile's velocity would be different. As there's no way to detect whether the projectile's velocity has already been adjusted to ignore the player's velocity, plugins can't not do it if it's not necessary. P2) I've noticed some inconsistencies, e.g. weird velocity when shooting while using an elytra. Checking for those inconsistencies is possible, but not as efficient as just not applying the velocity in the first place. P3) Solutions for 1) and especially 2) might not be future-proof, while this server-internal fix makes this change future-proof.
This commit is contained in:
parent
2cd6ace7ab
commit
a89e4e6ae3
@ -29,7 +29,16 @@
|
||||
|
||||
}
|
||||
|
||||
@@ -189,7 +197,12 @@
|
||||
@@ -184,12 +192,20 @@
|
||||
|
||||
this.shoot((double) f5, (double) f6, (double) f7, speed, divergence);
|
||||
Vec3 vec3d = shooter.getKnownMovement();
|
||||
-
|
||||
+ // Paper start - allow disabling relative velocity
|
||||
+ if (!shooter.level().paperConfig().misc.disableRelativeProjectileVelocity) {
|
||||
this.setDeltaMovement(this.getDeltaMovement().add(vec3d.x, shooter.onGround() ? 0.0D : vec3d.y, vec3d.z));
|
||||
+ }
|
||||
+ // Paper end - allow disabling relative velocity
|
||||
}
|
||||
|
||||
public static <T extends Projectile> T spawnProjectileFromRotation(Projectile.ProjectileFactory<T> creator, ServerLevel world, ItemStack projectileStack, LivingEntity shooter, float roll, float power, float divergence) {
|
||||
@ -43,7 +52,7 @@
|
||||
iprojectile.shootFromRotation(shooter, shooter.getXRot(), shooter.getYRot(), roll, power, divergence);
|
||||
});
|
||||
}
|
||||
@@ -201,7 +214,12 @@
|
||||
@@ -201,7 +217,12 @@
|
||||
}
|
||||
|
||||
public static <T extends Projectile> T spawnProjectileUsingShoot(T projectile, ServerLevel world, ItemStack projectileStack, double velocityX, double velocityY, double velocityZ, float power, float divergence) {
|
||||
@ -57,10 +66,12 @@
|
||||
projectile.shoot(velocityX, velocityY, velocityZ, power, divergence);
|
||||
});
|
||||
}
|
||||
@@ -211,11 +229,45 @@
|
||||
@@ -209,13 +230,47 @@
|
||||
public static <T extends Projectile> T spawnProjectile(T projectile, ServerLevel world, ItemStack projectileStack) {
|
||||
return Projectile.spawnProjectile(projectile, world, projectileStack, (iprojectile) -> {
|
||||
});
|
||||
}
|
||||
|
||||
+ }
|
||||
+
|
||||
+ // Paper start - delayed projectile spawning
|
||||
+ public record Delayed<T extends Projectile>(
|
||||
+ T projectile,
|
||||
@ -89,9 +100,9 @@
|
||||
+ this.attemptSpawn(reason);
|
||||
+ return projectile();
|
||||
+ }
|
||||
+ }
|
||||
}
|
||||
+ // Paper end - delayed projectile spawning
|
||||
+
|
||||
|
||||
public static <T extends Projectile> T spawnProjectile(T projectile, ServerLevel world, ItemStack projectileStack, Consumer<T> beforeSpawn) {
|
||||
+ // Paper start - delayed projectile spawning
|
||||
+ return spawnProjectileDelayed(projectile, world, projectileStack, beforeSpawn).spawn();
|
||||
@ -106,7 +117,7 @@
|
||||
}
|
||||
|
||||
public void applyOnProjectileSpawned(ServerLevel world, ItemStack projectileStack) {
|
||||
@@ -232,6 +284,17 @@
|
||||
@@ -232,6 +287,17 @@
|
||||
|
||||
}
|
||||
|
||||
@ -124,7 +135,7 @@
|
||||
protected ProjectileDeflection hitTargetOrDeflectSelf(HitResult hitResult) {
|
||||
if (hitResult.getType() == HitResult.Type.ENTITY) {
|
||||
EntityHitResult movingobjectpositionentity = (EntityHitResult) hitResult;
|
||||
@@ -309,6 +372,11 @@
|
||||
@@ -309,6 +375,11 @@
|
||||
protected void onHitEntity(EntityHitResult entityHitResult) {}
|
||||
|
||||
protected void onHitBlock(BlockHitResult blockHitResult) {
|
||||
@ -136,7 +147,7 @@
|
||||
BlockState iblockdata = this.level().getBlockState(blockHitResult.getBlockPos());
|
||||
|
||||
iblockdata.onProjectileHit(this.level(), iblockdata, blockHitResult, this);
|
||||
@@ -320,6 +388,15 @@
|
||||
@@ -320,6 +391,15 @@
|
||||
} else {
|
||||
Entity entity1 = this.getOwner();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user