Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@40adc23 Fix incorrect javadoc in JarLibrary (#9513) PaperMC/Paper@c016e03 Fix unbreakable flint and steel consumed when igniting creepers (#9509) PaperMC/Paper@b1334b5 Mark Player.sendSignChange as deprecated (#9382) PaperMC/Paper@2f8d9db Pathfinder hasPath should check if path is done. (#9231) PaperMC/Paper@46a36d3 Make ExperienceOrb entities call EntitySpawnEvent (#9197) PaperMC/Paper@24d690f Fix hopper not marking source inv as changed (#9070) PaperMC/Paper@383f0ed Remove sign ticking (#9478) PaperMC/Paper@d8b8f61 Configurable Region Compression Format (#8505) PaperMC/Paper@2c54b39 Don't support hex in book title and author (#9493) PaperMC/Paper@e19177a Rewrote Amethyst logic to throw both BlockGrowEvent and BlockSpreadEvent (#9217) PaperMC/Paper@4283054 Add player whitelist events (#9209) PaperMC/Paper@aa93dcf feat: add minimessage tag resolvers overload to CommandSender#sendMessage (#9505) PaperMC/Paper@b14979e Remove isRemoved skip on .discard() (#9520) PaperMC/Paper@1837f6c Prevent entity removals if the entity slices is receiving status updates PaperMC/Paper@a40e48f Add cause to PlayerOpenSignEvent (#9441) PaperMC/Paper@7d1cc6d Add Translatable interface to MusicInstrument (#9538) PaperMC/Paper@6c7e3c5 Clarify viewers set mutability in chat events (#9525) PaperMC/Paper@f402f89 Bump net.kyori.ansi to 1.0.2 (#9546) PaperMC/Paper@81619a6 Fix treasure map config default (#9572) PaperMC/Paper@13c9d3c Bump net.kyori:ansi to 1.0.3 (#9575) PaperMC/Paper@2c55dd8 Expand use of strict advancement dim check (#9545) PaperMC/Paper@69a8013 Fix inventorycloseevent javadocs (#9533) PaperMC/Paper@2fa8efc Updated Upstream (Bukkit/CraftBukkit) (#9485) PaperMC/Paper@508a295 Only erase allay memory on non-item targets (#9570) PaperMC/Paper@31358d5 API for updating recipes on clients (#6463) PaperMC/Paper@8fe8ca6 Add clickable version on version command (#9347) PaperMC/Paper@d6d2b6f Only capture actual tree growth (#6464)
265 lines
16 KiB
Diff
265 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 db54a9c32578defa02fa58dc694c96684a4885ac..6c2477f066f887557e89456994a49ddaf1f8aa27 100644
|
|
--- a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
|
|
@@ -339,6 +339,40 @@ 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 Optional<SoundEvent> asVanillaSound(final Key key) {
|
|
+ return BuiltInRegistries.SOUND_EVENT.getOptional(asVanilla(key));
|
|
+ }
|
|
+
|
|
+ public static Optional<Holder.Reference<SoundEvent>> asSoundHolder(final net.minecraft.resources.ResourceKey<SoundEvent> key) {
|
|
+ return BuiltInRegistries.SOUND_EVENT.getHolder(key);
|
|
+ }
|
|
+
|
|
+ public static Optional<Holder.Reference<net.minecraft.sounds.SoundEvent>> asVanillaSoundHolder(final Key key) {
|
|
+ return asSoundHolder(net.minecraft.resources.ResourceKey.create(net.minecraft.core.registries.Registries.SOUND_EVENT, asVanilla(key)));
|
|
+ }
|
|
+
|
|
+ @SuppressWarnings("PatternValidation")
|
|
+ public static Key asAdventure(final ResourceLocation key) {
|
|
+ return Key.key(key.getNamespace(), key.getPath());
|
|
+ }
|
|
+ // Parchment end
|
|
+
|
|
public static Packet<?> asSoundPacket(final Sound sound, final double x, final double y, final double z, final long seed, @Nullable BiConsumer<Packet<?>, Float> packetConsumer) {
|
|
final ResourceLocation name = asVanilla(sound.name());
|
|
final Optional<SoundEvent> soundEvent = BuiltInRegistries.SOUND_EVENT.getOptional(name);
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 18aac3da3c88f33b1a71a5920a8daa27e9723913..1727c741664b981311b69fadc849ac6de5423a6a 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1753,12 +1753,46 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
|
|
@Override
|
|
public void playSeededSound(@Nullable Player except, double x, double y, double z, Holder<SoundEvent> sound, SoundSource category, float volume, float pitch, long seed) {
|
|
- this.server.getPlayerList().broadcast(except, x, y, z, (double) ((SoundEvent) sound.value()).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()
|
|
+ .type(sound.unwrap().<net.kyori.adventure.key.Key>map(
|
|
+ key -> io.papermc.paper.adventure.PaperAdventure.asAdventure(key.location()),
|
|
+ soundEvent -> io.papermc.paper.adventure.PaperAdventure.asAdventure(soundEvent.getLocation())
|
|
+ ))
|
|
+ .source(io.papermc.paper.adventure.PaperAdventure.asAdventure(category))
|
|
+ .volume(volume)
|
|
+ .pitch(pitch)
|
|
+ .seed(seed)
|
|
+ .build(),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(this, x, y, z),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.DISTANCE_FUNCTION,
|
|
+ null
|
|
+ ));
|
|
+ // Parchment end
|
|
}
|
|
|
|
@Override
|
|
public void playSeededSound(@Nullable Player except, Entity entity, Holder<SoundEvent> sound, SoundSource category, float volume, float pitch, long seed) {
|
|
- this.server.getPlayerList().broadcast(except, entity.getX(), entity.getY(), entity.getZ(), (double) ((SoundEvent) sound.value()).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()
|
|
+ .type(sound.unwrap().<net.kyori.adventure.key.Key>map(
|
|
+ key -> io.papermc.paper.adventure.PaperAdventure.asAdventure(key.location()),
|
|
+ soundEvent -> io.papermc.paper.adventure.PaperAdventure.asAdventure(soundEvent.getLocation())
|
|
+ ))
|
|
+ .source(io.papermc.paper.adventure.PaperAdventure.asAdventure(category))
|
|
+ .volume(volume)
|
|
+ .pitch(pitch)
|
|
+ .seed(seed)
|
|
+ .build(),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(entity),
|
|
+ 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 dc5fda83a66afbfeb7897fc20b4742899d8aca08..6a5c781cf14521659426cf30bd1c46cd65814df4 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -2328,7 +2328,20 @@ public class ServerPlayer extends Player {
|
|
|
|
@Override
|
|
public void playNotifySound(SoundEvent event, SoundSource category, float volume, float pitch) {
|
|
- this.connection.send(new ClientboundSoundPacket(BuiltInRegistries.SOUND_EVENT.wrapAsHolder(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()
|
|
+ .type(io.papermc.paper.adventure.PaperAdventure.asAdventure(event.getLocation()))
|
|
+ .source(io.papermc.paper.adventure.PaperAdventure.asAdventure(category))
|
|
+ .volume(volume)
|
|
+ .pitch(pitch)
|
|
+ .seed(this.random.nextLong())
|
|
+ .build(),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(level(), getX(), getY(), getZ()),
|
|
+ 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 640e9bd618dc8286933318744c2064ede1fd9b5f..38eae743afa3c517c59bb1df83b1871d06165dbc 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -947,7 +947,7 @@ public abstract class PlayerList {
|
|
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.value(), 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 58152160d609d0e9d105153aeb166a56a7955603..7a4a07cd0618e7d51be0824e9102e979dfbdc7e6 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -1918,7 +1918,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(net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.wrapAsHolder(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()
|
|
+ .type(io.papermc.paper.adventure.PaperAdventure.asAdventure(soundEffect.getLocation()))
|
|
+ .source(io.papermc.paper.adventure.PaperAdventure.asAdventure(soundCategory))
|
|
+ .volume(volume)
|
|
+ .pitch(pitch)
|
|
+ .seed(fromEntity.random.nextLong())
|
|
+ .build(),
|
|
+ gg.projecteden.parchment.event.sound.ParchmentSoundEvent.createEmitter(fromEntity.level(), x, y, z),
|
|
+ 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 f7399737548483905f3b5c08a03876b0da54b714..e668de87a5b58febf451fe4be79e47143f4eab01 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
@@ -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.value(), 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 26e1a9002d675245d4cf91e6682605314b078fb2..9d5b1851f719cb51a64f7aa904268867f1855d72 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -2106,4 +2106,42 @@ public class CraftEventFactory {
|
|
return event;
|
|
}
|
|
// Paper end - add EntityFertilizeEggEvent
|
|
+
|
|
+ // 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) {
|
|
+ net.kyori.adventure.sound.Sound sound = event.calculateSound(recipient);
|
|
+ ResourceLocation name = io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.name());
|
|
+ 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 = sound.seed().orElse(0L); // TODO: random source?
|
|
+ net.minecraft.resources.ResourceKey<net.minecraft.sounds.SoundEvent> soundKey = net.minecraft.resources.ResourceKey.create(net.minecraft.core.registries.Registries.SOUND_EVENT, name);
|
|
+ net.minecraft.core.Holder.Reference<net.minecraft.sounds.SoundEvent> soundEvent = io.papermc.paper.adventure.PaperAdventure.asVanillaSoundHolder(sound.name()) // TODO: calculate event distance?
|
|
+ .orElseGet(() -> net.minecraft.core.Holder.Reference.create(net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.holderOwner(), soundKey, net.minecraft.sounds.SoundEvent.createFixedRangeEvent(name, (float) event.calculateDistance())));
|
|
+ if (emitter instanceof gg.projecteden.parchment.event.sound.SoundEvent.EntityEmitter entityEmitter)
|
|
+ return new net.minecraft.network.protocol.game.ClientboundSoundEntityPacket(soundEvent, source, ((CraftEntity) entityEmitter.entity()).getHandle(), volume, pitch, seed);
|
|
+ else if (emitter instanceof gg.projecteden.parchment.event.sound.SoundEvent.LocationEmitter locationEmitter) {
|
|
+ org.bukkit.Location loc = locationEmitter.getLocation();
|
|
+ return new net.minecraft.network.protocol.game.ClientboundSoundPacket(soundEvent, source, loc.getX(), loc.getY(), loc.getZ(), volume, pitch, seed);
|
|
+ }
|
|
+ throw new IllegalArgumentException("Unknown emitter type: " + emitter.getClass().getName());
|
|
+ }
|
|
+
|
|
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event) {
|
|
+ org.apache.commons.lang3.Validate.notNull(event, "event");
|
|
+ io.papermc.paper.util.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
|
|
}
|