package net.minecraft.network.protocol.game;

import net.minecraft.network.PacketListener;
import java.io.IOException;
import net.minecraft.network.FriendlyByteBuf;
import javax.annotation.Nullable;
import net.minecraft.sounds.SoundSource;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.network.protocol.Packet;

public class ClientboundStopSoundPacket implements Packet<ClientGamePacketListener> {
    private ResourceLocation name;
    private SoundSource source;
    
    public ClientboundStopSoundPacket() {
    }
    
    public ClientboundStopSoundPacket(@Nullable final ResourceLocation sm, @Nullable final SoundSource aaj) {
        this.name = sm;
        this.source = aaj;
    }
    
    @Override
    public void read(final FriendlyByteBuf kv) throws IOException {
        final int integer3 = kv.readByte();
        if ((integer3 & 0x1) > 0) {
            this.source = kv.<SoundSource>readEnum(SoundSource.class);
        }
        if ((integer3 & 0x2) > 0) {
            this.name = kv.readResourceLocation();
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf kv) throws IOException {
        if (this.source != null) {
            if (this.name != null) {
                kv.writeByte(3);
                kv.writeEnum(this.source);
                kv.writeResourceLocation(this.name);
            }
            else {
                kv.writeByte(1);
                kv.writeEnum(this.source);
            }
        }
        else if (this.name != null) {
            kv.writeByte(2);
            kv.writeResourceLocation(this.name);
        }
        else {
            kv.writeByte(0);
        }
    }
    
    @Nullable
    public ResourceLocation getName() {
        return this.name;
    }
    
    @Nullable
    public SoundSource getSource() {
        return this.source;
    }
    
    @Override
    public void handle(final ClientGamePacketListener lw) {
        lw.handleStopSoundEvent(this);
    }
}
