| 1 | package net.minecraft.client.tutorial;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.ChatFormatting;
|
| 6 | import net.minecraft.client.Minecraft;
|
| 7 | import net.minecraft.client.Options;
|
| 8 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 9 | import net.minecraft.client.player.ClientInput;
|
| 10 | import net.minecraft.core.BlockPos;
|
| 11 | import net.minecraft.network.chat.Component;
|
| 12 | import net.minecraft.world.inventory.ClickAction;
|
| 13 | import net.minecraft.world.item.ItemStack;
|
| 14 | import net.minecraft.world.level.GameType;
|
| 15 | import net.minecraft.world.level.block.state.BlockState;
|
| 16 | import net.minecraft.world.phys.HitResult;
|
| 17 | import org.jspecify.annotations.Nullable;
|
| 18 |
|
| 19 | @Environment(EnvType.CLIENT)
|
| 20 | public class Tutorial {
|
| 21 | private final Minecraft minecraft;
|
| 22 | private @Nullable TutorialStepInstance instance;
|
| 23 |
|
| 24 | public Tutorial(final Minecraft minecraft, final Options options) {
|
| 25 | this.minecraft = minecraft;
|
| 26 | }
|
| 27 |
|
| 28 | public void onInput(final ClientInput input) {
|
| 29 | if (this.instance != null) {
|
| 30 | this.instance.onInput(input);
|
| 31 | }
|
| 32 | }
|
| 33 |
|
| 34 | public void onMouse(final double xd, final double yd) {
|
| 35 | if (this.instance != null) {
|
| 36 | this.instance.onMouse(xd, yd);
|
| 37 | }
|
| 38 | }
|
| 39 |
|
| 40 | public void onLookAt(final @Nullable ClientLevel level, final @Nullable HitResult hit) {
|
| 41 | if (this.instance != null && hit != null && level != null) {
|
| 42 | this.instance.onLookAt(level, hit);
|
| 43 | }
|
| 44 | }
|
| 45 |
|
| 46 | public void onDestroyBlock(final ClientLevel level, final BlockPos pos, final BlockState state, final float percent) {
|
| 47 | if (this.instance != null) {
|
| 48 | this.instance.onDestroyBlock(level, pos, state, percent);
|
| 49 | }
|
| 50 | }
|
| 51 |
|
| 52 | public void onOpenInventory() {
|
| 53 | if (this.instance != null) {
|
| 54 | this.instance.onOpenInventory();
|
| 55 | }
|
| 56 | }
|
| 57 |
|
| 58 | public void onGetItem(final ItemStack itemStack) {
|
| 59 | if (this.instance != null) {
|
| 60 | this.instance.onGetItem(itemStack);
|
| 61 | }
|
| 62 | }
|
| 63 |
|
| 64 | public void stop() {
|
| 65 | if (this.instance != null) {
|
| 66 | this.instance.clear();
|
| 67 | this.instance = null;
|
| 68 | }
|
| 69 | }
|
| 70 |
|
| 71 | public void start() {
|
| 72 | if (this.instance != null) {
|
| 73 | this.stop();
|
| 74 | }
|
| 75 |
|
| 76 | this.instance = this.minecraft.options.tutorialStep.create(this);
|
| 77 | }
|
| 78 |
|
| 79 | public void tick() {
|
| 80 | if (this.instance != null) {
|
| 81 | if (this.minecraft.level != null) {
|
| 82 | this.instance.tick();
|
| 83 | } else {
|
| 84 | this.stop();
|
| 85 | }
|
| 86 | } else if (this.minecraft.level != null) {
|
| 87 | this.start();
|
| 88 | }
|
| 89 | }
|
| 90 |
|
| 91 | public void setStep(final TutorialSteps step) {
|
| 92 | this.minecraft.options.tutorialStep = step;
|
| 93 | this.minecraft.options.save();
|
| 94 | if (this.instance != null) {
|
| 95 | this.instance.clear();
|
| 96 | this.instance = step.create(this);
|
| 97 | }
|
| 98 | }
|
| 99 |
|
| 100 | public Minecraft getMinecraft() {
|
| 101 | return this.minecraft;
|
| 102 | }
|
| 103 |
|
| 104 | public boolean isSurvival() {
|
| 105 | return this.minecraft.gameMode == null ? false : this.minecraft.gameMode.getPlayerMode() == GameType.SURVIVAL;
|
| 106 | }
|
| 107 |
|
| 108 | public static Component key(final String name) {
|
| 109 | return Component.keybind("key." + name).withStyle(ChatFormatting.BOLD);
|
| 110 | }
|
| 111 |
|
| 112 | public void onInventoryAction(final ItemStack itemCarried, final ItemStack itemInSlot, final ClickAction clickAction) {
|
| 113 | }
|
| 114 | }
|
| 115 |
|