| 1 | package net.minecraft.client.tutorial;
|
| 2 |
|
| 3 | import net.fabricmc.api.EnvType;
|
| 4 | import net.fabricmc.api.Environment;
|
| 5 | import net.minecraft.client.Minecraft;
|
| 6 | import net.minecraft.client.gui.components.toasts.TutorialToast;
|
| 7 | import net.minecraft.client.multiplayer.ClientLevel;
|
| 8 | import net.minecraft.client.player.LocalPlayer;
|
| 9 | import net.minecraft.core.BlockPos;
|
| 10 | import net.minecraft.network.chat.Component;
|
| 11 | import net.minecraft.tags.BlockTags;
|
| 12 | import net.minecraft.tags.ItemTags;
|
| 13 | import net.minecraft.world.item.ItemStack;
|
| 14 | import net.minecraft.world.level.block.state.BlockState;
|
| 15 | import org.jspecify.annotations.Nullable;
|
| 16 |
|
| 17 | @Environment(EnvType.CLIENT)
|
| 18 | public class PunchTreeTutorialStepInstance implements TutorialStepInstance {
|
| 19 | private static final int HINT_DELAY = 600;
|
| 20 | private static final Component TITLE = Component.translatable("tutorial.punch_tree.title");
|
| 21 | private static final Component DESCRIPTION = Component.translatable("tutorial.punch_tree.description", Tutorial.key("attack"));
|
| 22 | private final Tutorial tutorial;
|
| 23 | private @Nullable TutorialToast toast;
|
| 24 | private int timeWaiting;
|
| 25 | private int resetCount;
|
| 26 |
|
| 27 | public PunchTreeTutorialStepInstance(final Tutorial tutorial) {
|
| 28 | this.tutorial = tutorial;
|
| 29 | }
|
| 30 |
|
| 31 | @Override
|
| 32 | public void tick() {
|
| 33 | this.timeWaiting++;
|
| 34 | if (!this.tutorial.isSurvival()) {
|
| 35 | this.tutorial.setStep(TutorialSteps.NONE);
|
| 36 | } else {
|
| 37 | Minecraft minecraft = this.tutorial.getMinecraft();
|
| 38 | if (this.timeWaiting == 1) {
|
| 39 | LocalPlayer player = minecraft.player;
|
| 40 | if (player != null) {
|
| 41 | if (player.getInventory().contains(ItemTags.LOGS)) {
|
| 42 | this.tutorial.setStep(TutorialSteps.CRAFT_PLANKS);
|
| 43 | return;
|
| 44 | }
|
| 45 |
|
| 46 | if (FindTreeTutorialStepInstance.hasPunchedTreesPreviously(player)) {
|
| 47 | this.tutorial.setStep(TutorialSteps.CRAFT_PLANKS);
|
| 48 | return;
|
| 49 | }
|
| 50 | }
|
| 51 | }
|
| 52 |
|
| 53 | if ((this.timeWaiting >= 600 || this.resetCount > 3) && this.toast == null) {
|
| 54 | this.toast = new TutorialToast(minecraft.font, TutorialToast.Icons.TREE, TITLE, DESCRIPTION, true);
|
| 55 | minecraft.gui.toastManager().addToast(this.toast);
|
| 56 | }
|
| 57 | }
|
| 58 | }
|
| 59 |
|
| 60 | @Override
|
| 61 | public void clear() {
|
| 62 | if (this.toast != null) {
|
| 63 | this.toast.hide();
|
| 64 | this.toast = null;
|
| 65 | }
|
| 66 | }
|
| 67 |
|
| 68 | @Override
|
| 69 | public void onDestroyBlock(final ClientLevel level, final BlockPos pos, final BlockState state, final float percent) {
|
| 70 | boolean isLogBlock = state.is(BlockTags.LOGS);
|
| 71 | if (isLogBlock && percent > 0.0F) {
|
| 72 | if (this.toast != null) {
|
| 73 | this.toast.updateProgress(percent);
|
| 74 | }
|
| 75 |
|
| 76 | if (percent >= 1.0F) {
|
| 77 | this.tutorial.setStep(TutorialSteps.OPEN_INVENTORY);
|
| 78 | }
|
| 79 | } else if (this.toast != null) {
|
| 80 | this.toast.updateProgress(0.0F);
|
| 81 | } else if (isLogBlock) {
|
| 82 | this.resetCount++;
|
| 83 | }
|
| 84 | }
|
| 85 |
|
| 86 | @Override
|
| 87 | public void onGetItem(final ItemStack itemStack) {
|
| 88 | if (itemStack.is(ItemTags.LOGS)) {
|
| 89 | this.tutorial.setStep(TutorialSteps.CRAFT_PLANKS);
|
| 90 | }
|
| 91 | }
|
| 92 | }
|
| 93 |
|