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 dbn) {
        this.minecraft = dbn;
    }
    
    public void onInput(final Input dpz) {
        if (this.instance != null) {
            this.instance.onInput(dpz);
        }
    }
    
    public void onMouse(final double double1, final double double2) {
        if (this.instance != null) {
            this.instance.onMouse(double1, double2);
        }
    }
    
    public void onLookAt(@Nullable final ClientLevel dno, @Nullable final HitResult cvi) {
        if (this.instance != null && cvi != null && dno != null) {
            this.instance.onLookAt(dno, cvi);
        }
    }
    
    public void onDestroyBlock(final ClientLevel dno, final BlockPos fk, final BlockState byj, final float float4) {
        if (this.instance != null) {
            this.instance.onDestroyBlock(dno, fk, byj, float4);
        }
    }
    
    public void onOpenInventory() {
        if (this.instance != null) {
            this.instance.onOpenInventory();
        }
    }
    
    public void onGetItem(final ItemStack ben) {
        if (this.instance != null) {
            this.instance.onGetItem(ben);
        }
    }
    
    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 eel) {
        this.minecraft.options.tutorialStep = eel;
        this.minecraft.options.save();
        if (this.instance != null) {
            this.instance.clear();
            this.instance = eel.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);
    }
}
