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.sounds.SoundSource;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.network.protocol.Packet;

public class ClientboundSoundPacket implements Packet<ClientGamePacketListener> {
    private SoundEvent sound;
    private SoundSource source;
    private int x;
    private int y;
    private int z;
    private float volume;
    private float pitch;
    
    public ClientboundSoundPacket() {
    }
    
    public ClientboundSoundPacket(final SoundEvent aah, final SoundSource aaj, final double double3, final double double4, final double double5, final float float6, final float float7) {
        Validate.notNull(aah, "sound", new Object[0]);
        this.sound = aah;
        this.source = aaj;
        this.x = (int)(double3 * 8.0);
        this.y = (int)(double4 * 8.0);
        this.z = (int)(double5 * 8.0);
        this.volume = float6;
        this.pitch = float7;
    }
    
    @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.x = kv.readInt();
        this.y = kv.readInt();
        this.z = kv.readInt();
        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.writeInt(this.x);
        kv.writeInt(this.y);
        kv.writeInt(this.z);
        kv.writeFloat(this.volume);
        kv.writeFloat(this.pitch);
    }
    
    public SoundEvent getSound() {
        return this.sound;
    }
    
    public SoundSource getSource() {
        return this.source;
    }
    
    public double getX() {
        return this.x / 8.0f;
    }
    
    public double getY() {
        return this.y / 8.0f;
    }
    
    public double getZ() {
        return this.z / 8.0f;
    }
    
    public float getVolume() {
        return this.volume;
    }
    
    public float getPitch() {
        return this.pitch;
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleSoundEvent(this);
    }
}
