Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@0bf8790 Fix client lag spikes due to client light recalc PaperMC/Paper@aabf676 Prevent unloading worlds with pending player logins PaperMC/Paper@eff22eb Ensure players are removed from pendingLogin PaperMC/Paper@046466f Re-arrange most chunk system patches to front (#8338) PaperMC/Paper@e8c2c3b Fix World#refreshChunk not working for chunks in no-tick range PaperMC/Paper@09904fd Re-add legacy getChunkAtAsynchronously to ChunkProviderServer PaperMC/Paper@36a5f15 Allow preventing BlockDestroyEvent from dropping items (#8349) PaperMC/Paper@e51401e Updated Upstream (Bukkit/CraftBukkit/Spigot) (#8347) PaperMC/Paper@51183af Fix console completer/highlighter having invalid source stack (#8346) PaperMC/Paper@ef0e5a6 Updated Upstream (Bukkit/CraftBukkit/Spigot) PaperMC/Paper@178f035 Restore no-crash behaviour when read-only config file(s) (#8318) PaperMC/Paper@267dd18 Stop large look changes from crashing the server (#8326) PaperMC/Paper@36f0c1b Rebuild patches PaperMC/Paper@751d092 Properly close section storage managed files (#8364) PaperMC/Paper@f5f84ff Add custom destroyerIdentity parameter to the sendBlockBreak function (#5840) PaperMC/Paper@05f6a5c Limit size of Authenticator Cache Thread Pool (#8360) PaperMC/Paper@ef670eb EndDragonFight killed statuses should be false for newly created worlds (#8354) PaperMC/Paper@b826065 fire EntityChangeBlockEvent in more places (#6371) PaperMC/Paper@34777cd Missing eating regain reason (#8244) PaperMC/Paper@dbda887 Missing some effect cause (#8307) PaperMC/Paper@63cb747 Added byte array serialization/deserialization for PersistentDataContainers (#7505) PaperMC/Paper@ea777c3 Add a consumer parameter to ProjectileSource#launchProjectile (#8374) PaperMC/Paper@470c638 Configurable chat thread limit (#7878) PaperMC/Paper@dbc2d60 Make WorldCreator#keepSpawnLoaded return the WorldCreator (Fixes #8321) (#8371) PaperMC/Paper@f8742e2 Also load resources from LibraryLoader (#8335) PaperMC/Paper@f7e6809 Fix Pathfinding After World Has Changed (#8068) PaperMC/Paper@ad3dffe Respect preventMovingIntoUnloadedChunks for optimized collision checking (#8259) PaperMC/Paper@8db45c4 Copper clear on lightning strike calls EntityChangeBlockEvent (#8126) PaperMC/Paper@9e614e6 Fix ground pathfinding (#7683) PaperMC/Paper@339e85d Updated Upstream (CraftBukkit) (#8376) PaperMC/Paper@980c1d1 Updated Upstream (Bukkit/CraftBukkit) (#8378) PaperMC/Paper@8681503 Call EntityChangeBlockEvent for frogs egg (#8136) PaperMC/Paper@ec0c550 Call BlockPhysicsEvent more often (#8264) PaperMC/Paper@f528f53 Correct javadocs on PlayerArmorStandManipulateEvent (#7719) PaperMC/Paper@3996e6e Updated Upstream (Bukkit/CraftBukkit/Spigot) PaperMC/Paper@d332623 Avoid potential place where the world map could be modified after its iterator is created (#8315) PaperMC/Paper@6736f39 Fix mangled patch PaperMC/Paper@4d52f1d Add method isTickingWorlds to Bukkit (#8316) PaperMC/Paper@62680d5 Avoid item meta usage for itemstack enchantment getter (#8373) PaperMC/Paper@b4c025b Fix player desync on dimension change (#8253) PaperMC/Paper@6d63005 Fix setEggCount method from TurtleLayEggEvent (#8385) PaperMC/Paper@abe53a7 Fix typos in isTickingWorlds API javadocs (#8382) PaperMC/Paper@01a1387 Rewrite chunk system (#8177) PaperMC/Paper@b58c0cf Update snekyaml
277 lines
16 KiB
Diff
277 lines
16 KiB
Diff
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
|
|
From: lexikiq <noellekiq@gmail.com>
|
|
Date: Sat, 19 Jun 2021 16:30:39 -0400
|
|
Subject: [PATCH] Add SoundEvent
|
|
|
|
|
|
diff --git a/src/main/java/gg/projecteden/parchment/event/sound/ParchmentSoundEvent.java b/src/main/java/gg/projecteden/parchment/event/sound/ParchmentSoundEvent.java
|
|
new file mode 100644
|
|
index 0000000000000000000000000000000000000000..44245b61f64e4e2eb21ac4f5e540aa9a583bfcfe
|
|
--- /dev/null
|
|
+++ b/src/main/java/gg/projecteden/parchment/event/sound/ParchmentSoundEvent.java
|
|
@@ -0,0 +1,28 @@
|
|
+package gg.projecteden.parchment.event.sound;
|
|
+
|
|
+import io.papermc.paper.adventure.PaperAdventure;
|
|
+import net.kyori.adventure.sound.Sound;
|
|
+import net.minecraft.sounds.SoundEvent;
|
|
+import net.minecraft.world.entity.Entity;
|
|
+import net.minecraft.world.level.Level;
|
|
+import org.bukkit.Location;
|
|
+
|
|
+import java.util.Optional;
|
|
+import java.util.function.Function;
|
|
+
|
|
+public class ParchmentSoundEvent {
|
|
+ public static final Function<Sound, Double> DISTANCE_FUNCTION = sound -> {
|
|
+ Optional<SoundEvent> soundEvent = PaperAdventure.asVanillaSound(sound.name());
|
|
+ if (soundEvent.isPresent())
|
|
+ return Double.valueOf(soundEvent.get().getRange(sound.volume()));
|
|
+ return gg.projecteden.parchment.event.sound.SoundEvent.DEFAULT_DISTANCE_FUNCTION.apply(sound);
|
|
+ };
|
|
+
|
|
+ public static gg.projecteden.parchment.event.sound.SoundEvent.Emitter createEmitter(Level level, double x, double y, double z) {
|
|
+ return new gg.projecteden.parchment.event.sound.SoundEvent.LocationEmitter(new Location(level.getWorld(), x, y, z));
|
|
+ }
|
|
+
|
|
+ public static gg.projecteden.parchment.event.sound.SoundEvent.Emitter createEmitter(Entity entity) {
|
|
+ return new gg.projecteden.parchment.event.sound.SoundEvent.EntityEmitter(entity.getBukkitEntity());
|
|
+ }
|
|
+}
|
|
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
index 6679038054796b9bdfeb6fb4b29e50aa63052101..0ba919d0e8ae347c6db4813d59adaec90eeed151 100644
|
|
--- a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
@@ -302,6 +302,32 @@ public final class PaperAdventure {
|
|
return asVanilla(source);
|
|
}
|
|
|
|
+ // Parchment start
|
|
+ public static Sound.Source asAdventure(final SoundSource source) {
|
|
+ return switch (source) {
|
|
+ case MASTER -> Sound.Source.MASTER;
|
|
+ case MUSIC -> Sound.Source.MUSIC;
|
|
+ case RECORDS -> Sound.Source.RECORD;
|
|
+ case WEATHER -> Sound.Source.WEATHER;
|
|
+ case BLOCKS -> Sound.Source.BLOCK;
|
|
+ case HOSTILE -> Sound.Source.HOSTILE;
|
|
+ case NEUTRAL -> Sound.Source.NEUTRAL;
|
|
+ case PLAYERS -> Sound.Source.PLAYER;
|
|
+ case AMBIENT -> Sound.Source.AMBIENT;
|
|
+ case VOICE -> Sound.Source.VOICE;
|
|
+ };
|
|
+ }
|
|
+
|
|
+ public static java.util.Optional<net.minecraft.sounds.SoundEvent> asVanillaSound(final Key key) {
|
|
+ return net.minecraft.core.Registry.SOUND_EVENT.getOptional(asVanilla(key));
|
|
+ }
|
|
+
|
|
+ @SuppressWarnings("PatternValidation")
|
|
+ public static Key asAdventure(final ResourceLocation key) {
|
|
+ return Key.key(key.getNamespace(), key.getPath());
|
|
+ }
|
|
+ // Parchment end
|
|
+
|
|
// NBT
|
|
|
|
public static @Nullable BinaryTagHolder asBinaryTagHolder(final @Nullable CompoundTag tag) {
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index b396e9b35f315db37ba070ad4baeec1f098d0cb8..532c32dbec9b3e33adaf49aec8a96a3705376ce4 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1572,12 +1572,40 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
|
|
@Override
|
|
public void playSeededSound(@Nullable Player except, double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch, long seed) {
|
|
- this.server.getPlayerList().broadcast(except, x, y, z, (double) sound.getRange(volume), this.dimension(), new ClientboundSoundPacket(sound, category, x, y, z, volume, pitch, seed));
|
|
+ // Parchment start - sound event
|
|
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
|
|
+ except == null ? null : except.getBukkitEntity(),
|
|
+ net.kyori.adventure.sound.Sound.sound(
|
|
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(sound.getLocation()),
|
|
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(category),
|
|
+ volume,
|
|
+ pitch
|
|
+ ),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(this, x, y, z),
|
|
+ seed,
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.DISTANCE_FUNCTION,
|
|
+ null
|
|
+ ));
|
|
+ // Parchment end
|
|
}
|
|
|
|
@Override
|
|
public void playSeededSound(@Nullable Player except, Entity entity, SoundEvent sound, SoundSource category, float volume, float pitch, long seed) {
|
|
- this.server.getPlayerList().broadcast(except, entity.getX(), entity.getY(), entity.getZ(), (double) sound.getRange(volume), this.dimension(), new ClientboundSoundEntityPacket(sound, category, entity, volume, pitch, seed));
|
|
+ // Parchment start - sound event
|
|
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
|
|
+ except == null ? null : except.getBukkitEntity(),
|
|
+ net.kyori.adventure.sound.Sound.sound(
|
|
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(sound.getLocation()),
|
|
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(category),
|
|
+ volume,
|
|
+ pitch
|
|
+ ),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(entity),
|
|
+ seed,
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.DISTANCE_FUNCTION,
|
|
+ null
|
|
+ ));
|
|
+ // Parchment end
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index af7acb628b84539b1ee5ef1934f75f091c4cd91e..9fae1cd71bfe8832a9294ac0f51e667776ba1744 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -2208,7 +2208,19 @@ public class ServerPlayer extends Player {
|
|
|
|
@Override
|
|
public void playNotifySound(SoundEvent event, SoundSource category, float volume, float pitch) {
|
|
- this.connection.send(new ClientboundSoundPacket(event, category, this.getX(), this.getY(), this.getZ(), volume, pitch, this.random.nextLong()));
|
|
+ // Parchment start - sound event
|
|
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
|
|
+ null,
|
|
+ net.kyori.adventure.sound.Sound.sound(
|
|
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(event.getLocation()),
|
|
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(category),
|
|
+ volume,
|
|
+ pitch
|
|
+ ),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(level, getX(), getY(), getZ()),
|
|
+ this.random.nextLong(), sound -> 0d, soundEvent -> java.util.Collections.singletonList(getBukkitEntity())
|
|
+ ));
|
|
+ // Parchment end
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 06eda955f96b5fe2d08ed0d39229c7a6ebb88931..6f7261afd306da4f523718a80881ab9d6e4b4b41 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -984,7 +984,7 @@ public abstract class PlayerList {
|
|
if (flag2 && !isLocAltered) {
|
|
BlockState data = worldserver1.getBlockState(blockposition);
|
|
worldserver1.setBlock(blockposition, data.setValue(net.minecraft.world.level.block.RespawnAnchorBlock.CHARGE, data.getValue(net.minecraft.world.level.block.RespawnAnchorBlock.CHARGE) - 1), 3);
|
|
- entityplayer1.connection.send(new ClientboundSoundPacket(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, (double) location.getX(), (double) location.getY(), (double) location.getZ(), 1.0F, 1.0F, worldserver1.getRandom().nextLong()));
|
|
+ entityplayer1.playNotifySound(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, 1.0F, 1.0F); // Parchment - use existing play sound method
|
|
// Paper end
|
|
}
|
|
// Added from changeDimension
|
|
diff --git a/src/main/java/net/minecraft/world/entity/player/Player.java b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
index 9b131f0a827413e9f5d6d0f7491c5481576cb8b1..7d982b7735c09d87d139c34d1cda5cbfb5327c5f 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -1908,7 +1908,21 @@ public abstract class Player extends LivingEntity {
|
|
private static void sendSoundEffect(Player fromEntity, double x, double y, double z, SoundEvent soundEffect, SoundSource soundCategory, float volume, float pitch) {
|
|
fromEntity.level.playSound(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity himself
|
|
if (fromEntity instanceof ServerPlayer) {
|
|
- ((ServerPlayer) fromEntity).connection.send(new net.minecraft.network.protocol.game.ClientboundSoundPacket(soundEffect, soundCategory, x, y, z, volume, pitch, fromEntity.random.nextLong()));
|
|
+ // Parchment start - sound event
|
|
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.SoundEvent(
|
|
+ null,
|
|
+ net.kyori.adventure.sound.Sound.sound(
|
|
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(soundEffect.getLocation()),
|
|
+ io.papermc.paper.adventure.PaperAdventure.asAdventure(soundCategory),
|
|
+ volume,
|
|
+ pitch
|
|
+ ),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(fromEntity.level, x, y, z),
|
|
+ fromEntity.random.nextLong(),
|
|
+ sound -> 0d,
|
|
+ soundEvent -> java.util.Collections.singletonList(((ServerPlayer) fromEntity).getBukkitEntity())
|
|
+ ));
|
|
+ // Parchment end
|
|
}
|
|
}
|
|
// Paper end
|
|
diff --git a/src/main/java/net/minecraft/world/entity/raid/Raid.java b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
index 6a0a1731fd6804eb69d3641213712d31bce085b2..81819d12e0becde85b6d66f3b3ffedde847a72f6 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
@@ -526,7 +526,7 @@ public class Raid {
|
|
float f = 13.0F;
|
|
boolean flag = true;
|
|
Collection<ServerPlayer> collection = this.raidEvent.getPlayers();
|
|
- long i = this.random.nextLong();
|
|
+ //long i = this.random.nextLong(); // Parchment - remove redundant variable
|
|
Iterator iterator = this.level.players().iterator();
|
|
|
|
while (iterator.hasNext()) {
|
|
@@ -538,7 +538,7 @@ public class Raid {
|
|
double d2 = vec3d.z + 13.0D / d0 * (vec3d1.z - vec3d.z);
|
|
|
|
if (d0 <= 64.0D || collection.contains(entityplayer)) {
|
|
- entityplayer.connection.send(new ClientboundSoundPacket(SoundEvents.RAID_HORN, SoundSource.NEUTRAL, d1, entityplayer.getY(), d2, 64.0F, 1.0F, i));
|
|
+ entityplayer.playNotifySound(SoundEvents.RAID_HORN, SoundSource.NEUTRAL, 64.0F, 1.0F); // Parchment - use existing play sound method
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index 03d389f3458cd77166a0319fa38c7207e8714e6f..419d85a7561d8d5cecb1a79d6900c3f37e5b5faa 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.event;
|
|
|
|
import com.google.common.base.Function;
|
|
import com.google.common.base.Functions;
|
|
-import com.google.common.collect.Lists;
|
|
import com.mojang.datafixers.util.Either;
|
|
import java.net.InetAddress;
|
|
import java.util.ArrayList;
|
|
@@ -1920,4 +1919,52 @@ public class CraftEventFactory {
|
|
return event.callEvent();
|
|
}
|
|
// Paper end
|
|
+
|
|
+ // Parchment start
|
|
+ private static net.minecraft.network.protocol.@org.jetbrains.annotations.NotNull Packet<net.minecraft.network.protocol.game.ClientGamePacketListener> handleSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event, CraftPlayer recipient) {
|
|
+ // init variables
|
|
+ net.kyori.adventure.sound.Sound sound = event.calculateSound(recipient);
|
|
+ gg.projecteden.parchment.event.sound.SoundEvent.Emitter emitter = event.calculateEmitter(recipient);
|
|
+ net.minecraft.sounds.SoundSource source = io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source());
|
|
+ float volume = sound.volume();
|
|
+ float pitch = sound.pitch();
|
|
+ long seed = event.getSeed();
|
|
+ java.util.Optional<net.minecraft.sounds.SoundEvent> soundEvent = io.papermc.paper.adventure.PaperAdventure.asVanillaSound(sound.name());
|
|
+ // handle vanilla sounds
|
|
+ if (soundEvent.isPresent()) {
|
|
+ if (emitter instanceof gg.projecteden.parchment.event.sound.SoundEvent.EntityEmitter entityEmitter)
|
|
+ return new net.minecraft.network.protocol.game.ClientboundSoundEntityPacket(soundEvent.get(), source, ((CraftEntity) entityEmitter.entity()).getHandle(), volume, pitch, seed);
|
|
+ else if (emitter instanceof gg.projecteden.parchment.event.sound.SoundEvent.LocationEmitter locationEmitter) {
|
|
+ Location loc = locationEmitter.location();
|
|
+ return new net.minecraft.network.protocol.game.ClientboundSoundPacket(soundEvent.get(), source, loc.getX(), loc.getY(), loc.getZ(), volume, pitch, seed);
|
|
+ }
|
|
+ else
|
|
+ throw new IllegalArgumentException("Unknown emitter type: " + emitter.getClass().getName());
|
|
+ }
|
|
+ // handle custom sounds
|
|
+ else {
|
|
+ // warn if trying to use EntityEmitter with custom sound
|
|
+ if (emitter instanceof gg.projecteden.parchment.event.sound.SoundEvent.EntityEmitter)
|
|
+ org.slf4j.LoggerFactory.getLogger("SoundEvent").warn("Sound event is using a custom sound ({}) which cannot be used with EntityEmitter. Falling back to playing at the entity's location.", sound.name().asString());
|
|
+ Vec3 pos = org.bukkit.craftbukkit.util.CraftVector.toNMS(emitter.location().toVector());
|
|
+ return new net.minecraft.network.protocol.game.ClientboundCustomSoundPacket(io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.name()), source, pos, volume, pitch, seed);
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event) {
|
|
+ org.apache.commons.lang3.Validate.notNull(event, "event");
|
|
+ net.minecraft.server.MCUtil.asyncExecutor.execute(() -> {
|
|
+ if (!event.callEvent())
|
|
+ return;
|
|
+ try {
|
|
+ for (Player _player : event.calculateRecipients()) {
|
|
+ CraftPlayer player = (CraftPlayer) _player;
|
|
+ player.getHandle().connection.send(handleSoundEvent(event, player));
|
|
+ }
|
|
+ } catch (Throwable e) {
|
|
+ org.slf4j.LoggerFactory.getLogger("SoundEvent").error("Error playing sound event", e);
|
|
+ }
|
|
+ });
|
|
+ }
|
|
+ // Parchment end
|
|
}
|