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

import net.minecraft.nbt.Tag;
import net.minecraft.nbt.CompoundTag;
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 CompoundTag jt) {
        super.load(jt);
        if (jt.contains("RecordItem", 10)) {
            this.setRecord(ItemStack.of(jt.getCompound("RecordItem")));
        }
    }
    
    @Override
    public CompoundTag save(final CompoundTag jt) {
        super.save(jt);
        if (!this.getRecord().isEmpty()) {
            jt.put("RecordItem", this.getRecord().save(new CompoundTag()));
        }
        return jt;
    }
    
    public ItemStack getRecord() {
        return this.record;
    }
    
    public void setRecord(final ItemStack ben) {
        this.record = ben;
        this.setChanged();
    }
    
    @Override
    public void clearContent() {
        this.setRecord(ItemStack.EMPTY);
    }
}
