2020-05-06 11:48:49 +02:00
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
2017-10-31 03:29:53 +01:00
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/server/EntityHuman.java b/src/main/java/net/minecraft/server/EntityHuman.java
2020-06-25 15:11:48 +02:00
index 69c0a4c7bfb1c753d544dcd074ad832d3e5ef3a0..eaed020982bd19dab72872849170fa62d75699eb 100644
2017-10-31 03:29:53 +01:00
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
2020-06-25 15:11:48 +02:00
@@ -1002,6 +1002,15 @@ public abstract class EntityHuman extends EntityLiving {
2019-12-12 00:43:22 +01:00
return vec3d;
2017-10-31 03:29:53 +01:00
}
+ // Paper start - send SoundEffect to everyone who can see fromEntity
+ private static void sendSoundEffect(EntityHuman fromEntity, double x, double y, double z, SoundEffect soundEffect, SoundCategory soundCategory, float volume, float pitch) {
+ fromEntity.world.sendSoundEffect(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity himself
+ if (fromEntity instanceof EntityPlayer) {
+ ((EntityPlayer) fromEntity).playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(soundEffect, soundCategory, x, y, z, volume, pitch));
+ }
+ }
+ // Paper end
+
public void attack(Entity entity) {
2020-06-25 15:11:48 +02:00
if (entity.bH()) {
2017-10-31 03:29:53 +01:00
if (!entity.t(this)) {
2020-06-25 15:11:48 +02:00
@@ -1026,7 +1035,7 @@ public abstract class EntityHuman extends EntityLiving {
2017-10-31 03:29:53 +01:00
int i = b0 + EnchantmentManager.b((EntityLiving) this);
if (this.isSprinting() && flag) {
2019-12-12 00:43:22 +01:00
- this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.getSoundCategory(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 03:29:53 +01:00
++i;
flag1 = true;
}
2020-06-25 15:11:48 +02:00
@@ -1101,7 +1110,7 @@ public abstract class EntityHuman extends EntityLiving {
2017-10-31 03:29:53 +01:00
}
}
2019-12-12 00:43:22 +01:00
- this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_SWEEP, this.getSoundCategory(), 1.0F, 1.0F); // Paper - send while respecting visibility
2020-06-25 15:11:48 +02:00
this.ew();
2017-10-31 03:29:53 +01:00
}
2020-06-25 15:11:48 +02:00
@@ -1129,15 +1138,15 @@ public abstract class EntityHuman extends EntityLiving {
2017-10-31 03:29:53 +01:00
}
if (flag2) {
2019-12-12 00:43:22 +01:00
- this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_CRIT, this.getSoundCategory(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 03:29:53 +01:00
this.a(entity);
}
if (!flag2 && !flag3) {
if (flag) {
2019-12-12 00:43:22 +01:00
- this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_STRONG, this.getSoundCategory(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 03:29:53 +01:00
} else {
2019-12-12 00:43:22 +01:00
- this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_WEAK, this.getSoundCategory(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 03:29:53 +01:00
}
}
2020-06-25 15:11:48 +02:00
@@ -1189,7 +1198,7 @@ public abstract class EntityHuman extends EntityLiving {
2017-10-31 03:29:53 +01:00
this.applyExhaustion(world.spigotConfig.combatExhaustion); // Spigot - Change to use configurable value
} else {
2019-12-12 00:43:22 +01:00
- this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_PLAYER_ATTACK_NODAMAGE, this.getSoundCategory(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 03:29:53 +01:00
if (flag4) {
entity.extinguish();
}
diff --git a/src/main/java/net/minecraft/server/World.java b/src/main/java/net/minecraft/server/World.java
2020-06-26 18:20:03 +02:00
index 15b1d9a82f8ced4d53a7848fa3cfdb835fbc3e5b..8b6667eb3b1976b4c7ed22060e55ad5c5b8179ce 100644
2017-10-31 03:29:53 +01:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2020-06-26 18:20:03 +02:00
@@ -646,6 +646,11 @@ public abstract class World implements GeneratorAccess, AutoCloseable {
2019-07-20 06:01:24 +02:00
this.playSound(entityhuman, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, soundeffect, soundcategory, f, f1);
2017-10-31 03:29:53 +01:00
}
+ // Paper start - OBFHELPER
+ public final void sendSoundEffect(@Nullable EntityHuman fromEntity, double x, double y, double z, SoundEffect soundeffect, SoundCategory soundcategory, float volume, float pitch) {
2019-07-20 06:01:24 +02:00
+ this.playSound(fromEntity, x, y, z, soundeffect, soundcategory, volume, pitch);
2017-10-31 03:29:53 +01:00
+ }
2019-07-20 06:01:24 +02:00
+ // Paper end
public abstract void playSound(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1);
2019-04-28 01:23:53 +02:00
2019-07-20 06:01:24 +02:00
public abstract void playSound(@Nullable EntityHuman entityhuman, Entity entity, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1);