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 uh, @Nullable final SoundSource acm) {
        this.name = uh;
        this.source = acm;
    }
    
    @Override
    public void read(final FriendlyByteBuf mg) throws IOException {
        final int integer3 = mg.readByte();
        if ((integer3 & 0x1) > 0) {
            this.source = mg.<SoundSource>readEnum(SoundSource.class);
        }
        if ((integer3 & 0x2) > 0) {
            this.name = mg.readResourceLocation();
        }
    }
    
    @Override
    public void write(final FriendlyByteBuf mg) throws IOException {
        if (this.source != null) {
            if (this.name != null) {
                mg.writeByte(3);
                mg.writeEnum(this.source);
                mg.writeResourceLocation(this.name);
            }
            else {
                mg.writeByte(1);
                mg.writeEnum(this.source);
            }
        }
        else if (this.name != null) {
            mg.writeByte(2);
            mg.writeResourceLocation(this.name);
        }
        else {
            mg.writeByte(0);
        }
    }
    
    @Nullable
    public ResourceLocation getName() {
        return this.name;
    }
    
    @Nullable
    public SoundSource getSource() {
        return this.source;
    }
    
    @Override
    public void handle(final ClientGamePacketListener nl) {
        nl.handleStopSoundEvent(this);
    }
}
