package net.minecraft.world.entity.projectile;

import net.minecraft.world.entity.Entity;
import net.minecraft.network.syncher.SynchedEntityData;
import net.minecraft.network.syncher.EntityDataSerializers;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.ItemLike;
import net.minecraft.Util;
import net.minecraft.world.item.Items;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.level.Level;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.network.syncher.EntityDataAccessor;

public abstract class Fireball extends AbstractHurtingProjectile implements ItemSupplier {
    private static final EntityDataAccessor<ItemStack> DATA_ITEM_STACK;
    
    public Fireball(final EntityType<? extends Fireball> aoq, final Level bqb) {
        super(aoq, bqb);
    }
    
    public Fireball(final EntityType<? extends Fireball> aoq, final double double2, final double double3, final double double4, final double double5, final double double6, final double double7, final Level bqb) {
        super(aoq, double2, double3, double4, double5, double6, double7, bqb);
    }
    
    public Fireball(final EntityType<? extends Fireball> aoq, final LivingEntity aoy, final double double3, final double double4, final double double5, final Level bqb) {
        super(aoq, aoy, double3, double4, double5, bqb);
    }
    
    public void setItem(final ItemStack bki) {
        if (bki.getItem() != Items.FIRE_CHARGE || bki.hasTag()) {
            this.getEntityData().<ItemStack>set(Fireball.DATA_ITEM_STACK, (ItemStack)Util.<T>make((T)bki.copy(), bki -> bki.setCount(1)));
        }
    }
    
    protected ItemStack getItemRaw() {
        return this.getEntityData().<ItemStack>get(Fireball.DATA_ITEM_STACK);
    }
    
    @Override
    public ItemStack getItem() {
        final ItemStack bki2 = this.getItemRaw();
        return bki2.isEmpty() ? new ItemStack(Items.FIRE_CHARGE) : bki2;
    }
    
    @Override
    protected void defineSynchedData() {
        this.getEntityData().<ItemStack>define(Fireball.DATA_ITEM_STACK, ItemStack.EMPTY);
    }
    
    @Override
    public void addAdditionalSaveData(final CompoundTag le) {
        super.addAdditionalSaveData(le);
        final ItemStack bki3 = this.getItemRaw();
        if (!bki3.isEmpty()) {
            le.put("Item", bki3.save(new CompoundTag()));
        }
    }
    
    @Override
    public void readAdditionalSaveData(final CompoundTag le) {
        super.readAdditionalSaveData(le);
        final ItemStack bki3 = ItemStack.of(le.getCompound("Item"));
        this.setItem(bki3);
    }
    
    static {
        DATA_ITEM_STACK = SynchedEntityData.<ItemStack>defineId(Fireball.class, EntityDataSerializers.ITEM_STACK);
    }
}
