Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Echest memory patch #4153

Merged
merged 5 commits into from
Oct 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,6 +23,7 @@
public class EChestMemory {
public static final DefaultedList<ItemStack> ITEMS = DefaultedList.ofSize(27, ItemStack.EMPTY);
private static int echestOpenedState;
private static boolean isKnown = false;

@PreInit
public static void init() {
Expand Down Expand Up @@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}