package net.minecraft.client.tutorial;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.KeybindComponent;
import net.minecraft.network.chat.Component;
import net.minecraft.world.level.GameType;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.HitResult;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.player.Input;
import javax.annotation.Nullable;
import net.minecraft.client.Minecraft;

public class Tutorial {
    private final Minecraft minecraft;
    @Nullable
    private TutorialStepInstance instance;
    
    public Tutorial(final Minecraft dlx) {
        this.minecraft = dlx;
    }
    
    public void onInput(final Input ebd) {
        if (this.instance != null) {
            this.instance.onInput(ebd);
        }
    }
    
    public void onMouse(final double double1, final double double2) {
        if (this.instance != null) {
            this.instance.onMouse(double1, double2);
        }
    }
    
    public void onLookAt(@Nullable final ClientLevel dym, @Nullable final HitResult dej) {
        if (this.instance != null && dej != null && dym != null) {
            this.instance.onLookAt(dym, dej);
        }
    }
    
    public void onDestroyBlock(final ClientLevel dym, final BlockPos fu, final BlockState cfj, final float float4) {
        if (this.instance != null) {
            this.instance.onDestroyBlock(dym, fu, cfj, float4);
        }
    }
    
    public void onOpenInventory() {
        if (this.instance != null) {
            this.instance.onOpenInventory();
        }
    }
    
    public void onGetItem(final ItemStack bki) {
        if (this.instance != null) {
            this.instance.onGetItem(bki);
        }
    }
    
    public void stop() {
        if (this.instance == null) {
            return;
        }
        this.instance.clear();
        this.instance = null;
    }
    
    public void start() {
        if (this.instance != null) {
            this.stop();
        }
        this.instance = this.minecraft.options.tutorialStep.create(this);
    }
    
    public void tick() {
        if (this.instance != null) {
            if (this.minecraft.level != null) {
                this.instance.tick();
            }
            else {
                this.stop();
            }
        }
        else if (this.minecraft.level != null) {
            this.start();
        }
    }
    
    public void setStep(final TutorialSteps epz) {
        this.minecraft.options.tutorialStep = epz;
        this.minecraft.options.save();
        if (this.instance != null) {
            this.instance.clear();
            this.instance = epz.create(this);
        }
    }
    
    public Minecraft getMinecraft() {
        return this.minecraft;
    }
    
    public GameType getGameMode() {
        if (this.minecraft.gameMode == null) {
            return GameType.NOT_SET;
        }
        return this.minecraft.gameMode.getPlayerMode();
    }
    
    public static Component key(final String string) {
        return new KeybindComponent("key." + string).withStyle(ChatFormatting.BOLD);
    }
}
