| 1 | package net.minecraft.network.protocol.game;
|
| 2 |
|
| 3 | import net.minecraft.core.Holder;
|
| 4 | import net.minecraft.network.RegistryFriendlyByteBuf;
|
| 5 | import net.minecraft.network.codec.StreamCodec;
|
| 6 | import net.minecraft.network.protocol.Packet;
|
| 7 | import net.minecraft.network.protocol.PacketType;
|
| 8 | import net.minecraft.sounds.SoundEvent;
|
| 9 | import net.minecraft.sounds.SoundSource;
|
| 10 | import net.minecraft.world.entity.Entity;
|
| 11 |
|
| 12 | public class ClientboundSoundEntityPacket implements Packet<ClientGamePacketListener> {
|
| 13 | public static final StreamCodec<RegistryFriendlyByteBuf, ClientboundSoundEntityPacket> STREAM_CODEC = Packet.codec(
|
| 14 | ClientboundSoundEntityPacket::write, ClientboundSoundEntityPacket::new
|
| 15 | );
|
| 16 | private final Holder<SoundEvent> sound;
|
| 17 | private final SoundSource source;
|
| 18 | private final int id;
|
| 19 | private final float volume;
|
| 20 | private final float pitch;
|
| 21 | private final long seed;
|
| 22 |
|
| 23 | public ClientboundSoundEntityPacket(
|
| 24 | final Holder<SoundEvent> sound, final SoundSource source, final Entity sourceEntity, final float volume, final float pitch, final long seed
|
| 25 | ) {
|
| 26 | this.sound = sound;
|
| 27 | this.source = source;
|
| 28 | this.id = sourceEntity.getId();
|
| 29 | this.volume = volume;
|
| 30 | this.pitch = pitch;
|
| 31 | this.seed = seed;
|
| 32 | }
|
| 33 |
|
| 34 | private ClientboundSoundEntityPacket(final RegistryFriendlyByteBuf input) {
|
| 35 | this.sound = SoundEvent.STREAM_CODEC.decode(input);
|
| 36 | this.source = input.readEnum(SoundSource.class);
|
| 37 | this.id = input.readVarInt();
|
| 38 | this.volume = input.readFloat();
|
| 39 | this.pitch = input.readFloat();
|
| 40 | this.seed = input.readLong();
|
| 41 | }
|
| 42 |
|
| 43 | private void write(final RegistryFriendlyByteBuf output) {
|
| 44 | SoundEvent.STREAM_CODEC.encode(output, this.sound);
|
| 45 | output.writeEnum(this.source);
|
| 46 | output.writeVarInt(this.id);
|
| 47 | output.writeFloat(this.volume);
|
| 48 | output.writeFloat(this.pitch);
|
| 49 | output.writeLong(this.seed);
|
| 50 | }
|
| 51 |
|
| 52 | @Override
|
| 53 | public PacketType<ClientboundSoundEntityPacket> type() {
|
| 54 | return GamePacketTypes.CLIENTBOUND_SOUND_ENTITY;
|
| 55 | }
|
| 56 |
|
| 57 | public void handle(final ClientGamePacketListener listener) {
|
| 58 | listener.handleSoundEntityEvent(this);
|
| 59 | }
|
| 60 |
|
| 61 | public Holder<SoundEvent> getSound() {
|
| 62 | return this.sound;
|
| 63 | }
|
| 64 |
|
| 65 | public SoundSource getSource() {
|
| 66 | return this.source;
|
| 67 | }
|
| 68 |
|
| 69 | public int getId() {
|
| 70 | return this.id;
|
| 71 | }
|
| 72 |
|
| 73 | public float getVolume() {
|
| 74 | return this.volume;
|
| 75 | }
|
| 76 |
|
| 77 | public float getPitch() {
|
| 78 | return this.pitch;
|
| 79 | }
|
| 80 |
|
| 81 | public long getSeed() {
|
| 82 | return this.seed;
|
| 83 | }
|
| 84 | }
|
| 85 |
|