Skip to content

Commit

Permalink
Echest memory patch (#4153)
Browse files Browse the repository at this point in the history
  • Loading branch information
RacoonDog authored Oct 22, 2023
1 parent f30f2b3 commit e5713e4
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
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;
}
}

0 comments on commit e5713e4

Please sign in to comment.