2024-06-13 20:09:28 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Brokkonaut <hannos17@gmx.de>
Date: Tue, 31 Oct 2017 03:26:18 +0100
Subject: [PATCH] Send attack SoundEffects only to players who can see the
attacker
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
2024-07-06 21:19:14 +02:00
index 362d75522aaa721e9fb1d12a149d0efec1ac17b1..34654395536ea022848db3d9f0291512081fc558 100644
2024-06-13 20:09:28 +02:00
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
2024-07-06 21:19:14 +02:00
@@ -1257,7 +1257,7 @@ public abstract class Player extends LivingEntity {
2024-06-13 20:09:28 +02:00
boolean flag1;
if (this.isSprinting() && flag) {
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
flag1 = true;
} else {
flag1 = false;
2024-07-06 21:19:14 +02:00
@@ -1338,7 +1338,7 @@ public abstract class Player extends LivingEntity {
2024-06-13 20:09:28 +02:00
}
}
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0F, 1.0F);
2024-06-23 22:03:32 +02:00
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
this.sweepAttack();
}
2024-06-13 20:09:28 +02:00
2024-07-06 21:19:14 +02:00
@@ -1366,15 +1366,15 @@ public abstract class Player extends LivingEntity {
2024-06-13 20:09:28 +02:00
}
2024-06-23 22:03:32 +02:00
if (flag2) {
2024-06-13 20:09:28 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0F, 1.0F);
2024-06-23 22:03:32 +02:00
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
this.crit(target);
}
2024-06-13 20:09:28 +02:00
2024-06-23 22:03:32 +02:00
if (!flag2 && !flag3) {
if (flag) {
2024-06-13 20:09:28 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0F, 1.0F);
2024-06-23 22:03:32 +02:00
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
} else {
2024-06-13 20:09:28 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0F, 1.0F);
2024-06-23 22:03:32 +02:00
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
2024-06-13 20:09:28 +02:00
}
}
2024-07-06 21:19:14 +02:00
@@ -1430,7 +1430,7 @@ public abstract class Player extends LivingEntity {
2024-06-13 20:09:28 +02:00
2024-06-23 22:03:32 +02:00
this.causeFoodExhaustion(this.level().spigotConfig.combatExhaustion, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent // Spigot - Change to use configurable value
} else {
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
// CraftBukkit start - resync on cancelled event
if (this instanceof ServerPlayer) {
((ServerPlayer) this).getBukkitEntity().updateInventory();
2024-07-06 21:19:14 +02:00
@@ -1825,6 +1825,14 @@ public abstract class Player extends LivingEntity {
2024-06-13 20:09:28 +02:00
public int getXpNeededForNextLevel() {
return this.experienceLevel >= 30 ? 112 + (this.experienceLevel - 30) * 9 : (this.experienceLevel >= 15 ? 37 + (this.experienceLevel - 15) * 5 : 7 + this.experienceLevel * 2);
}
+ // Paper start - send while respecting visibility
+ private static void sendSoundEffect(Player fromEntity, double x, double y, double z, SoundEvent soundEffect, SoundSource soundCategory, float volume, float pitch) {
2024-06-23 22:03:32 +02:00
+ fromEntity.level().playSound(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity itself
+ if (fromEntity instanceof ServerPlayer serverPlayer) {
+ serverPlayer.connection.send(new net.minecraft.network.protocol.game.ClientboundSoundPacket(net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.wrapAsHolder(soundEffect), soundCategory, x, y, z, volume, pitch, fromEntity.random.nextLong()));
2024-06-13 20:09:28 +02:00
+ }
+ }
+ // Paper end - send while respecting visibility
// CraftBukkit start
public void causeFoodExhaustion(float exhaustion) {