From e5713e4e03831c0558f6f4c5440e03441a8d2f0c Mon Sep 17 00:00:00 2001 From: RacoonDog <32882447+RacoonDog@users.noreply.github.com> Date: Sun, 22 Oct 2023 05:07:10 -0400 Subject: [PATCH] Echest memory patch (#4153) --- .../modules/render/BetterTooltips.java | 3 ++- .../utils/player/EChestMemory.java | 13 ++++++++++ .../utils/tooltip/TextTooltipComponent.java | 26 +++++++++++++++++++ 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 src/main/java/meteordevelopment/meteorclient/utils/tooltip/TextTooltipComponent.java diff --git a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java index cbf85e39ad..4158e0646e 100644 --- a/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java +++ b/src/main/java/meteordevelopment/meteorclient/systems/modules/render/BetterTooltips.java @@ -325,7 +325,8 @@ private void getTooltipData(TooltipDataEvent event) { // EChest preview else if (event.itemStack.getItem() == Items.ENDER_CHEST && previewEChest()) { - event.tooltipData = new ContainerTooltipComponent(EChestMemory.ITEMS, ECHEST_COLOR); + event.tooltipData = EChestMemory.isKnown() ? new ContainerTooltipComponent(EChestMemory.ITEMS, ECHEST_COLOR) + : new TextTooltipComponent(Text.literal("Unknown ender chest inventory.").formatted(Formatting.DARK_RED)); } // Map preview diff --git a/src/main/java/meteordevelopment/meteorclient/utils/player/EChestMemory.java b/src/main/java/meteordevelopment/meteorclient/utils/player/EChestMemory.java index 20797b548f..f806c712fb 100644 --- a/src/main/java/meteordevelopment/meteorclient/utils/player/EChestMemory.java +++ b/src/main/java/meteordevelopment/meteorclient/utils/player/EChestMemory.java @@ -6,6 +6,7 @@ package meteordevelopment.meteorclient.utils.player; import meteordevelopment.meteorclient.MeteorClient; +import meteordevelopment.meteorclient.events.game.GameLeftEvent; import meteordevelopment.meteorclient.events.game.OpenScreenEvent; import meteordevelopment.meteorclient.events.world.BlockActivateEvent; import meteordevelopment.meteorclient.utils.PreInit; @@ -22,6 +23,7 @@ public class EChestMemory { public static final DefaultedList ITEMS = DefaultedList.ofSize(27, ItemStack.EMPTY); private static int echestOpenedState; + private static boolean isKnown = false; @PreInit public static void init() { @@ -49,7 +51,18 @@ private static void onOpenScreenEvent(OpenScreenEvent event) { for (int i = 0; i < 27; i++) { ITEMS.set(i, inv.getStack(i)); } + isKnown = true; echestOpenedState = 0; } + + @EventHandler + private static void onLeaveEvent(GameLeftEvent event) { + ITEMS.clear(); + isKnown = false; + } + + public static boolean isKnown() { + return isKnown; + } } diff --git a/src/main/java/meteordevelopment/meteorclient/utils/tooltip/TextTooltipComponent.java b/src/main/java/meteordevelopment/meteorclient/utils/tooltip/TextTooltipComponent.java new file mode 100644 index 0000000000..8693e3ed2d --- /dev/null +++ b/src/main/java/meteordevelopment/meteorclient/utils/tooltip/TextTooltipComponent.java @@ -0,0 +1,26 @@ +/* + * This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client). + * Copyright (c) Meteor Development. + */ + +package meteordevelopment.meteorclient.utils.tooltip; + +import net.minecraft.client.gui.tooltip.OrderedTextTooltipComponent; +import net.minecraft.client.gui.tooltip.TooltipComponent; +import net.minecraft.text.OrderedText; +import net.minecraft.text.Text; + +public class TextTooltipComponent extends OrderedTextTooltipComponent implements MeteorTooltipData { + public TextTooltipComponent(OrderedText text) { + super(text); + } + + public TextTooltipComponent(Text text) { + this(text.asOrderedText()); + } + + @Override + public TooltipComponent getComponent() { + return this; + } +}