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.projectile.FireworkRocketEntity;
import net.minecraft.world.item.DyeColor;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Entity;
import net.minecraft.core.BlockPos;
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 Celebrate extends Behavior<Villager> {
    @Nullable
    private Raid currentRaid;
    
    public Celebrate(final int integer1, final int integer2) {
        super(ImmutableMap.of(), integer1, integer2);
    }
    
    @Override
    protected boolean checkExtraStartConditions(final ServerLevel xd, final Villager axw) {
        final BlockPos fk4 = new BlockPos(axw);
        this.currentRaid = xd.getRaidAt(fk4);
        return this.currentRaid != null && this.currentRaid.isVictory() && MoveToSkySeeingSpot.hasNoBlocksAbove(xd, axw, fk4);
    }
    
    @Override
    protected boolean canStillUse(final ServerLevel xd, final Villager axw, final long long3) {
        return this.currentRaid != null && !this.currentRaid.isStopped();
    }
    
    @Override
    protected void stop(final ServerLevel xd, final Villager axw, final long long3) {
        this.currentRaid = null;
        axw.getBrain().updateActivity(xd.getDayTime(), xd.getGameTime());
    }
    
    @Override
    protected void tick(final ServerLevel xd, final Villager axw, final long long3) {
        final Random random6 = axw.getRandom();
        if (random6.nextInt(100) == 0) {
            axw.playCelebrateSound();
        }
        if (random6.nextInt(200) == 0 && MoveToSkySeeingSpot.hasNoBlocksAbove(xd, axw, new BlockPos(axw))) {
            final DyeColor bdj7 = DyeColor.values()[random6.nextInt(DyeColor.values().length)];
            final int integer8 = random6.nextInt(3);
            final ItemStack ben9 = this.getFirework(bdj7, integer8);
            final FireworkRocketEntity ayu10 = new FireworkRocketEntity(axw.level, axw.getX(), axw.getEyeY(), axw.getZ(), ben9);
            axw.level.addFreshEntity(ayu10);
        }
    }
    
    private ItemStack getFirework(final DyeColor bdj, final int integer) {
        final ItemStack ben4 = new ItemStack(Items.FIREWORK_ROCKET, 1);
        final ItemStack ben5 = new ItemStack(Items.FIREWORK_STAR);
        final CompoundTag jt6 = ben5.getOrCreateTagElement("Explosion");
        final List<Integer> list7 = Lists.newArrayList();
        list7.add(bdj.getFireworkColor());
        jt6.putIntArray("Colors", list7);
        jt6.putByte("Type", (byte)FireworkRocketItem.Shape.BURST.getId());
        final CompoundTag jt7 = ben4.getOrCreateTagElement("Fireworks");
        final ListTag jz9 = new ListTag();
        final CompoundTag jt8 = ben5.getTagElement("Explosion");
        if (jt8 != null) {
            ((AbstractList<CompoundTag>)jz9).add(jt8);
        }
        jt7.putByte("Flight", (byte)integer);
        if (!jz9.isEmpty()) {
            jt7.put("Explosions", jz9);
        }
        return ben4;
    }
}
