package net.minecraft.client.tutorial;

import net.minecraft.network.chat.TranslatableComponent;
import com.google.common.collect.Sets;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.minecraft.client.multiplayer.ClientLevel;
import java.util.Iterator;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.gui.components.toasts.Toast;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.GameType;
import net.minecraft.client.gui.components.toasts.TutorialToast;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.block.Block;
import java.util.Set;

public class FindTreeTutorialStepInstance implements TutorialStepInstance {
    private static final Set<Block> TREE_BLOCKS;
    private static final Component TITLE;
    private static final Component DESCRIPTION;
    private final Tutorial tutorial;
    private TutorialToast toast;
    private int timeWaiting;
    
    public FindTreeTutorialStepInstance(final Tutorial eej) {
        this.tutorial = eej;
    }
    
    @Override
    public void tick() {
        ++this.timeWaiting;
        if (this.tutorial.getGameMode() != GameType.SURVIVAL) {
            this.tutorial.setStep(TutorialSteps.NONE);
            return;
        }
        if (this.timeWaiting == 1) {
            final LocalPlayer dqb2 = this.tutorial.getMinecraft().player;
            if (dqb2 != null) {
                for (final Block bph4 : FindTreeTutorialStepInstance.TREE_BLOCKS) {
                    if (dqb2.inventory.contains(new ItemStack(bph4))) {
                        this.tutorial.setStep(TutorialSteps.CRAFT_PLANKS);
                        return;
                    }
                }
                if (hasPunchedTreesPreviously(dqb2)) {
                    this.tutorial.setStep(TutorialSteps.CRAFT_PLANKS);
                    return;
                }
            }
        }
        if (this.timeWaiting >= 6000 && this.toast == null) {
            this.toast = new TutorialToast(TutorialToast.Icons.TREE, FindTreeTutorialStepInstance.TITLE, FindTreeTutorialStepInstance.DESCRIPTION, false);
            this.tutorial.getMinecraft().getToasts().addToast(this.toast);
        }
    }
    
    @Override
    public void clear() {
        if (this.toast != null) {
            this.toast.hide();
            this.toast = null;
        }
    }
    
    @Override
    public void onLookAt(final ClientLevel dno, final HitResult cvi) {
        if (cvi.getType() == HitResult.Type.BLOCK) {
            final BlockState byj4 = dno.getBlockState(((BlockHitResult)cvi).getBlockPos());
            if (FindTreeTutorialStepInstance.TREE_BLOCKS.contains(byj4.getBlock())) {
                this.tutorial.setStep(TutorialSteps.PUNCH_TREE);
            }
        }
    }
    
    @Override
    public void onGetItem(final ItemStack ben) {
        for (final Block bph4 : FindTreeTutorialStepInstance.TREE_BLOCKS) {
            if (ben.getItem() == bph4.asItem()) {
                this.tutorial.setStep(TutorialSteps.CRAFT_PLANKS);
            }
        }
    }
    
    public static boolean hasPunchedTreesPreviously(final LocalPlayer dqb) {
        for (final Block bph3 : FindTreeTutorialStepInstance.TREE_BLOCKS) {
            if (dqb.getStats().getValue(Stats.BLOCK_MINED.get(bph3)) > 0) {
                return true;
            }
        }
        return false;
    }
    
    static {
        TREE_BLOCKS = Sets.<Block>newHashSet(Blocks.OAK_LOG, Blocks.SPRUCE_LOG, Blocks.BIRCH_LOG, Blocks.JUNGLE_LOG, Blocks.ACACIA_LOG, Blocks.DARK_OAK_LOG, Blocks.OAK_WOOD, Blocks.SPRUCE_WOOD, Blocks.BIRCH_WOOD, Blocks.JUNGLE_WOOD, Blocks.ACACIA_WOOD, Blocks.DARK_OAK_WOOD, Blocks.OAK_LEAVES, Blocks.SPRUCE_LEAVES, Blocks.BIRCH_LEAVES, Blocks.JUNGLE_LEAVES, Blocks.ACACIA_LEAVES, Blocks.DARK_OAK_LEAVES);
        TITLE = new TranslatableComponent("tutorial.find_tree.title", new Object[0]);
        DESCRIPTION = new TranslatableComponent("tutorial.find_tree.description", new Object[0]);
    }
}
