2021-06-11 14:02: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-01-23 15:43:48 +01:00
index 08dd71295154395d6de41a97f214157658f0c24b..5680bc0c9c71f915f66eecae401e8f51dc4225fe 100644
2021-06-11 14:02: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-01-23 15:43:48 +01:00
@@ -1227,7 +1227,7 @@ public abstract class Player extends LivingEntity {
2021-11-23 15:03:50 +01:00
int i = b0 + EnchantmentHelper.getKnockbackBonus(this);
2021-06-11 14:02:28 +02:00
if (this.isSprinting() && flag) {
2023-06-07 21:37:42 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F);
2021-06-11 14:02:28 +02:00
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_KNOCKBACK, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
++i;
flag1 = true;
}
2024-01-23 15:43:48 +01:00
@@ -1302,7 +1302,7 @@ public abstract class Player extends LivingEntity {
2021-06-11 14:02:28 +02:00
}
}
2023-06-07 21:37:42 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_SWEEP, this.getSoundSource(), 1.0F, 1.0F);
2021-06-11 14:02:28 +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-01-23 15:43:48 +01:00
@@ -1330,15 +1330,15 @@ public abstract class Player extends LivingEntity {
2021-06-11 14:02:28 +02:00
}
if (flag2) {
2023-06-07 21:37:42 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_CRIT, this.getSoundSource(), 1.0F, 1.0F);
2021-06-11 14:02:28 +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);
}
if (!flag2 && !flag3) {
if (flag) {
2023-06-07 21:37:42 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_STRONG, this.getSoundSource(), 1.0F, 1.0F);
2021-06-11 14:02:28 +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 {
2023-06-07 21:37:42 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_WEAK, this.getSoundSource(), 1.0F, 1.0F);
2021-06-11 14:02:28 +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-01-23 15:43:48 +01:00
@@ -1390,7 +1390,7 @@ public abstract class Player extends LivingEntity {
2021-06-11 14:02:28 +02:00
2023-06-07 21:37:42 +02:00
this.causeFoodExhaustion(this.level().spigotConfig.combatExhaustion, EntityExhaustionEvent.ExhaustionReason.ATTACK); // CraftBukkit - EntityExhaustionEvent // Spigot - Change to use configurable value
2021-06-11 14:02:28 +02:00
} else {
2023-06-07 21:37:42 +02:00
- this.level().playSound((Player) null, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F);
2021-06-11 14:02:28 +02:00
+ sendSoundEffect(this, this.getX(), this.getY(), this.getZ(), SoundEvents.PLAYER_ATTACK_NODAMAGE, this.getSoundSource(), 1.0F, 1.0F); // Paper - send while respecting visibility
if (flag4) {
target.clearFire();
}
2024-01-23 15:43:48 +01:00
@@ -1784,6 +1784,14 @@ public abstract class Player extends LivingEntity {
2021-06-11 14:02: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);
}
2024-01-22 18:04:55 +01:00
+ // Paper start - send while respecting visibility
2021-06-11 14:02:28 +02:00
+ private static void sendSoundEffect(Player fromEntity, double x, double y, double z, SoundEvent soundEffect, SoundSource soundCategory, float volume, float pitch) {
2023-06-07 22:19:14 +02:00
+ fromEntity.level().playSound(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity himself
2021-06-11 14:02:28 +02:00
+ if (fromEntity instanceof ServerPlayer) {
2022-12-08 04:24:00 +01:00
+ ((ServerPlayer) fromEntity).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()));
2021-06-11 14:02:28 +02:00
+ }
+ }
2024-01-22 18:04:55 +01:00
+ // Paper end - send while respecting visibility
2021-06-11 14:02:28 +02:00
// CraftBukkit start
public void causeFoodExhaustion(float exhaustion) {