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 ack, final SoundSource acm, final double double3, final double double4, final double double5, final float float6, final float float7) {
        Validate.notNull(ack, "sound", new Object[0]);
        this.sound = ack;
        this.source = acm;
        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 mg) throws IOException {
        this.sound = Registry.SOUND_EVENT.byId(mg.readVarInt());
        this.source = mg.<SoundSource>readEnum(SoundSource.class);
        this.x = mg.readInt();
        this.y = mg.readInt();
        this.z = mg.readInt();
        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.writeInt(this.x);
        mg.writeInt(this.y);
        mg.writeInt(this.z);
        mg.writeFloat(this.volume);
        mg.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 nl) {
        nl.handleSoundEvent(this);
    }
}
