package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.core.Registry;
import net.minecraft.network.FriendlyByteBuf;
import org.apache.commons.lang3.Validate;
import net.minecraft.world.entity.Entity;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.network.protocol.Packet;

public class ClientboundSoundEntityPacket implements Packet<ClientGamePacketListener> {
    private SoundEvent sound;
    private SoundSource source;
    private int id;
    private float volume;
    private float pitch;
    
    public ClientboundSoundEntityPacket() {
    }
    
    public ClientboundSoundEntityPacket(final SoundEvent aah, final SoundSource aaj, final Entity akq, final float float4, final float float5) {
        Validate.notNull(aah, "sound", new Object[0]);
        this.sound = aah;
        this.source = aaj;
        this.id = akq.getId();
        this.volume = float4;
        this.pitch = float5;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.sound = Registry.SOUND_EVENT.byId(kv.readVarInt());
        this.source = kv.<SoundSource>readEnum(SoundSource.class);
        this.id = kv.readVarInt();
        this.volume = kv.readFloat();
        this.pitch = kv.readFloat();
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        kv.writeVarInt(Registry.SOUND_EVENT.getId(this.sound));
        kv.writeEnum(this.source);
        kv.writeVarInt(this.id);
        kv.writeFloat(this.volume);
        kv.writeFloat(this.pitch);
    }
    
    public SoundEvent getSound() {
        return this.sound;
    }
    
    public SoundSource getSource() {
        return this.source;
    }
    
    public int getId() {
        return this.id;
    }
    
    public float getVolume() {
        return this.volume;
    }
    
    public float getPitch() {
        return this.pitch;
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleSoundEntityEvent(this);
    }
}
