Files
ParchmentMC/patches/reverted/server/0010-Add-SoundEvent.patch
2021-06-17 03:03:07 -04:00

430 lines
31 KiB
Diff

From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: lexikiq <noellekiq@gmail.com>
Date: Wed, 9 Jun 2021 18:39:18 -0400
Subject: [PATCH] Add SoundEvent
diff --git a/src/main/java/net/minecraft/server/commands/CommandPlaySound.java b/src/main/java/net/minecraft/server/commands/CommandPlaySound.java
index f896dd7447d8a8fbc6e3c1abad0c3da5448273c1..2ee039d18ddd98298586f1ace2e6b980cb3061e0 100644
--- a/src/main/java/net/minecraft/server/commands/CommandPlaySound.java
+++ b/src/main/java/net/minecraft/server/commands/CommandPlaySound.java
@@ -15,7 +15,6 @@ import net.minecraft.commands.arguments.ArgumentMinecraftKeyRegistered;
import net.minecraft.commands.arguments.coordinates.ArgumentVec3;
import net.minecraft.commands.synchronization.CompletionProviders;
import net.minecraft.network.chat.ChatMessage;
-import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect;
import net.minecraft.resources.MinecraftKey;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.sounds.SoundCategory;
@@ -81,7 +80,7 @@ public class CommandPlaySound {
f3 = f2;
}
- entityplayer.playerConnection.sendPacket(new PacketPlayOutCustomSoundEffect(minecraftkey, soundcategory, vec3d1, f3, f1));
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationCustomSoundEvent(entityplayer.getBukkitEntity(), entityplayer.getWorldServer().getWorld(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(vec3d1), org.bukkit.craftbukkit.util.CraftNamespacedKey.fromMinecraft(minecraftkey), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f3, f1), entityplayer); // Parchment - sound event
++i;
}
diff --git a/src/main/java/net/minecraft/server/level/EntityPlayer.java b/src/main/java/net/minecraft/server/level/EntityPlayer.java
index 75bcfb3a2b4a104aeebb2fe3298714b2e5b569d2..703ae4aab9b47415a31245c2be641b6fa41502b7 100644
--- a/src/main/java/net/minecraft/server/level/EntityPlayer.java
+++ b/src/main/java/net/minecraft/server/level/EntityPlayer.java
@@ -53,7 +53,6 @@ import net.minecraft.network.protocol.game.PacketPlayOutExperience;
import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange;
import net.minecraft.network.protocol.game.PacketPlayOutLookAt;
import net.minecraft.network.protocol.game.PacketPlayOutNamedEntitySpawn;
-import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
import net.minecraft.network.protocol.game.PacketPlayOutOpenBook;
import net.minecraft.network.protocol.game.PacketPlayOutOpenSignEditor;
import net.minecraft.network.protocol.game.PacketPlayOutOpenWindow;
@@ -2158,7 +2157,7 @@ public class EntityPlayer extends EntityHuman implements ICrafting {
@Override
public void a(SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) {
- this.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(soundeffect, soundcategory, this.locX(), this.locY(), this.locZ(), f, f1));
+ CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(this.getBukkitEntity(), this.getWorld().getWorld(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(this.getPositionVector()), org.bukkit.craftbukkit.CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1), this); // Parchment - sound event
}
@Override
diff --git a/src/main/java/net/minecraft/server/level/WorldServer.java b/src/main/java/net/minecraft/server/level/WorldServer.java
index f68a252378a94c8fcab622d2d89d738aceab45a4..7a290adb13ed083db50f197fc2acf0007f6dd2d2 100644
--- a/src/main/java/net/minecraft/server/level/WorldServer.java
+++ b/src/main/java/net/minecraft/server/level/WorldServer.java
@@ -58,11 +58,9 @@ import net.minecraft.network.protocol.Packet;
import net.minecraft.network.protocol.game.PacketDebug;
import net.minecraft.network.protocol.game.PacketPlayOutBlockAction;
import net.minecraft.network.protocol.game.PacketPlayOutBlockBreakAnimation;
-import net.minecraft.network.protocol.game.PacketPlayOutEntitySound;
import net.minecraft.network.protocol.game.PacketPlayOutEntityStatus;
import net.minecraft.network.protocol.game.PacketPlayOutExplosion;
import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange;
-import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
import net.minecraft.network.protocol.game.PacketPlayOutSpawnPosition;
import net.minecraft.network.protocol.game.PacketPlayOutWorldEvent;
import net.minecraft.network.protocol.game.PacketPlayOutWorldParticles;
@@ -168,6 +166,10 @@ import org.bukkit.event.server.MapInitializeEvent;
import org.bukkit.event.weather.LightningStrikeEvent;
import org.bukkit.event.world.TimeSkipEvent;
// CraftBukkit end
+// Parchment start
+import org.bukkit.craftbukkit.CraftSound;
+import org.bukkit.util.Vector;
+// Parchment end
public class WorldServer extends World implements GeneratorAccessSeed {
@@ -1663,12 +1665,20 @@ public class WorldServer extends World implements GeneratorAccessSeed {
@Override
public void playSound(@Nullable EntityHuman entityhuman, double d0, double d1, double d2, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) {
- this.server.getPlayerList().sendPacketNearby(entityhuman, d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this.getDimensionKey(), new PacketPlayOutNamedSoundEffect(soundeffect, soundcategory, d0, d1, d2, f, f1));
+ // Parchment start
+ CraftEventFactory.playSoundEvent(
+ new me.lexikiq.event.sound.LocationNamedSoundEvent(entityhuman == null ? null : entityhuman.getBukkitEntity(), getWorld(), new org.bukkit.util.Vector(d0, d1, d2), org.bukkit.craftbukkit.CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1),
+ this.server, entityhuman, d0, d1, d2, f > 1.0F ? (double) (16.0F * f) : 16.0D, this);
+ // Parchment end
}
@Override
public void playSound(@Nullable EntityHuman entityhuman, Entity entity, SoundEffect soundeffect, SoundCategory soundcategory, float f, float f1) {
- this.server.getPlayerList().sendPacketNearby(entityhuman, entity.locX(), entity.locY(), entity.locZ(), f > 1.0F ? (double) (16.0F * f) : 16.0D, this.getDimensionKey(), new PacketPlayOutEntitySound(soundeffect, soundcategory, entity, f, f1));
+ // Parchment start
+ CraftEventFactory.playSoundEvent(
+ new me.lexikiq.event.sound.EntitySoundEvent(entityhuman == null ? null : entityhuman.getBukkitEntity(), entity.getBukkitEntity(), org.bukkit.craftbukkit.CraftSound.getBukkit(soundeffect), org.bukkit.SoundCategory.valueOf(soundcategory.name()), f, f1),
+ this.server, entityhuman, entity.locX(), entity.locY(), entity.locZ(), f > 1.0F ? (double) (16.0F * f) : 16.0D, this);
+ // 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 90776231b1faffb11e4394f555f336ca248e3004..319226264b341fa04ab264087e243c8b87d8c012 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -43,7 +43,6 @@ import net.minecraft.network.protocol.game.PacketPlayOutGameStateChange;
import net.minecraft.network.protocol.game.PacketPlayOutHeldItemSlot;
import net.minecraft.network.protocol.game.PacketPlayOutKickDisconnect;
import net.minecraft.network.protocol.game.PacketPlayOutLogin;
-import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
import net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo;
import net.minecraft.network.protocol.game.PacketPlayOutRecipeUpdate;
import net.minecraft.network.protocol.game.PacketPlayOutRespawn;
@@ -67,8 +66,6 @@ import net.minecraft.server.level.PlayerInteractManager;
import net.minecraft.server.level.TicketType;
import net.minecraft.server.level.WorldServer;
import net.minecraft.server.network.PlayerConnection;
-import net.minecraft.sounds.SoundCategory;
-import net.minecraft.sounds.SoundEffects;
import net.minecraft.stats.ServerStatisticManager;
import net.minecraft.stats.StatisticList;
import net.minecraft.tags.Tag;
@@ -981,7 +978,7 @@ public abstract class PlayerList {
if (flag2 && !isLocAltered) {
IBlockData data = worldserver1.getType(blockposition);
worldserver1.setTypeAndData(blockposition, data.set(BlockRespawnAnchor.a, data.get(BlockRespawnAnchor.a) - 1), 3);
- entityplayer1.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.BLOCK_RESPAWN_ANCHOR_DEPLETE, SoundCategory.BLOCKS, (double) location.getX(), (double) location.getY(), (double) location.getZ(), 1.0F, 1.0F));
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(entityplayer1.getBukkitEntity(), entityplayer1.getWorld().getWorld(), org.bukkit.craftbukkit.util.CraftVector.toBukkit(entityplayer1.getPositionVector()), org.bukkit.Sound.BLOCK_RESPAWN_ANCHOR_DEPLETE, org.bukkit.SoundCategory.BLOCKS, 1.0F, 1.0F), entityplayer1); // Parchment - sound event
// Paper end
}
// Added from changeDimension
diff --git a/src/main/java/net/minecraft/world/entity/EntityLightning.java b/src/main/java/net/minecraft/world/entity/EntityLightning.java
index 85f571a791bce63989890f277857bc7bdeec0cb5..fb7feb22c964cc6f2cfafa84ef3068d35d56cb04 100644
--- a/src/main/java/net/minecraft/world/entity/EntityLightning.java
+++ b/src/main/java/net/minecraft/world/entity/EntityLightning.java
@@ -12,9 +12,7 @@ import net.minecraft.network.protocol.game.PacketPlayOutSpawnEntity;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.WorldServer;
import net.minecraft.sounds.SoundCategory;
-import net.minecraft.sounds.SoundEffects;
import net.minecraft.world.EnumDifficulty;
-import net.minecraft.world.entity.player.EntityHuman;
import net.minecraft.world.level.GameRules;
import net.minecraft.world.level.IBlockAccess;
import net.minecraft.world.level.World;
@@ -23,9 +21,13 @@ import net.minecraft.world.level.block.state.IBlockData;
import net.minecraft.world.phys.AxisAlignedBB;
// CraftBukkit start
-import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
import org.bukkit.craftbukkit.event.CraftEventFactory;
// CraftBukkit end
+// Parchment start
+import org.bukkit.Sound;
+import org.bukkit.util.Vector;
+import me.lexikiq.event.sound.LocationNamedSoundEvent;
+// Parchment end
public class EntityLightning extends Entity {
@@ -88,8 +90,7 @@ public class EntityLightning extends Entity {
double distanceSquared = deltaX * deltaX + deltaZ * deltaZ;
// Paper start - Limit lightning strike effect distance
if (distanceSquared <= this.world.paperConfig.sqrMaxLightningImpactSoundDistance) {
- player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT,
- SoundCategory.WEATHER, this.locX(), this.locY(), this.locZ(), 2.0f, 0.5F + this.random.nextFloat() * 0.2F));
+ CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(player.getBukkitEntity(), world.getWorld(), new org.bukkit.util.Vector(this.locX(), this.locY(), this.locZ()), org.bukkit.Sound.ENTITY_LIGHTNING_BOLT_IMPACT, org.bukkit.SoundCategory.WEATHER, 2f, 0.5F + this.random.nextFloat() * 0.2F), player); // Parchment - sound event
}
if (world.paperConfig.sqrMaxThunderDistance != -1 && distanceSquared >= world.paperConfig.sqrMaxThunderDistance) {
@@ -97,14 +98,14 @@ public class EntityLightning extends Entity {
}
// Paper end
+ double relativeX = this.locX(); // Parchment - sound event
+ double relativeZ = this.locZ(); // Parchment - sound event
if (distanceSquared > viewDistance * viewDistance) {
double deltaLength = Math.sqrt(distanceSquared);
- double relativeX = player.locX() + (deltaX / deltaLength) * viewDistance;
- double relativeZ = player.locZ() + (deltaZ / deltaLength) * viewDistance;
- player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, relativeX, this.locY(), relativeZ, 10000.0F, pitch));
- } else {
- player.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.ENTITY_LIGHTNING_BOLT_THUNDER, SoundCategory.WEATHER, this.locX(), this.locY(), this.locZ(), 10000.0F, pitch));
+ relativeX = player.locX() + (deltaX / deltaLength) * viewDistance; // Parchment - sound event
+ relativeZ = player.locZ() + (deltaZ / deltaLength) * viewDistance; // Parchment - sound event
}
+ CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(player.getBukkitEntity(), world.getWorld(), new org.bukkit.util.Vector(relativeX, this.locY(), relativeZ), org.bukkit.Sound.ENTITY_LIGHTNING_BOLT_THUNDER, org.bukkit.SoundCategory.WEATHER, 10000.0F, pitch), player); // Parchment - sound event
}
// CraftBukkit end
// this.world.playSound((EntityHuman) null, this.locX(), this.locY(), this.locZ(), SoundEffects.ENTITY_LIGHTNING_BOLT_IMPACT, SoundCategory.WEATHER, 2.0F, 0.5F + this.random.nextFloat() * 0.2F); // Paper - Limit lightning strike effect distance (the packet is now sent from inside the loop)
diff --git a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
index c39c50e53549e9cb9d3520bc7e8b7e89cfa20163..9c344b510bca742f31911fddeeb7c947c335e2e8 100644
--- a/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
+++ b/src/main/java/net/minecraft/world/entity/player/EntityHuman.java
@@ -28,7 +28,6 @@ import net.minecraft.network.chat.ChatMessage;
import net.minecraft.network.chat.IChatBaseComponent;
import net.minecraft.network.chat.IChatMutableComponent;
import net.minecraft.network.protocol.game.PacketPlayOutEntityVelocity;
-import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
import net.minecraft.network.syncher.DataWatcher;
import net.minecraft.network.syncher.DataWatcherObject;
import net.minecraft.network.syncher.DataWatcherRegistry;
@@ -1755,7 +1754,7 @@ public abstract class EntityHuman extends EntityLiving {
private static void sendSoundEffect(EntityHuman fromEntity, double x, double y, double z, SoundEffect soundEffect, SoundCategory soundCategory, float volume, float pitch) {
fromEntity.world.playSound(fromEntity, x, y, z, soundEffect, soundCategory, volume, pitch); // This will not send the effect to the entity himself
if (fromEntity instanceof EntityPlayer) {
- ((EntityPlayer) fromEntity).playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(soundEffect, soundCategory, x, y, z, volume, pitch));
+ CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(((EntityPlayer) fromEntity).getBukkitEntity(), fromEntity.getWorld().getWorld(), new org.bukkit.util.Vector(x, y, z), org.bukkit.craftbukkit.CraftSound.getBukkit(soundEffect), org.bukkit.SoundCategory.valueOf(soundCategory.name()), volume, pitch), ((EntityPlayer) fromEntity)); // Parchment - sound event
}
}
// 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 457cbdab3fa96fdf7fad1b0206bec9c0aa7847d8..44d7231bb9901b84a1363e8bbbdf993d74f1744a 100644
--- a/src/main/java/net/minecraft/world/entity/raid/Raid.java
+++ b/src/main/java/net/minecraft/world/entity/raid/Raid.java
@@ -26,12 +26,9 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.chat.ChatMessage;
import net.minecraft.network.chat.IChatBaseComponent;
-import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
import net.minecraft.server.level.BossBattleServer;
import net.minecraft.server.level.EntityPlayer;
import net.minecraft.server.level.WorldServer;
-import net.minecraft.sounds.SoundCategory;
-import net.minecraft.sounds.SoundEffects;
import net.minecraft.stats.StatisticList;
import net.minecraft.util.MathHelper;
import net.minecraft.world.BossBattle;
@@ -495,7 +492,7 @@ public class Raid {
double d1 = vec3d.z + (double) (13.0F / f1) * (vec3d1.z - vec3d.z);
if (f1 <= 64.0F || collection.contains(entityplayer)) {
- entityplayer.playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(SoundEffects.EVENT_RAID_HORN, SoundCategory.NEUTRAL, d0, entityplayer.locY(), d1, 64.0F, 1.0F));
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(entityplayer.getBukkitEntity(), world.getWorld(), new org.bukkit.util.Vector(d0, entityplayer.locY(), d1), org.bukkit.Sound.EVENT_RAID_HORN, org.bukkit.SoundCategory.NEUTRAL, 64.0F, 1.0F), entityplayer); // Parchment - sound event
}
}
diff --git a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
index c0b49a0eaeda06b89a4fb425eec3d5bfa9717379..21891dad5b799ef4dbebbd47487ddf7b366ed937 100644
--- a/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
+++ b/src/main/java/org/bukkit/craftbukkit/CraftWorld.java
@@ -26,10 +26,8 @@ import net.minecraft.core.BlockPosition;
import net.minecraft.core.EnumDirection;
import net.minecraft.core.IRegistry;
import net.minecraft.data.worldgen.BiomeDecoratorGroups;
-import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect;
import net.minecraft.network.protocol.game.PacketPlayOutUpdateTime;
import net.minecraft.network.protocol.game.PacketPlayOutWorldEvent;
-import net.minecraft.resources.MinecraftKey;
import net.minecraft.server.MCUtil;
import net.minecraft.server.level.ChunkMapDistance;
import net.minecraft.server.level.PlayerChunk;
@@ -2326,8 +2324,11 @@ public class CraftWorld implements World {
double y = loc.getY();
double z = loc.getZ();
- PacketPlayOutCustomSoundEffect packet = new PacketPlayOutCustomSoundEffect(new MinecraftKey(sound), SoundCategory.valueOf(category.name()), new Vec3D(x, y, z), volume, pitch);
- world.getMinecraftServer().getPlayerList().sendPacketNearby(null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, this.world.getDimensionKey(), packet);
+ // Parchment start
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(
+ new me.lexikiq.event.sound.LocationCustomSoundEvent(null, this, new Vector(x, y, z), org.bukkit.craftbukkit.util.CraftNamespacedKey.fromString(sound), category, volume, pitch),
+ world.getMinecraftServer(), null, x, y, z, volume > 1.0F ? 16.0F * volume : 16.0D, world);
+ // Parchment end
}
private static Map<String, GameRules.GameRuleKey<?>> gamerules;
diff --git a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
index cfe6898dc373fe55a08acf5c90e200061aa7d0fc..e43fe61c298acdb346beac81003b8591d11eddc7 100644
--- a/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
+++ b/src/main/java/org/bukkit/craftbukkit/entity/CraftPlayer.java
@@ -41,10 +41,8 @@ import net.minecraft.network.protocol.game.PacketPlayOutBlockBreakAnimation;
import net.minecraft.network.protocol.game.PacketPlayOutBlockChange;
import net.minecraft.network.protocol.game.PacketPlayOutChat;
import net.minecraft.network.protocol.game.PacketPlayOutCustomPayload;
-import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect;
import net.minecraft.network.protocol.game.PacketPlayOutExperience;
import net.minecraft.network.protocol.game.PacketPlayOutMap;
-import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
import net.minecraft.network.protocol.game.PacketPlayOutPlayerInfo;
import net.minecraft.network.protocol.game.PacketPlayOutPlayerListHeaderFooter;
import net.minecraft.network.protocol.game.PacketPlayOutSpawnPosition;
@@ -582,7 +580,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
}
float f = (float) Math.pow(2.0D, (note - 12.0D) / 12.0D);
- getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect("block.note_block." + instrumentName), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f));
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(this, getWorld(), new org.bukkit.util.Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Sound.valueOf("BLOCK_NOTE_BLOCK_" + instrumentName.toUpperCase()), org.bukkit.SoundCategory.RECORDS, 3f, f), this); // Parchment - sound event
}
@Override
@@ -644,7 +642,7 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
break;
}
float f = (float) Math.pow(2.0D, (note.getId() - 12.0D) / 12.0D);
- getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect("block.note_block." + instrumentName), net.minecraft.sounds.SoundCategory.RECORDS, loc.getBlockX(), loc.getBlockY(), loc.getBlockZ(), 3.0f, f));
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(this, getWorld(), new org.bukkit.util.Vector(loc.getBlockX(), loc.getBlockY(), loc.getBlockZ()), Sound.valueOf("BLOCK_NOTE_BLOCK_" + instrumentName.toUpperCase()), org.bukkit.SoundCategory.RECORDS, 3f, f), this); // Parchment - sound event
}
@Override
@@ -660,17 +658,13 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
@Override
public void playSound(Location loc, Sound sound, org.bukkit.SoundCategory category, float volume, float pitch) {
if (loc == null || sound == null || category == null || getHandle().playerConnection == null) return;
-
- PacketPlayOutNamedSoundEffect packet = new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), loc.getX(), loc.getY(), loc.getZ(), volume, pitch);
- getHandle().playerConnection.sendPacket(packet);
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationNamedSoundEvent(this, getWorld(), loc.toVector(), sound, category, volume, pitch), this); // Parchment - sound event
}
@Override
public void playSound(Location loc, String sound, org.bukkit.SoundCategory category, float volume, float pitch) {
if (loc == null || sound == null || category == null || getHandle().playerConnection == null) return;
-
- PacketPlayOutCustomSoundEffect packet = new PacketPlayOutCustomSoundEffect(new MinecraftKey(sound), net.minecraft.sounds.SoundCategory.valueOf(category.name()), new Vec3D(loc.getX(), loc.getY(), loc.getZ()), volume, pitch);
- getHandle().playerConnection.sendPacket(packet);
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(new me.lexikiq.event.sound.LocationCustomSoundEvent(this, getWorld(), loc.toVector(), CraftNamespacedKey.fromString(sound), category, volume, pitch), this); // Parchment - sound event
}
@Override
@@ -2216,11 +2210,17 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
public void playSound(final net.kyori.adventure.sound.Sound sound, final double x, final double y, final double z) {
final MinecraftKey name = io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.name());
final java.util.Optional<net.minecraft.sounds.SoundEffect> event = net.minecraft.core.IRegistry.SOUND_EVENT.getOptional(name);
+ // Parchment start
+ me.lexikiq.event.sound.SoundEvent soundEvent;
+ org.bukkit.util.Vector pos = new org.bukkit.util.Vector(x, y, z);
+ org.bukkit.SoundCategory category = org.bukkit.SoundCategory.valueOf(io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()).name());
if (event.isPresent()) {
- this.getHandle().playerConnection.sendPacket(new PacketPlayOutNamedSoundEffect(event.get(), io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), x, y, z, sound.volume(), sound.pitch()));
+ soundEvent = new me.lexikiq.event.sound.LocationNamedSoundEvent(this, getWorld(), pos, CraftSound.getBukkit(event.get()), category, sound.volume(), sound.pitch());
} else {
- this.getHandle().playerConnection.sendPacket(new PacketPlayOutCustomSoundEffect(name, io.papermc.paper.adventure.PaperAdventure.asVanilla(sound.source()), new Vec3D(x, y, z), sound.volume(), sound.pitch()));
+ soundEvent = new me.lexikiq.event.sound.LocationCustomSoundEvent(this, getWorld(), pos, CraftNamespacedKey.fromMinecraft(name), category, sound.volume(), sound.pitch());
}
+ org.bukkit.craftbukkit.event.CraftEventFactory.playSoundEvent(soundEvent, this);
+ // Parchment end
}
@Override
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index 0df40bc18dcd66a367b82e435316851eb99d077c..375a51ce14fe0bd4ed0dac6f65167e9124307af1 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -231,6 +231,18 @@ import org.bukkit.inventory.meta.BookMeta;
import org.bukkit.potion.PotionEffect;
import org.bukkit.event.entity.SpawnerSpawnEvent; // Spigot
+// Parchment start
+import org.bukkit.util.Vector;
+import org.bukkit.craftbukkit.util.CraftVector;
+import org.bukkit.craftbukkit.CraftSound;
+import net.minecraft.network.protocol.game.PacketPlayOutCustomSoundEffect;
+import net.minecraft.network.protocol.game.PacketPlayOutEntitySound;
+import net.minecraft.network.protocol.game.PacketPlayOutNamedSoundEffect;
+import me.lexikiq.event.sound.EntitySoundEvent;
+import me.lexikiq.event.sound.LocationCustomSoundEvent;
+import me.lexikiq.event.sound.LocationNamedSoundEvent;
+import me.lexikiq.event.sound.SoundEvent;
+// Parchment end
public class CraftEventFactory {
public static final DamageSource MELTING = CraftDamageSource.copyOf(DamageSource.BURN);
@@ -1841,4 +1853,69 @@ public class CraftEventFactory {
return event.callEvent();
}
// Paper end
+
+ // Parchment start
+ private static net.minecraft.network.protocol.Packet<net.minecraft.network.protocol.game.PacketListenerPlayOut> handleSoundEvent(SoundEvent _event) {
+ if (!_event.callEvent())
+ return null;
+ else {
+ float volume = _event.getVolume();
+ float pitch = _event.getPitch();
+ if (_event instanceof LocationNamedSoundEvent) {
+ LocationNamedSoundEvent event = (LocationNamedSoundEvent) _event;
+ Vector pos = event.getVector();
+ return new PacketPlayOutNamedSoundEffect(CraftSound.getSoundEffect(event.getSound()), SoundCategory.valueOf(event.getCategory().name()), pos.getX(), pos.getY(), pos.getZ(), volume, pitch);
+ } else if (_event instanceof LocationCustomSoundEvent) {
+ LocationCustomSoundEvent event = (LocationCustomSoundEvent) _event;
+ Vector pos = event.getVector();
+ return new PacketPlayOutCustomSoundEffect(CraftNamespacedKey.toMinecraft(event.getKey()), SoundCategory.valueOf(event.getCategory().name()), CraftVector.toNMS(pos), volume, pitch);
+ } else { // EntitySoundEvent
+ EntitySoundEvent event = (EntitySoundEvent) _event;
+ return new PacketPlayOutEntitySound(CraftSound.getSoundEffect(event.getSound()), SoundCategory.valueOf(event.getCategory().name()), ((CraftEntity) event.getOrigin()).getHandle(), volume, pitch);
+ }
+ }
+ }
+
+ public static void playSoundEvent(SoundEvent event, java.util.function.Consumer<net.minecraft.network.protocol.Packet<net.minecraft.network.protocol.game.PacketListenerPlayOut>> soundPlayer) {
+ org.apache.commons.lang.Validate.notNull(event, "Sound event cannot be null");
+ org.apache.commons.lang.Validate.notNull(soundPlayer, "Sound packet consumer cannot be null");
+
+ if (!(event instanceof LocationNamedSoundEvent || event instanceof LocationCustomSoundEvent || event instanceof EntitySoundEvent))
+ throw new IllegalArgumentException("Unknown sound event: " + event.getClass().getName());
+
+ java.util.concurrent.ThreadPoolExecutor executor = net.minecraft.server.MCUtil.asyncExecutor;
+ java.util.concurrent.CompletableFuture.supplyAsync(() -> handleSoundEvent(event), executor).thenAcceptAsync(packet -> {
+ if (packet != null)
+ soundPlayer.accept(packet);
+ }, executor);
+ }
+
+ public static void playSoundEvent(SoundEvent event, CraftPlayer sendTo) {
+ playSoundEvent(event, sendTo.getHandle());
+ }
+
+ public static void playSoundEvent(SoundEvent event, net.minecraft.server.level.EntityPlayer sendTo) {
+ playSoundEvent(event, sendTo.playerConnection);
+ }
+
+ public static void playSoundEvent(SoundEvent event, net.minecraft.server.network.PlayerConnection sendTo) {
+ playSoundEvent(event, sendTo::sendPacket);
+ }
+
+ public static void playSoundEvent(SoundEvent event, net.minecraft.server.MinecraftServer server, @Nullable EntityHuman human, double x, double y, double z, double radius, World world) {
+ playSoundEvent(event, server, human, x, y, z, radius, world.getDimensionKey());
+ }
+
+ public static void playSoundEvent(SoundEvent event, net.minecraft.server.MinecraftServer server, @Nullable EntityHuman human, double x, double y, double z, double radius, net.minecraft.resources.ResourceKey<World> world) {
+ playSoundEvent(event, server.getPlayerList(), human, x, y, z, radius, world);
+ }
+
+ public static void playSoundEvent(SoundEvent event, net.minecraft.server.players.PlayerList playerList, @Nullable EntityHuman human, double x, double y, double z, double radius, World world) {
+ playSoundEvent(event, playerList, human, x, y, z, radius, world.getDimensionKey());
+ }
+
+ public static void playSoundEvent(SoundEvent event, net.minecraft.server.players.PlayerList playerList, @Nullable EntityHuman human, double x, double y, double z, double radius, net.minecraft.resources.ResourceKey<World> world) {
+ playSoundEvent(event, packet -> playerList.sendPacketNearby(human, x, y, z, radius, world, packet));
+ }
+ // Parchment end
}