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 ack, final SoundSource acm, final Entity aom, final float float4, final float float5) {
        Validate.notNull(ack, "sound", new Object[0]);
        this.sound = ack;
        this.source = acm;
        this.id = aom.getId();
        this.volume = float4;
        this.pitch = float5;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.sound = Registry.SOUND_EVENT.byId(mg.readVarInt());
        this.source = mg.<SoundSource>readEnum(SoundSource.class);
        this.id = mg.readVarInt();
        this.volume = mg.readFloat();
        this.pitch = mg.readFloat();
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        mg.writeVarInt(Registry.SOUND_EVENT.getId(this.sound));
        mg.writeEnum(this.source);
        mg.writeVarInt(this.id);
        mg.writeFloat(this.volume);
        mg.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 nl) {
        nl.handleSoundEntityEvent(this);
    }
}
