2019-02-03 15:34:04 +00:00
From 9da6eabeb84a6797d1dc255cb701801bcfa538c6 Mon Sep 17 00:00:00 2001
2017-10-31 02:29:53 +00: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
2019-02-03 15:34:04 +00:00
index 8378c0789..54d03feb9 100644
2017-10-31 02:29:53 +00:00
--- a/src/main/java/net/minecraft/server/EntityHuman.java
+++ b/src/main/java/net/minecraft/server/EntityHuman.java
2019-01-01 03:15:55 +00:00
@@ -989,6 +989,15 @@ public abstract class EntityHuman extends EntityLiving {
2018-07-18 00:08:13 +00:00
this.k = 0;
2017-10-31 02:29:53 +00: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) {
2018-07-18 00:08:13 +00:00
if (entity.bk()) {
2017-10-31 02:29:53 +00:00
if (!entity.t(this)) {
2019-01-01 03:15:55 +00:00
@@ -1013,7 +1022,7 @@ public abstract class EntityHuman extends EntityLiving {
2017-10-31 02:29:53 +00:00
int i = b0 + EnchantmentManager.b((EntityLiving) this);
if (this.isSprinting() && flag) {
2018-07-18 00:08:13 +00:00
- this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.bV(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_KNOCKBACK, this.bV(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 02:29:53 +00:00
++i;
flag1 = true;
}
2019-01-01 03:15:55 +00:00
@@ -1091,7 +1100,7 @@ public abstract class EntityHuman extends EntityLiving {
2017-10-31 02:29:53 +00:00
}
}
2018-07-18 00:08:13 +00:00
- this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_SWEEP, this.bV(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_SWEEP, this.bV(), 1.0F, 1.0F); // Paper - send while respecting visibility
2018-07-22 05:27:46 +00:00
this.dl();
2017-10-31 02:29:53 +00:00
}
2019-01-01 03:15:55 +00:00
@@ -1121,15 +1130,15 @@ public abstract class EntityHuman extends EntityLiving {
2017-10-31 02:29:53 +00:00
}
if (flag2) {
2018-07-18 00:08:13 +00:00
- this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_CRIT, this.bV(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_CRIT, this.bV(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 02:29:53 +00:00
this.a(entity);
}
if (!flag2 && !flag3) {
if (flag) {
2018-07-18 00:08:13 +00:00
- this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_STRONG, this.bV(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_STRONG, this.bV(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 02:29:53 +00:00
} else {
2018-07-18 00:08:13 +00:00
- this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_WEAK, this.bV(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_WEAK, this.bV(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 02:29:53 +00:00
}
}
2019-01-01 03:15:55 +00:00
@@ -1185,7 +1194,7 @@ public abstract class EntityHuman extends EntityLiving {
2017-10-31 02:29:53 +00:00
this.applyExhaustion(world.spigotConfig.combatExhaustion); // Spigot - Change to use configurable value
} else {
2018-07-18 00:08:13 +00:00
- this.world.a((EntityHuman) null, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_NODAMAGE, this.bV(), 1.0F, 1.0F);
+ sendSoundEffect(this, this.locX, this.locY, this.locZ, SoundEffects.ENTITY_PLAYER_ATTACK_NODAMAGE, this.bV(), 1.0F, 1.0F); // Paper - send while respecting visibility
2017-10-31 02:29:53 +00: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
2019-02-03 15:34:04 +00:00
index 30f4ea451..c98c11541 100644
2017-10-31 02:29:53 +00:00
--- a/src/main/java/net/minecraft/server/World.java
+++ b/src/main/java/net/minecraft/server/World.java
2019-02-03 15:34:04 +00:00
@@ -954,6 +954,12 @@ public abstract class World implements IEntityAccess, GeneratorAccess, IIBlockAc
2017-10-31 02:29:53 +00:00
this.a(entityhuman, (double) blockposition.getX() + 0.5D, (double) blockposition.getY() + 0.5D, (double) blockposition.getZ() + 0.5D, soundeffect, soundcategory, f, f1);
}
+ // Paper start - OBFHELPER
+ public final void sendSoundEffect(@Nullable EntityHuman fromEntity, double x, double y, double z, SoundEffect soundeffect, SoundCategory soundcategory, float volume, float pitch) {
+ this.a(fromEntity, x, y, z, soundeffect, soundcategory, volume, pitch);
+ }
+ // Paper end
+
public void a(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) {
2018-07-18 00:08:13 +00:00
for (int i = 0; i < this.v.size(); ++i) {
((IWorldAccess) this.v.get(i)).a(entityhuman, soundeffect, soundcategory, d0, d1, d2, f, f1);
2017-10-31 02:29:53 +00:00
--
2019-01-01 03:15:55 +00:00
2.20.1
2017-10-31 02:29:53 +00:00