Upstream has released updates that appear to apply and compile correctly Paper Changes: PaperMC/Paper@c50fc3a Updated Upstream (Bukkit/CraftBukkit/Spigot) (#7480) PaperMC/Paper@2a4aef3 Mark ChatRender#render as ApiStatus.Override PaperMC/Paper@f5b9e07 Add GameEvent tags (#6439) PaperMC/Paper@b173c3e Use access transformers for player profile API (#7468) PaperMC/Paper@286bd1b 1.18 misc performance dev branch (#7368) PaperMC/Paper@5bb4549 Fix entity armor not showing on death animation (#7355) PaperMC/Paper@7b8e0c3 Updated Upstream (Bukkit/CraftBukkit) PaperMC/Paper@36a1650 Furnace RecipesUsed API (#7399) PaperMC/Paper@392acfd Configurable sculk sensor listener range (#6443) PaperMC/Paper@b757019 Add missing block data mins and maxes (#6790) PaperMC/Paper@9cab01e [ci skip] Update Gradle wrapper to 7.4 PaperMC/Paper@cdb893b Add mid-tick task execution to block ticking PaperMC/Paper@854f3d3 Put world into worldlist before initing the world PaperMC/Paper@db81163 Execute mid tick tasks during tile entity ticking PaperMC/Paper@501834e Fix custom inventory holders (#6199) PaperMC/Paper@04a337a Add some missing deprecations to the adventure patch (#7500) PaperMC/Paper@b6dad9c Fix desync on teleporting entity on first tick (#7183) PaperMC/Paper@2a55e35 Option to have default CustomSpawners in custom worlds (#7493) PaperMC/Paper@bfa50ad Custom Potion Mixes (#6744) PaperMC/Paper@7f65b0b Add DataConverter to StructureCheck, for structure lookups PaperMC/Paper@30cb7d0 ignore excessive vel for Minecarts (Fixes #7515)
169 lines
12 KiB
Diff
169 lines
12 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/net/minecraft/server/level/ServerLevel.java b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
index 768017ba650f1bd96e3db0aad8fda939e2ea7add..47ccd16dd86072805359266b746ff9a70e4513ad 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
|
|
@@ -1509,12 +1509,12 @@ public class ServerLevel extends Level implements WorldGenLevel {
|
|
|
|
@Override
|
|
public void playSound(@Nullable Player except, double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch) {
|
|
- this.server.getPlayerList().broadcast(except, x, y, z, volume > 1.0F ? (double) (16.0F * volume) : 16.0D, this.dimension(), new ClientboundSoundPacket(sound, category, x, y, z, volume, pitch));
|
|
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.LocationNamedSoundEvent(null, getWorld(), new org.bukkit.util.Vector(x, y, z), org.bukkit.craftbukkit.CraftSound.getBukkit(sound), org.bukkit.SoundCategory.valueOf(category.name()), volume, pitch), this.server, volume > 1.0F ? (double) (16.0F * volume) : 16.0D); // Parchment
|
|
}
|
|
|
|
@Override
|
|
public void playSound(@Nullable Player except, Entity entity, SoundEvent sound, SoundSource category, float volume, float pitch) {
|
|
- this.server.getPlayerList().broadcast(except, entity.getX(), entity.getY(), entity.getZ(), volume > 1.0F ? (double) (16.0F * volume) : 16.0D, this.dimension(), new ClientboundSoundEntityPacket(sound, category, entity, volume, pitch));
|
|
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.EntitySoundEvent(null, entity.getBukkitEntity(), org.bukkit.craftbukkit.CraftSound.getBukkit(sound), org.bukkit.SoundCategory.valueOf(category.name()), volume, pitch), this.server, volume > 1.0F ? (double) (16.0F * volume) : 16.0D); // Parchment
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
index 470dbed47830e2f580c090bc762a7be5cf389ce5..c0ec32d2575bd9bfcea81ec60af22bb341b7802b 100644
|
|
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
|
|
@@ -2189,7 +2189,7 @@ 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));
|
|
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.LocationNamedSoundEvent(getBukkitEntity(), org.bukkit.craftbukkit.CraftSound.getBukkit(event), org.bukkit.SoundCategory.valueOf(category.name()), volume, pitch), this); // Parchment
|
|
}
|
|
|
|
@Override
|
|
diff --git a/src/main/java/net/minecraft/server/players/PlayerList.java b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
index 7a0c1ba40156df69bbbf36d96bed0950130d2351..7d535b82ccfd3d5269ecaeb35a8cb9ac7d18a69a 100644
|
|
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
|
|
@@ -967,7 +967,7 @@ public abstract class PlayerList {
|
|
if (flag2 && !isLocAltered) {
|
|
BlockState data = worldserver1.getBlockState(blockposition);
|
|
worldserver1.setBlock(blockposition, data.setValue(RespawnAnchorBlock.CHARGE, data.getValue(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));
|
|
+ entityplayer1.playNotifySound(SoundEvents.RESPAWN_ANCHOR_DEPLETE, SoundSource.BLOCKS, 1.0F, 1.0F); // Parchment
|
|
// 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 d85da02be7f1d494af8f2cc840c49073774f5f9c..a90cbb8d5c3231f3278bd4893fa1443827c6567b 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/player/Player.java
|
|
@@ -1833,7 +1833,7 @@ 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 ClientboundSoundPacket(soundEffect, soundCategory, x, y, z, volume, pitch));
|
|
+ CraftEventFactory.playSoundEvent(new gg.projecteden.parchment.event.sound.LocationNamedSoundEvent(fromEntity.getBukkitEntity(), new org.bukkit.util.Vector(x, y, z), org.bukkit.craftbukkit.CraftSound.getBukkit(soundEffect), org.bukkit.SoundCategory.valueOf(soundCategory.name()), volume, pitch), (ServerPlayer) fromEntity); // Parchment
|
|
}
|
|
}
|
|
// 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 7131226de05bc57830f7a68ba545ebfd19d33a59..56b5f5f9992c9f9fea7a606684efd44c901e3525 100644
|
|
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
|
|
@@ -26,7 +26,7 @@ import net.minecraft.nbt.ListTag;
|
|
import net.minecraft.nbt.NbtUtils;
|
|
import net.minecraft.network.chat.Component;
|
|
import net.minecraft.network.chat.TranslatableComponent;
|
|
-import net.minecraft.network.protocol.game.ClientboundSoundPacket;
|
|
+//import net.minecraft.network.protocol.game.ClientboundSoundPacket; // Parchment
|
|
import net.minecraft.server.level.ServerBossEvent;
|
|
import net.minecraft.server.level.ServerLevel;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
@@ -537,7 +537,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));
|
|
+ entityplayer.playNotifySound(SoundEvents.RAID_HORN, SoundSource.NEUTRAL, 64.0F, 1.0F); // Parchment
|
|
}
|
|
}
|
|
|
|
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
index a3c8a0291fa9ae6f3c96d937dd4621edd7c48535..d2a1368eeff0704760432166e0910343512bbe4f 100644
|
|
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
|
|
@@ -1919,4 +1919,77 @@ public class CraftEventFactory {
|
|
return event.callEvent();
|
|
}
|
|
// Paper end
|
|
+
|
|
+ // Parchment start
|
|
+ private static net.minecraft.network.protocol.Packet<net.minecraft.network.protocol.game.ClientGamePacketListener> handleSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent _event) {
|
|
+ if (!_event.callEvent()) {
|
|
+ return null;
|
|
+ } else {
|
|
+ float volume = _event.getVolume();
|
|
+ float pitch = _event.getPitch();
|
|
+ net.minecraft.sounds.SoundSource source = net.minecraft.sounds.SoundSource.valueOf(_event.getCategory().name());
|
|
+
|
|
+ if (_event instanceof gg.projecteden.parchment.event.sound.NamedSoundEvent namedSoundEvent) {
|
|
+ net.minecraft.sounds.SoundEvent sound = org.bukkit.craftbukkit.CraftSound.getSoundEffect(namedSoundEvent.getSound());
|
|
+
|
|
+ if (_event instanceof gg.projecteden.parchment.event.sound.LocationNamedSoundEvent event) {
|
|
+ org.bukkit.util.Vector pos = event.getVector();
|
|
+ return new net.minecraft.network.protocol.game.ClientboundSoundPacket(sound, source, pos.getX(), pos.getY(), pos.getZ(), volume, pitch);
|
|
+ } else {
|
|
+ gg.projecteden.parchment.event.sound.EntitySoundEvent event = (gg.projecteden.parchment.event.sound.EntitySoundEvent) _event;
|
|
+ return new net.minecraft.network.protocol.game.ClientboundSoundEntityPacket(sound, source, ((CraftEntity) event.getOrigin()).getHandle(), volume, pitch);
|
|
+ }
|
|
+ } else {
|
|
+ gg.projecteden.parchment.event.sound.LocationCustomSoundEvent event = (gg.projecteden.parchment.event.sound.LocationCustomSoundEvent) _event;
|
|
+ org.bukkit.util.Vector pos = event.getVector();
|
|
+ return new net.minecraft.network.protocol.game.ClientboundCustomSoundPacket(CraftNamespacedKey.toMinecraft(event.getKey()), source, org.bukkit.craftbukkit.util.CraftVector.toNMS(pos), volume, pitch);
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event, java.util.function.Consumer<net.minecraft.network.protocol.Packet<net.minecraft.network.protocol.game.ClientGamePacketListener>> soundPlayer) {
|
|
+ org.apache.commons.lang3.Validate.notNull(event, "event");
|
|
+ org.apache.commons.lang3.Validate.notNull(soundPlayer, "soundPlayer");
|
|
+ if (!(event instanceof gg.projecteden.parchment.event.sound.LocationNamedSoundEvent || event instanceof gg.projecteden.parchment.event.sound.LocationCustomSoundEvent || event instanceof gg.projecteden.parchment.event.sound.EntitySoundEvent)) {
|
|
+ throw new IllegalArgumentException("Unknown sound event: " + event.getClass().getName());
|
|
+ }
|
|
+ java.util.concurrent.CompletableFuture.supplyAsync(() -> handleSoundEvent(event), net.minecraft.server.MCUtil.asyncExecutor).thenAcceptAsync(packet -> {
|
|
+ if (packet != null)
|
|
+ soundPlayer.accept(packet);
|
|
+ }, net.minecraft.server.MCUtil.asyncExecutor);
|
|
+ }
|
|
+
|
|
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event, CraftPlayer sendTo) {
|
|
+ playSoundEvent(event, sendTo.getHandle());
|
|
+ }
|
|
+
|
|
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event, ServerPlayer sendTo) {
|
|
+ playSoundEvent(event, sendTo.connection);
|
|
+ }
|
|
+
|
|
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event, net.minecraft.server.network.ServerPlayerConnection sendTo) {
|
|
+ playSoundEvent(event, sendTo::send);
|
|
+ }
|
|
+
|
|
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event, net.minecraft.server.MinecraftServer server, double radius) {
|
|
+ playSoundEvent(event, server.getPlayerList(), radius);
|
|
+ }
|
|
+
|
|
+ public static void playSoundEvent(gg.projecteden.parchment.event.sound.SoundEvent event, net.minecraft.server.players.PlayerList playerList, double radius) {
|
|
+ final net.minecraft.world.entity.player.Player player = event.getPlayer() == null ? null : ((org.bukkit.craftbukkit.entity.CraftHumanEntity) event.getPlayer()).getHandle();
|
|
+ final net.minecraft.resources.ResourceKey<Level> world = ((CraftWorld) event.getWorld()).getHandle().dimension();
|
|
+ final org.bukkit.util.Vector pos;
|
|
+ if (event instanceof gg.projecteden.parchment.HasLocation hasLoc) {
|
|
+ pos = hasLoc.getLocation().toVector();
|
|
+ } else if (event instanceof gg.projecteden.parchment.event.sound.EntitySoundEvent entityEvent) {
|
|
+ pos = entityEvent.getOrigin().getLocation().toVector();
|
|
+ } else {
|
|
+ throw new IllegalArgumentException("Could not determine location of sound event");
|
|
+ }
|
|
+ final double posX = pos.getX();
|
|
+ final double posY = pos.getY();
|
|
+ final double posZ = pos.getZ();
|
|
+ playSoundEvent(event, packet -> playerList.broadcast(player, posX, posY, posZ, radius, world, packet));
|
|
+ }
|
|
+ // Parchment end
|
|
}
|