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 uh, final SoundSource acm, final Vec3 dem, final float float4, final float float5) {
        this.y = Integer.MAX_VALUE;
        this.name = uh;
        this.source = acm;
        this.x = (int)(dem.x * 8.0);
        this.y = (int)(dem.y * 8.0);
        this.z = (int)(dem.z * 8.0);
        this.volume = float4;
        this.pitch = float5;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        this.name = mg.readResourceLocation();
        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.writeResourceLocation(this.name);
        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 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 nl) {
        nl.handleCustomSoundEvent(this);
    }
}
