package net.minecraft.world.level.block.entity;

import net.minecraft.nbt.Tag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.Clearable;

public class JukeboxBlockEntity extends BlockEntity implements Clearable {
    private ItemStack record;
    
    public JukeboxBlockEntity() {
        super(BlockEntityType.JUKEBOX);
        this.record = ItemStack.EMPTY;
    }
    
    @Override
    public void load(final BlockState cfj, final CompoundTag le) {
        super.load(cfj, le);
        if (le.contains("RecordItem", 10)) {
            this.setRecord(ItemStack.of(le.getCompound("RecordItem")));
        }
    }
    
    @Override
    public CompoundTag save(final CompoundTag le) {
        super.save(le);
        if (!this.getRecord().isEmpty()) {
            le.put("RecordItem", this.getRecord().save(new CompoundTag()));
        }
        return le;
    }
    
    public ItemStack getRecord() {
        return this.record;
    }
    
    public void setRecord(final ItemStack bki) {
        this.record = bki;
        this.setChanged();
    }
    
    @Override
    public void clearContent() {
        this.setRecord(ItemStack.EMPTY);
    }
}
