Fix global sound handling

* Only send global sounds to same world if limiting radius
* respect global sound events gamerule

Co-authored-by: Evan McCarthy <evanmccarthy@outlook.com>
Co-authored-by: lexikiq <noellekiq@gmail.com>
Co-authored-by: Aikar <aikar@aikar.co>
This commit is contained in:
Jake Potrebic
2016-05-31 22:53:50 -04:00
parent 2a69b8dd1a
commit 08698c4642
4 changed files with 64 additions and 34 deletions

View File

@@ -91,7 +91,7 @@
for (int k1 = i; k1 <= l; ++k1) {
for (int l1 = j; l1 <= i1; ++l1) {
@@ -467,7 +494,11 @@
@@ -467,14 +494,61 @@
if (!iblockdata.isAir() && !iblockdata.is(BlockTags.DRAGON_TRANSPARENT)) {
if (world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(BlockTags.DRAGON_IMMUNE)) {
@@ -104,10 +104,11 @@
} else {
flag = true;
}
@@ -476,6 +507,49 @@
}
}
}
+ }
+ }
+ }
+
+ // CraftBukkit start - Set off an EntityExplodeEvent for the dragon exploding all these blocks
+ // SPIGOT-4882: don't fire event if nothing hit
+ if (!flag1) {
@@ -143,17 +144,16 @@
+ Block.popResource(this.level(), blockposition, itemstack);
+ });
+ craftBlock.getNMS().spawnAfterBreak((ServerLevel) this.level(), blockposition, ItemStack.EMPTY, false);
+ }
}
+ nmsBlock.wasExploded((ServerLevel) this.level(), blockposition, this.explosionSource);
+
+ this.level().removeBlock(blockposition, false);
+ }
+ }
}
}
+ // CraftBukkit end
+
if (flag1) {
BlockPos blockposition1 = new BlockPos(i + this.random.nextInt(l - i + 1), j + this.random.nextInt(i1 - j + 1), k + this.random.nextInt(j1 - k + 1));
@@ -531,7 +605,7 @@
@Override
@@ -186,7 +186,7 @@
protected void tickDeath() {
if (this.dragonFight != null) {
this.dragonFight.updateDragon(this);
@@ -555,21 +644,43 @@
@@ -555,21 +644,44 @@
this.level().addParticle(ParticleTypes.EXPLOSION_EMITTER, this.getX() + (double) f, this.getY() + 2.0D + (double) f1, this.getZ() + (double) f2, 0.0D, 0.0D, 0.0D);
}
@@ -214,11 +214,12 @@
+ // CraftBukkit start - Use relative location for far away sounds
+ // worldserver.globalLevelEvent(1028, this.blockPosition(), 0);
+ int viewDistance = worldserver.getCraftServer().getViewDistance() * 16;
+ for (net.minecraft.server.level.ServerPlayer player : worldserver.getServer().getPlayerList().players) {
+ for (net.minecraft.server.level.ServerPlayer player : worldserver.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ double deltaX = this.getX() - player.getX();
+ double deltaZ = this.getZ() - player.getZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+ if ( worldserver.spigotConfig.dragonDeathSoundRadius > 0 && distanceSquared > worldserver.spigotConfig.dragonDeathSoundRadius * worldserver.spigotConfig.dragonDeathSoundRadius ) continue; // Spigot
+ final double soundRadiusSquared = worldserver.getGlobalSoundRangeSquared(config -> config.dragonDeathSoundRadius); // Paper - respect global sound events gamerule
+ if ( !worldserver.getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared ) continue; // Spigot // Paper - respect global sound events gamerule
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
@@ -232,7 +233,7 @@
}
}
@@ -592,7 +703,7 @@
@@ -592,7 +704,7 @@
if (world1 instanceof ServerLevel) {
ServerLevel worldserver1 = (ServerLevel) world1;
@@ -241,7 +242,7 @@
ExperienceOrb.award(worldserver1, this.position(), Mth.floor((float) short0 * 0.2F));
}
@@ -600,7 +711,7 @@
@@ -600,7 +712,7 @@
this.dragonFight.setDragonKilled(this);
}
@@ -250,7 +251,7 @@
this.gameEvent(GameEvent.ENTITY_DIE);
}
}
@@ -814,6 +925,7 @@
@@ -814,6 +926,7 @@
super.addAdditionalSaveData(nbt);
nbt.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId());
nbt.putInt("DragonDeathTime", this.dragonDeathTime);
@@ -258,7 +259,7 @@
}
@Override
@@ -827,6 +939,11 @@
@@ -827,6 +940,11 @@
this.dragonDeathTime = nbt.getInt("DragonDeathTime");
}

View File

@@ -38,7 +38,7 @@
public class WitherBoss extends Monster implements RangedAttackMob {
@@ -252,15 +261,41 @@
@@ -252,15 +261,42 @@
i = this.getInvulnerableTicks() - 1;
this.bossEvent.setProgress(1.0F - (float) i / 220.0F);
if (i <= 0) {
@@ -58,11 +58,12 @@
+ // CraftBukkit start - Use relative location for far away sounds
+ // worldserver.globalLevelEvent(1023, new BlockPosition(this), 0);
+ int viewDistance = world.getCraftServer().getViewDistance() * 16;
+ for (ServerPlayer player : (List<ServerPlayer>) MinecraftServer.getServer().getPlayerList().players) {
+ for (ServerPlayer player : world.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ double deltaX = this.getX() - player.getX();
+ double deltaZ = this.getZ() - player.getZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+ if ( world.spigotConfig.witherSpawnSoundRadius > 0 && distanceSquared > world.spigotConfig.witherSpawnSoundRadius * world.spigotConfig.witherSpawnSoundRadius ) continue; // Spigot
+ final double soundRadiusSquared = world.getGlobalSoundRangeSquared(config -> config.witherSpawnSoundRadius); // Paper - respect global sound events gamerule
+ if ( !world.getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared ) continue; // Spigot // Paper - respect global sound events gamerule
+ if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
@@ -83,7 +84,7 @@
}
} else {
@@ -305,6 +340,7 @@
@@ -305,6 +341,7 @@
if (!list.isEmpty()) {
LivingEntity entityliving1 = (LivingEntity) list.get(this.random.nextInt(list.size()));
@@ -91,7 +92,7 @@
this.setAlternativeTarget(i, entityliving1.getId());
}
}
@@ -331,6 +367,11 @@
@@ -331,6 +368,11 @@
BlockState iblockdata = world.getBlockState(blockposition);
if (WitherBoss.canDestroy(iblockdata)) {
@@ -103,7 +104,7 @@
flag = world.destroyBlock(blockposition, true, this) || flag;
}
}
@@ -342,7 +383,7 @@
@@ -342,7 +384,7 @@
}
if (this.tickCount % 20 == 0) {
@@ -112,7 +113,7 @@
}
this.bossEvent.setProgress(this.getHealth() / this.getMaxHealth());
@@ -499,7 +540,7 @@
@@ -499,7 +541,7 @@
@Override
public void checkDespawn() {
if (this.level().getDifficulty() == Difficulty.PEACEFUL && this.shouldDespawnInPeaceful()) {