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

@@ -445,10 +445,9 @@
@VisibleForTesting @VisibleForTesting
public void resetWeatherCycle() { public void resetWeatherCycle() {
- this.serverLevelData.setRainTime(0); - this.serverLevelData.setRainTime(0);
- this.serverLevelData.setRaining(false);
- this.serverLevelData.setThunderTime(0);
+ // CraftBukkit start + // CraftBukkit start
+ this.serverLevelData.setRaining(false); this.serverLevelData.setRaining(false);
- this.serverLevelData.setThunderTime(0);
+ // If we stop due to everyone sleeping we should reset the weather duration to some other random value. + // If we stop due to everyone sleeping we should reset the weather duration to some other random value.
+ // Not that everyone ever manages to get the whole server to sleep at the same time.... + // Not that everyone ever manages to get the whole server to sleep at the same time....
+ if (!this.serverLevelData.isRaining()) { + if (!this.serverLevelData.isRaining()) {
@@ -674,6 +673,15 @@
if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) { if (d0 * d0 + d1 * d1 + d2 * d2 < 1024.0D) {
entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress)); entityplayer.connection.send(new ClientboundBlockDestructionPacket(entityId, pos, progress));
} }
@@ -1030,7 +1311,7 @@
@Override
public void levelEvent(@Nullable Player player, int eventId, BlockPos pos, int data) {
- this.server.getPlayerList().broadcast(player, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 64.0D, this.dimension(), new ClientboundLevelEventPacket(eventId, pos, data, false));
+ this.server.getPlayerList().broadcast(player, (double) pos.getX(), (double) pos.getY(), (double) pos.getZ(), 64.0D, this.dimension(), new ClientboundLevelEventPacket(eventId, pos, data, false)); // Paper - diff on change (the 64.0 distance is used as defaults for sound ranges in spigot config for ender dragon, end portal and wither)
}
public int getLogicalHeight() {
@@ -1060,7 +1341,18 @@ @@ -1060,7 +1341,18 @@
Iterator iterator = this.navigatingMobs.iterator(); Iterator iterator = this.navigatingMobs.iterator();
@@ -882,7 +890,25 @@
return this.entityManager.getEntityGetter(); return this.entityManager.getEntityGetter();
} }
@@ -1836,6 +2171,7 @@ @@ -1802,6 +2137,17 @@
return this.serverLevelData.getGameRules();
}
+ // Paper start - respect global sound events gamerule
+ public List<net.minecraft.server.level.ServerPlayer> getPlayersForGlobalSoundGamerule() {
+ return this.getGameRules().getBoolean(GameRules.RULE_GLOBAL_SOUND_EVENTS) ? ((ServerLevel) this).getServer().getPlayerList().players : ((ServerLevel) this).players();
+ }
+
+ public double getGlobalSoundRangeSquared(java.util.function.Function<org.spigotmc.SpigotWorldConfig, Integer> rangeFunction) {
+ final double range = rangeFunction.apply(this.spigotConfig);
+ return range <= 0 ? 64.0 * 64.0 : range * range; // 64 is taken from default in ServerLevel#levelEvent
+ }
+ // Paper end - respect global sound events gamerule
+
@Override
public CrashReportCategory fillReportDetails(CrashReport report) {
CrashReportCategory crashreportsystemdetails = super.fillReportDetails(report);
@@ -1836,6 +2182,7 @@
} }
public void onTrackingStart(Entity entity) { public void onTrackingStart(Entity entity) {
@@ -890,7 +916,7 @@
ServerLevel.this.getChunkSource().addEntity(entity); ServerLevel.this.getChunkSource().addEntity(entity);
if (entity instanceof ServerPlayer entityplayer) { if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.add(entityplayer); ServerLevel.this.players.add(entityplayer);
@@ -1864,9 +2200,52 @@ @@ -1864,9 +2211,52 @@
} }
entity.updateDynamicGameEventListener(DynamicGameEventListener::add); entity.updateDynamicGameEventListener(DynamicGameEventListener::add);
@@ -943,7 +969,7 @@
ServerLevel.this.getChunkSource().removeEntity(entity); ServerLevel.this.getChunkSource().removeEntity(entity);
if (entity instanceof ServerPlayer entityplayer) { if (entity instanceof ServerPlayer entityplayer) {
ServerLevel.this.players.remove(entityplayer); ServerLevel.this.players.remove(entityplayer);
@@ -1895,6 +2274,15 @@ @@ -1895,6 +2285,15 @@
} }
entity.updateDynamicGameEventListener(DynamicGameEventListener::remove); entity.updateDynamicGameEventListener(DynamicGameEventListener::remove);

View File

@@ -91,7 +91,7 @@
for (int k1 = i; k1 <= l; ++k1) { for (int k1 = i; k1 <= l; ++k1) {
for (int l1 = j; l1 <= i1; ++l1) { for (int l1 = j; l1 <= i1; ++l1) {
@@ -467,7 +494,11 @@ @@ -467,14 +494,61 @@
if (!iblockdata.isAir() && !iblockdata.is(BlockTags.DRAGON_TRANSPARENT)) { if (!iblockdata.isAir() && !iblockdata.is(BlockTags.DRAGON_TRANSPARENT)) {
if (world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(BlockTags.DRAGON_IMMUNE)) { if (world.getGameRules().getBoolean(GameRules.RULE_MOBGRIEFING) && !iblockdata.is(BlockTags.DRAGON_IMMUNE)) {
@@ -104,10 +104,11 @@
} else { } else {
flag = true; flag = true;
} }
@@ -476,6 +507,49 @@
} }
} + }
+ }
+ }
+
+ // CraftBukkit start - Set off an EntityExplodeEvent for the dragon exploding all these blocks + // CraftBukkit start - Set off an EntityExplodeEvent for the dragon exploding all these blocks
+ // SPIGOT-4882: don't fire event if nothing hit + // SPIGOT-4882: don't fire event if nothing hit
+ if (!flag1) { + if (!flag1) {
@@ -143,17 +144,16 @@
+ Block.popResource(this.level(), blockposition, itemstack); + Block.popResource(this.level(), blockposition, itemstack);
+ }); + });
+ craftBlock.getNMS().spawnAfterBreak((ServerLevel) this.level(), blockposition, ItemStack.EMPTY, false); + craftBlock.getNMS().spawnAfterBreak((ServerLevel) this.level(), blockposition, ItemStack.EMPTY, false);
+ } }
+ nmsBlock.wasExploded((ServerLevel) this.level(), blockposition, this.explosionSource); + nmsBlock.wasExploded((ServerLevel) this.level(), blockposition, this.explosionSource);
+ +
+ this.level().removeBlock(blockposition, false); + this.level().removeBlock(blockposition, false);
+ } }
+ } }
+ // CraftBukkit end + // CraftBukkit end
+
if (flag1) { 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)); 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 @@ @@ -531,7 +605,7 @@
@Override @Override
@@ -186,7 +186,7 @@
protected void tickDeath() { protected void tickDeath() {
if (this.dragonFight != null) { if (this.dragonFight != null) {
this.dragonFight.updateDragon(this); 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); 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 + // CraftBukkit start - Use relative location for far away sounds
+ // worldserver.globalLevelEvent(1028, this.blockPosition(), 0); + // worldserver.globalLevelEvent(1028, this.blockPosition(), 0);
+ int viewDistance = worldserver.getCraftServer().getViewDistance() * 16; + 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 deltaX = this.getX() - player.getX();
+ double deltaZ = this.getZ() - player.getZ(); + double deltaZ = this.getZ() - player.getZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ; + 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) { + if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared); + double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance; + double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
@@ -232,7 +233,7 @@
} }
} }
@@ -592,7 +703,7 @@ @@ -592,7 +704,7 @@
if (world1 instanceof ServerLevel) { if (world1 instanceof ServerLevel) {
ServerLevel worldserver1 = (ServerLevel) world1; ServerLevel worldserver1 = (ServerLevel) world1;
@@ -241,7 +242,7 @@
ExperienceOrb.award(worldserver1, this.position(), Mth.floor((float) short0 * 0.2F)); ExperienceOrb.award(worldserver1, this.position(), Mth.floor((float) short0 * 0.2F));
} }
@@ -600,7 +711,7 @@ @@ -600,7 +712,7 @@
this.dragonFight.setDragonKilled(this); this.dragonFight.setDragonKilled(this);
} }
@@ -250,7 +251,7 @@
this.gameEvent(GameEvent.ENTITY_DIE); this.gameEvent(GameEvent.ENTITY_DIE);
} }
} }
@@ -814,6 +925,7 @@ @@ -814,6 +926,7 @@
super.addAdditionalSaveData(nbt); super.addAdditionalSaveData(nbt);
nbt.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId()); nbt.putInt("DragonPhase", this.phaseManager.getCurrentPhase().getPhase().getId());
nbt.putInt("DragonDeathTime", this.dragonDeathTime); nbt.putInt("DragonDeathTime", this.dragonDeathTime);
@@ -258,7 +259,7 @@
} }
@Override @Override
@@ -827,6 +939,11 @@ @@ -827,6 +940,11 @@
this.dragonDeathTime = nbt.getInt("DragonDeathTime"); this.dragonDeathTime = nbt.getInt("DragonDeathTime");
} }

View File

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

View File

@@ -1,6 +1,6 @@
--- a/net/minecraft/world/item/EnderEyeItem.java --- a/net/minecraft/world/item/EnderEyeItem.java
+++ b/net/minecraft/world/item/EnderEyeItem.java +++ b/net/minecraft/world/item/EnderEyeItem.java
@@ -62,7 +62,25 @@ @@ -62,7 +62,27 @@
} }
} }
@@ -9,11 +9,13 @@
+ // world.globalLevelEvent(1038, blockposition1.offset(1, 0, 1), 0); + // world.globalLevelEvent(1038, blockposition1.offset(1, 0, 1), 0);
+ int viewDistance = world.getCraftServer().getViewDistance() * 16; + int viewDistance = world.getCraftServer().getViewDistance() * 16;
+ BlockPos soundPos = blockposition1.offset(1, 0, 1); + BlockPos soundPos = blockposition1.offset(1, 0, 1);
+ for (ServerPlayer player : world.getServer().getPlayerList().players) { + final net.minecraft.server.level.ServerLevel serverLevel = (net.minecraft.server.level.ServerLevel) world; // Paper - respect global sound events gamerule - ensured by isClientSide check above
+ for (ServerPlayer player : serverLevel.getPlayersForGlobalSoundGamerule()) { // Paper - respect global sound events gamerule
+ double deltaX = soundPos.getX() - player.getX(); + double deltaX = soundPos.getX() - player.getX();
+ double deltaZ = soundPos.getZ() - player.getZ(); + double deltaZ = soundPos.getZ() - player.getZ();
+ double distanceSquared = deltaX * deltaX + deltaZ * deltaZ; + double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
+ if (world.spigotConfig.endPortalSoundRadius > 0 && distanceSquared > world.spigotConfig.endPortalSoundRadius * world.spigotConfig.endPortalSoundRadius) continue; // Spigot + final double soundRadiusSquared = serverLevel.getGlobalSoundRangeSquared(config -> config.endPortalSoundRadius); // Paper - respect global sound events gamerule
+ if (!serverLevel.getGameRules().getBoolean(net.minecraft.world.level.GameRules.RULE_GLOBAL_SOUND_EVENTS) && distanceSquared > soundRadiusSquared) continue; // Spigot // Paper - respect global sound events gamerule
+ if (distanceSquared > viewDistance * viewDistance) { + if (distanceSquared > viewDistance * viewDistance) {
+ double deltaLength = Math.sqrt(distanceSquared); + double deltaLength = Math.sqrt(distanceSquared);
+ double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance; + double relativeX = player.getX() + (deltaX / deltaLength) * viewDistance;
@@ -27,7 +29,7 @@
} }
return InteractionResult.SUCCESS; return InteractionResult.SUCCESS;
@@ -99,7 +117,11 @@ @@ -99,7 +119,11 @@
entityendersignal.setItem(itemstack); entityendersignal.setItem(itemstack);
entityendersignal.signalTo(blockposition); entityendersignal.signalTo(blockposition);
world.gameEvent((Holder) GameEvent.PROJECTILE_SHOOT, entityendersignal.position(), GameEvent.Context.of((Entity) user)); world.gameEvent((Holder) GameEvent.PROJECTILE_SHOOT, entityendersignal.position(), GameEvent.Context.of((Entity) user));