package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.phys.Vec3;
import net.minecraft.sounds.SoundSource;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.protocol.Packet;

public class ClientboundCustomSoundPacket implements Packet<ClientGamePacketListener> {
    private ResourceLocation name;
    private SoundSource source;
    private int x;
    private int y;
    private int z;
    private float volume;
    private float pitch;
    
    public ClientboundCustomSoundPacket() {
        this.y = Integer.MAX_VALUE;
    }
    
    public ClientboundCustomSoundPacket(final ResourceLocation sm, final SoundSource aaj, final Vec3 cvl, final float float4, final float float5) {
        this.y = Integer.MAX_VALUE;
        this.name = sm;
        this.source = aaj;
        this.x = (int)(cvl.x * 8.0);
        this.y = (int)(cvl.y * 8.0);
        this.z = (int)(cvl.z * 8.0);
        this.volume = float4;
        this.pitch = float5;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        this.name = kv.readResourceLocation();
        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.writeResourceLocation(this.name);
        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 ResourceLocation getName() {
        return this.name;
    }
    
    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.handleCustomSoundEvent(this);
    }
}
