package net.minecraft.world.entity.ai.behavior;

import java.util.AbstractList;
import java.util.List;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.nbt.ListTag;
import net.minecraft.world.item.FireworkRocketItem;
import com.google.common.collect.Lists;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.ItemStack;
import java.util.Random;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.projectile.FireworkRocketEntity;
import net.minecraft.Util;
import net.minecraft.world.item.DyeColor;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.server.level.ServerLevel;
import java.util.Map;
import com.google.common.collect.ImmutableMap;
import javax.annotation.Nullable;
import net.minecraft.world.entity.raid.Raid;
import net.minecraft.world.entity.npc.Villager;

public class CelebrateVillagersSurvivedRaid extends Behavior<Villager> {
    @Nullable
    private Raid currentRaid;
    
    public CelebrateVillagersSurvivedRaid(final int integer1, final int integer2) {
        super(ImmutableMap.of(), integer1, integer2);
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel zd, final Villager bdp) {
        final BlockPos fu4 = bdp.blockPosition();
        this.currentRaid = zd.getRaidAt(fu4);
        return this.currentRaid != null && this.currentRaid.isVictory() && MoveToSkySeeingSpot.hasNoBlocksAbove(zd, bdp, fu4);
    }
    
    @Override
    protected boolean canStillUse(final ServerLevel zd, final Villager bdp, final long long3) {
        return this.currentRaid != null && !this.currentRaid.isStopped();
    }
    
    @Override
    protected void stop(final ServerLevel zd, final Villager bdp, final long long3) {
        this.currentRaid = null;
        bdp.getBrain().updateActivityFromSchedule(zd.getDayTime(), zd.getGameTime());
    }
    
    @Override
    protected void stop(final ServerLevel zd, final Villager bdp, final long long3) {
        final Random random6 = bdp.getRandom();
        if (random6.nextInt(100) == 0) {
            bdp.playCelebrateSound();
        }
        if (random6.nextInt(200) == 0 && MoveToSkySeeingSpot.hasNoBlocksAbove(zd, bdp, bdp.blockPosition())) {
            final DyeColor bje7 = Util.<DyeColor>getRandom(DyeColor.values(), random6);
            final int integer8 = random6.nextInt(3);
            final ItemStack bki9 = this.getFirework(bje7, integer8);
            final FireworkRocketEntity ben10 = new FireworkRocketEntity(bdp.level, bdp, bdp.getX(), bdp.getEyeY(), bdp.getZ(), bki9);
            bdp.level.addFreshEntity(ben10);
        }
    }
    
    private ItemStack getFirework(final DyeColor bje, final int integer) {
        final ItemStack bki4 = new ItemStack(Items.FIREWORK_ROCKET, 1);
        final ItemStack bki5 = new ItemStack(Items.FIREWORK_STAR);
        final CompoundTag le6 = bki5.getOrCreateTagElement("Explosion");
        final List<Integer> list7 = Lists.newArrayList();
        list7.add(bje.getFireworkColor());
        le6.putIntArray("Colors", list7);
        le6.putByte("Type", (byte)FireworkRocketItem.Shape.BURST.getId());
        final CompoundTag le7 = bki4.getOrCreateTagElement("Fireworks");
        final ListTag lk9 = new ListTag();
        final CompoundTag le8 = bki5.getTagElement("Explosion");
        if (le8 != null) {
            ((AbstractList<CompoundTag>)lk9).add(le8);
        }
        le7.putByte("Flight", (byte)integer);
        if (!lk9.isEmpty()) {
            le7.put("Explosions", lk9);
        }
        return bki4;
    }
}
