Skip to content

Commit

Permalink
Change tooltip manager to allow adding tooltips on non-handled screens
Browse files Browse the repository at this point in the history
  • Loading branch information
Emirlol committed Jul 10, 2024
1 parent e5a04c4 commit d261bca
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor;
import de.hysky.skyblocker.skyblock.chocolatefactory.ChocolateFactorySolver;
import de.hysky.skyblocker.skyblock.item.tooltip.adders.*;
import de.hysky.skyblocker.skyblock.item.tooltip.adders.CraftPriceTooltip;
import de.hysky.skyblocker.utils.Utils;
import de.hysky.skyblocker.utils.container.TooltipAdder;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.slot.Slot;
Expand Down Expand Up @@ -50,14 +50,12 @@ public static void init() {
}
});
ScreenEvents.AFTER_INIT.register((client, screen, width, height) -> {
if (screen instanceof HandledScreen<?> handledScreen) {
onScreenChange(handledScreen);
}
onScreenChange(screen);
ScreenEvents.remove(screen).register(ignored -> currentScreenAdders.clear());
});
}

private static void onScreenChange(HandledScreen<?> screen) {
private static void onScreenChange(Screen screen) {
currentScreenAdders.clear();
for (TooltipAdder adder : adders) {
if (adder.isEnabled() && adder.test(screen)) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package de.hysky.skyblocker.utils.container;

import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.Screen;
import org.jetbrains.annotations.NotNull;

public interface ContainerMatcher {
/**
* Tests if the given screen should be handled by this matcher.
* @return {@code true} if this matcher should apply to the given screen, {@code false} otherwise
*/
boolean test(@NotNull HandledScreen<?> screen);
boolean test(@NotNull Screen screen);

/**
* @return {@code true} if this matcher is enabled, {@code false} otherwise
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.hysky.skyblocker.utils.container;

import de.hysky.skyblocker.skyblock.ChestValue;
import net.minecraft.client.gui.screen.ingame.HandledScreen;
import net.minecraft.client.gui.screen.Screen;
import org.intellij.lang.annotations.Language;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -26,7 +26,7 @@ public abstract class RegexContainerMatcher implements ContainerMatcher {
public String[] groups = null;

@Override
public boolean test(@NotNull HandledScreen<?> screen) {
public boolean test(@NotNull Screen screen) {
return test(screen.getTitle().getString());
}

Expand Down

0 comments on commit d261bca

Please sign in to comment.