feat: 1.20.1

This commit is contained in:
Lexi Larkin
2023-06-30 14:54:32 -04:00
parent 3edba7dac4
commit 17e63ac792
42 changed files with 783 additions and 828 deletions

View File

@@ -39,10 +39,10 @@ index 0000000000000000000000000000000000000000..44245b61f64e4e2eb21ac4f5e540aa9a
+ }
+}
diff --git a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
index ecddb6fe55e8ee1ca3b163503dd62200ce2d7d04..7d613f50cd0c6469a74529a834f30490defdaa00 100644
index db54a9c32578defa02fa58dc694c96684a4885ac..6c2477f066f887557e89456994a49ddaf1f8aa27 100644
--- a/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
+++ b/src/main/java/io/papermc/paper/adventure/PaperAdventure.java
@@ -325,6 +325,32 @@ public final class PaperAdventure {
@@ -339,6 +339,40 @@ public final class PaperAdventure {
return asVanilla(source);
}
@@ -62,8 +62,16 @@ index ecddb6fe55e8ee1ca3b163503dd62200ce2d7d04..7d613f50cd0c6469a74529a834f30490
+ };
+ }
+
+ public static java.util.Optional<net.minecraft.sounds.SoundEvent> asVanillaSound(final Key key) {
+ return net.minecraft.core.registries.BuiltInRegistries.SOUND_EVENT.getOptional(asVanilla(key));
+ 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")
@@ -72,62 +80,67 @@ index ecddb6fe55e8ee1ca3b163503dd62200ce2d7d04..7d613f50cd0c6469a74529a834f30490
+ }
+ // Parchment end
+
// NBT
public static @Nullable BinaryTagHolder asBinaryTagHolder(final @Nullable CompoundTag tag) {
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 5a5ff40df37db9cbd53c584ed26a3ce4888b29c0..30c05db4ad0fcd5aa83cb3168ed32c7b0d205972 100644
index 18aac3da3c88f33b1a71a5920a8daa27e9723913..1727c741664b981311b69fadc849ac6de5423a6a 100644
--- a/src/main/java/net/minecraft/server/level/ServerLevel.java
+++ b/src/main/java/net/minecraft/server/level/ServerLevel.java
@@ -1718,6 +1718,43 @@ public class ServerLevel extends Level implements WorldGenLevel {
this.neighborUpdater.neighborChanged(state, pos, sourceBlock, sourcePos, notify);
@@ -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
}
+ public void playSeededSound(@org.jetbrains.annotations.Nullable Player except, double x, double y, double z, SoundEvent sound, SoundSource category, float volume, float pitch, long 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(@org.jetbrains.annotations.Nullable Player except, Entity entity, SoundEvent sound, SoundSource category, float volume, float pitch, long 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
public void broadcastEntityEvent(Entity entity, byte status) {
this.getChunkSource().broadcastAndSend(entity, new ClientboundEntityEventPacket(entity, status));
diff --git a/src/main/java/net/minecraft/server/level/ServerPlayer.java b/src/main/java/net/minecraft/server/level/ServerPlayer.java
index 1d4d02f26391ac55c7631817f09d05e2769b0d29..cbcc4141c904360127780d6441a960842e661ef0 100644
index 9d46536f80b5b3e6641fd377c02166a431edfd77..2abe06cb5de5ac63c31c1a120a3239aca07557f8 100644
--- a/src/main/java/net/minecraft/server/level/ServerPlayer.java
+++ b/src/main/java/net/minecraft/server/level/ServerPlayer.java
@@ -2270,7 +2270,19 @@ public class ServerPlayer extends Player {
@@ -2328,7 +2328,20 @@ public class ServerPlayer extends Player {
@Override
public void playNotifySound(SoundEvent event, SoundSource category, float volume, float pitch) {
@@ -135,24 +148,25 @@ index 1d4d02f26391ac55c7631817f09d05e2769b0d29..cbcc4141c904360127780d6441a96084
+ // 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())
+ 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 c0c14766adaac855112f85a203a6163b8adfdded..d59d36c8a77524d5ac0c25a4ef1cf57f339eeda2 100644
index fff7ad7a45f310783ac96b44575ad3db13d537fa..5bb09632231293bd3551cac7988651657e2b3783 100644
--- a/src/main/java/net/minecraft/server/players/PlayerList.java
+++ b/src/main/java/net/minecraft/server/players/PlayerList.java
@@ -932,7 +932,7 @@ public abstract class PlayerList {
@@ -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);
}
@@ -162,25 +176,25 @@ index c0c14766adaac855112f85a203a6163b8adfdded..d59d36c8a77524d5ac0c25a4ef1cf57f
}
// 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 0629c471d38a77c44fc1c86ccdfcb0690f61ca17..791e9f43afae265f7f32588db2d6f2092c5f32c7 100644
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
@@ -1891,7 +1891,21 @@ public abstract class Player extends LivingEntity {
@@ -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
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(
+ 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(),
+ 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())
+ ));
@@ -189,7 +203,7 @@ index 0629c471d38a77c44fc1c86ccdfcb0690f61ca17..791e9f43afae265f7f32588db2d6f209
}
// 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 879c3bb661e24b9682b654def57c2800f4f8ca92..78c2067b9683611ea31cfe1c95755aa9e23e5982 100644
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 {
@@ -202,44 +216,33 @@ index 879c3bb661e24b9682b654def57c2800f4f8ca92..78c2067b9683611ea31cfe1c95755aa9
}
diff --git a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
index cdb8ec04f4a19ec3dbedbd5b17a7d1f3afaa238e..42b9f8d0b038a26fb3689bc0e974ceeed4de4254 100644
index c1583340ecaedab0af44501213b2d24f8ad71e0c..d6f2d56e15298ca9161f6b6e1384da0b07518616 100644
--- a/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
+++ b/src/main/java/org/bukkit/craftbukkit/event/CraftEventFactory.java
@@ -1945,4 +1945,53 @@ public class CraftEventFactory {
return event.callEvent();
@@ -2010,4 +2010,42 @@ public class CraftEventFactory {
return event;
}
// Paper end
// 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) {
+ // init variables
+ 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 = 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(net.minecraft.core.Holder.direct(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(net.minecraft.core.Holder.direct(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 {
+ return null; // ClientboundCustomSoundPacket was removed and the standard packet now supports custom sounds
+// // 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);
+ 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) {