diff --git a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java index 08b0915a57..58b1b48df5 100644 --- a/src/main/java/de/hysky/skyblocker/SkyblockerMod.java +++ b/src/main/java/de/hysky/skyblocker/SkyblockerMod.java @@ -54,7 +54,7 @@ import de.hysky.skyblocker.utils.discord.DiscordRPCManager; import de.hysky.skyblocker.utils.render.RenderHelper; import de.hysky.skyblocker.utils.render.culling.OcclusionCulling; -import de.hysky.skyblocker.utils.render.gui.ContainerSolverManager; +import de.hysky.skyblocker.utils.container.ContainerSolverManager; import de.hysky.skyblocker.utils.render.title.TitleContainer; import de.hysky.skyblocker.utils.scheduler.MessageScheduler; import de.hysky.skyblocker.utils.scheduler.Scheduler; diff --git a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java index ab674b185b..7669359eb6 100644 --- a/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java +++ b/src/main/java/de/hysky/skyblocker/config/categories/GeneralCategory.java @@ -5,10 +5,12 @@ import de.hysky.skyblocker.config.SkyblockerConfig; import de.hysky.skyblocker.config.configs.GeneralConfig; import de.hysky.skyblocker.skyblock.item.tooltip.adders.CraftPriceTooltip; +import de.hysky.skyblocker.skyblock.item.slottext.SlotTextMode; import de.hysky.skyblocker.skyblock.shortcut.ShortcutsConfigScreen; import dev.isxander.yacl3.api.*; import dev.isxander.yacl3.api.controller.FloatSliderControllerBuilder; import net.minecraft.client.MinecraftClient; +import net.minecraft.client.gui.screen.option.KeybindsScreen; import net.minecraft.text.Text; import net.minecraft.util.Formatting; @@ -234,13 +236,18 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig .group(OptionGroup.createBuilder() .name(Text.translatable("skyblocker.config.general.itemInfoDisplay")) .collapsed(true) - .option(Option.createBuilder() + .option(Option.createBuilder() .name(Text.translatable("skyblocker.config.general.itemInfoDisplay.slotText")) .description(OptionDescription.of(Text.translatable("skyblocker.config.general.itemInfoDisplay.slotText.@Tooltip"))) - .binding(defaults.general.itemInfoDisplay.slotText, - () -> config.general.itemInfoDisplay.slotText, - newValue -> config.general.itemInfoDisplay.slotText = newValue) - .controller(ConfigUtils::createBooleanController) + .binding(defaults.general.itemInfoDisplay.slotTextMode, + () -> config.general.itemInfoDisplay.slotTextMode, + newValue -> config.general.itemInfoDisplay.slotTextMode = newValue) + .controller(ConfigUtils::createEnumCyclingListController) + .build()) + .option(ButtonOption.createBuilder() + .name(Text.translatable("skyblocker.config.shortcutToKeybindsSettings")) + .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new KeybindsScreen(screen, MinecraftClient.getInstance().options))) + .text(Text.translatable("skyblocker.config.shortcutToKeybindsSettings.@Text")) .build()) .option(Option.createBuilder() .name(Text.translatable("skyblocker.config.general.itemInfoDisplay.attributeShardInfo")) @@ -301,6 +308,11 @@ public static ConfigCategory create(SkyblockerConfig defaults, SkyblockerConfig newValue -> config.general.wikiLookup.enableWikiLookup = newValue) .controller(ConfigUtils::createBooleanController) .build()) + .option(ButtonOption.createBuilder() + .name(Text.translatable("skyblocker.config.shortcutToKeybindsSettings")) + .action((screen, opt) -> MinecraftClient.getInstance().setScreen(new KeybindsScreen(screen, MinecraftClient.getInstance().options))) + .text(Text.translatable("skyblocker.config.shortcutToKeybindsSettings.@Text")) + .build()) .option(Option.createBuilder() .name(Text.translatable("skyblocker.config.general.wikiLookup.officialWiki")) .description(OptionDescription.of(Text.translatable("skyblocker.config.general.wikiLookup.officialWiki.@Tooltip"))) diff --git a/src/main/java/de/hysky/skyblocker/config/configs/GeneralConfig.java b/src/main/java/de/hysky/skyblocker/config/configs/GeneralConfig.java index 691e6f794b..61386452fa 100644 --- a/src/main/java/de/hysky/skyblocker/config/configs/GeneralConfig.java +++ b/src/main/java/de/hysky/skyblocker/config/configs/GeneralConfig.java @@ -3,6 +3,7 @@ import de.hysky.skyblocker.SkyblockerMod; import de.hysky.skyblocker.skyblock.item.CustomArmorAnimatedDyes; import de.hysky.skyblocker.skyblock.item.CustomArmorTrims; +import de.hysky.skyblocker.skyblock.item.slottext.SlotTextMode; import dev.isxander.yacl3.config.v2.api.SerialEntry; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -163,9 +164,16 @@ public String getOrder() { } public static class ItemInfoDisplay { + @Deprecated @SerialEntry public boolean slotText = true; + @SerialEntry + public SlotTextMode slotTextMode = SlotTextMode.ENABLED; + + @SerialEntry + public boolean slotTextToggled = true; + @SerialEntry public boolean attributeShardInfo = true; diff --git a/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java b/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java index 709b8697d7..2f22a87036 100644 --- a/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java +++ b/src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java @@ -14,7 +14,6 @@ import de.hysky.skyblocker.skyblock.item.ItemRarityBackgrounds; import de.hysky.skyblocker.skyblock.item.MuseumItemCache; import de.hysky.skyblocker.skyblock.item.WikiLookup; -import de.hysky.skyblocker.skyblock.item.slottext.SlotText; import de.hysky.skyblocker.skyblock.item.slottext.SlotTextManager; import de.hysky.skyblocker.skyblock.item.tooltip.BackpackPreview; import de.hysky.skyblocker.skyblock.item.tooltip.CompactorDeletorPreview; @@ -22,11 +21,10 @@ import de.hysky.skyblocker.skyblock.quicknav.QuickNavButton; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.Utils; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; +import de.hysky.skyblocker.utils.container.ContainerSolver; import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.client.util.math.MatrixStack; import net.minecraft.inventory.SimpleInventory; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -236,7 +234,7 @@ protected HandledScreenMixin(Text title) { // Prevent clicks on filler items if (SkyblockerConfigManager.get().uiAndVisuals.hideEmptyTooltips && FILLER_ITEMS.contains(stack.getName().getString()) && // Allow clicks in Ultrasequencer and Superpairs - (!UltrasequencerSolver.INSTANCE.getName().matcher(title).matches() || SkyblockerConfigManager.get().helpers.experiments.enableUltrasequencerSolver)) { + (!UltrasequencerSolver.INSTANCE.getTitlePattern().matcher(title).matches() || SkyblockerConfigManager.get().helpers.experiments.enableUltrasequencerSolver)) { ci.cancel(); return; } @@ -335,31 +333,8 @@ protected HandledScreenMixin(Text title) { @Inject(method = "drawSlot", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/DrawContext;drawItemInSlot(Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/item/ItemStack;IILjava/lang/String;)V")) private void skyblocker$drawSlotText(DrawContext context, Slot slot, CallbackInfo ci) { - List textList = SlotTextManager.getText(slot); - if (textList.isEmpty()) return; - MatrixStack matrices = context.getMatrices(); - - for (SlotText slotText : textList) { - matrices.push(); - matrices.translate(0.0f, 0.0f, 200.0f); - int length = textRenderer.getWidth(slotText.text()); - if (length > 16) { - matrices.scale(16.0f / length, 16.0f / length, 1.0f); //Make them fit in the slot. FYI, a slot is sized 16×16. - final float x = (slot.x * length / 16.0f) - slot.x; //Save in a variable to not recalculate - switch (slotText.position()) { - case TOP_LEFT, TOP_RIGHT -> matrices.translate(x, (slot.y * length / 16.0f) - slot.y, 0.0f); - case BOTTOM_LEFT, BOTTOM_RIGHT -> matrices.translate(x, ((slot.y + 16f - textRenderer.fontHeight + 2f + 0.7f) * length / 16.0f) - slot.y, 0.0f); - } - } else { - switch (slotText.position()) { - case TOP_LEFT -> { /*Do Nothing*/ } - case TOP_RIGHT -> matrices.translate(16f - length, 0.0f, 0.0f); - case BOTTOM_LEFT -> matrices.translate(0.0f, 16f - textRenderer.fontHeight + 2f, 0.0f); - case BOTTOM_RIGHT -> matrices.translate(16f - length, 16f - textRenderer.fontHeight + 2f, 0.0f); - } - } - context.drawText(textRenderer, slotText.text(), slot.x, slot.y, 0xFFFFFF, true); - matrices.pop(); + if (Utils.isOnSkyblock()) { + SlotTextManager.renderSlotText(context, textRenderer, slot); } } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/accessories/newyearcakes/NewYearCakeBagHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/accessories/newyearcakes/NewYearCakeBagHelper.java index 747ce9b464..11c99daab2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/accessories/newyearcakes/NewYearCakeBagHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/accessories/newyearcakes/NewYearCakeBagHelper.java @@ -2,7 +2,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.client.MinecraftClient; import net.minecraft.item.ItemStack; @@ -10,18 +10,18 @@ import java.util.List; -public class NewYearCakeBagHelper extends ContainerSolver { +public class NewYearCakeBagHelper extends SimpleContainerSolver { public NewYearCakeBagHelper() { super("New Year Cake Bag"); } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return SkyblockerConfigManager.get().helpers.enableNewYearCakesHelper; } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { MinecraftClient client = MinecraftClient.getInstance(); if (client.player != null) { for (Slot slot : client.player.currentScreenHandler.slots) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/accessories/newyearcakes/NewYearCakesHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/accessories/newyearcakes/NewYearCakesHelper.java index c403a81b5b..4b3dbda854 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/accessories/newyearcakes/NewYearCakesHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/accessories/newyearcakes/NewYearCakesHelper.java @@ -3,7 +3,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.Utils; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; @@ -19,8 +19,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class NewYearCakesHelper extends ContainerSolver { - private static final Logger LOGGER = LoggerFactory.getLogger(NewYearCakeBagHelper.class); +public class NewYearCakesHelper extends SimpleContainerSolver { + private static final Logger LOGGER = LoggerFactory.getLogger(NewYearCakesHelper.class); private static final Pattern NEW_YEAR_CAKE = Pattern.compile("New Year Cake \\(Year (?\\d+)\\)"); private static final Pattern NEW_YEAR_CAKE_PURCHASE = Pattern.compile("You purchased New Year Cake \\(Year (?\\d+)\\) for .+ coins!"); private static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US); @@ -49,7 +49,7 @@ public static int getCakeYear(Pattern pattern, String name) { } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return SkyblockerConfigManager.get().helpers.enableNewYearCakesHelper; } @@ -65,7 +65,7 @@ private void onChatMessage(Text message, boolean overlay) { } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { String profile = Utils.getProfile(); if (cakes.isEmpty() || !cakes.containsKey(profile) || cakes.containsKey(profile) && cakes.get(profile).isEmpty()) return List.of(); List highlights = new ArrayList<>(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java index 8b83b06bdf..8fbeb6e0b4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/bazaar/BazaarHelper.java @@ -1,8 +1,8 @@ package de.hysky.skyblocker.skyblock.bazaar; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -11,12 +11,13 @@ import net.minecraft.util.Formatting; import org.apache.commons.lang3.math.NumberUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class BazaarHelper extends SlotTextAdder { +public class BazaarHelper extends SimpleSlotTextAdder { private static final Pattern FILLED_PATTERN = Pattern.compile("Filled: \\S+ \\(?([\\d.]+)%\\)?!?"); private static final int RED = 0xe60b1e; private static final int YELLOW = 0xe6ba0b; @@ -27,14 +28,19 @@ public BazaarHelper() { } @Override - public @NotNull List getText(Slot slot) { - if (!SkyblockerConfigManager.get().helpers.bazaar.enableBazaarHelper) return List.of(); + public boolean isEnabled() { + return SkyblockerConfigManager.get().helpers.bazaar.enableBazaarHelper; + } + + @Override + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (slot == null) return List.of(); // Skip the first row as it's always glass panes. - if (slot.id < 10) return List.of(); + if (slotId < 10) return List.of(); // Skip the last 10 items. 11 is subtracted because size is 1-based so the last slot is size - 1. - if (slot.id > slot.inventory.size() - 11) return List.of(); //Note that this also skips the slots in player's inventory (anything above 36/45/54 depending on the order count) + if (slotId > slot.inventory.size() - 11) return List.of(); //Note that this also skips the slots in player's inventory (anything above 36/45/54 depending on the order count) - int column = slot.id % 9; + int column = slotId % 9; if (column == 0 || column == 8) return List.of(); // Skip the first and last column as those are always glass panes as well. ItemStack item = slot.getStack(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java index c2b11926b1..f6c53528f3 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/bazaar/ReorderHelper.java @@ -1,9 +1,9 @@ package de.hysky.skyblocker.skyblock.bazaar; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; import de.hysky.skyblocker.utils.ItemUtils; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; +import de.hysky.skyblocker.utils.container.TooltipAdder; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.client.MinecraftClient; import net.minecraft.client.util.InputUtil; @@ -19,7 +19,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class ReorderHelper extends ContainerSolver { +public class ReorderHelper extends SimpleContainerSolver implements TooltipAdder { private static final Pattern BUY_PATTERN = Pattern.compile("([\\d,]+)x missing items\\."); private static final Pattern SELL_PATTERN = Pattern.compile("([\\d,]+)x items\\."); @@ -28,12 +28,12 @@ public ReorderHelper() { } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return true; } @Override - protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) { + public boolean onClickSlot(int slot, ItemStack stack, int screenId) { // V This part is so that it short-circuits if not necessary if ((slot == 11 || slot == 13) && stack.isOf(Items.GREEN_TERRACOTTA) && InputUtil.isKeyPressed(MinecraftClient.getInstance().getWindow().getHandle(), GLFW.GLFW_KEY_LEFT_CONTROL)) { Matcher matcher; @@ -49,25 +49,24 @@ protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { return List.of(); } - public static class Tooltip extends TooltipAdder { - public Tooltip() { - super("^Order options", Integer.MIN_VALUE); - } - - @Override - public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { - if (focusedSlot == null || !stack.isOf(Items.GREEN_TERRACOTTA)) return; - switch (focusedSlot.id) { - case 11, 13 -> { - lines.add(Text.empty()); - lines.add(Text.empty().append(Text.translatable("skyblocker.reorderHelper.tooltip.line1")).formatted(Formatting.DARK_GRAY, Formatting.ITALIC)); - lines.add(Text.empty().append(Text.translatable("skyblocker.reorderHelper.tooltip.line2")).formatted(Formatting.DARK_GRAY, Formatting.ITALIC)); - } + @Override + public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { + if (focusedSlot == null || !stack.isOf(Items.GREEN_TERRACOTTA)) return; + switch (focusedSlot.id) { + case 11, 13 -> { + lines.add(Text.empty()); + lines.add(Text.empty().append(Text.translatable("skyblocker.reorderHelper.tooltip.line1")).formatted(Formatting.DARK_GRAY, Formatting.ITALIC)); + lines.add(Text.empty().append(Text.translatable("skyblocker.reorderHelper.tooltip.line2")).formatted(Formatting.DARK_GRAY, Formatting.ITALIC)); } } } + + @Override + public int getPriority() { + return Integer.MIN_VALUE; + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java index 04f6536d0a..edb6aa0dbc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/chocolatefactory/ChocolateFactorySolver.java @@ -1,12 +1,12 @@ package de.hysky.skyblocker.skyblock.chocolatefactory; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.adders.LineSmoothener; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RegexUtils; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; +import de.hysky.skyblocker.utils.container.TooltipAdder; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.objects.ObjectArrayList; import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; @@ -28,7 +28,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class ChocolateFactorySolver extends ContainerSolver { +public class ChocolateFactorySolver extends SimpleContainerSolver implements TooltipAdder { //Patterns private static final Pattern CPS_PATTERN = Pattern.compile("([\\d,.]+) Chocolate per second"); private static final Pattern CPS_INCREASE_PATTERN = Pattern.compile("\\+([\\d,]+) Chocolate per second"); @@ -52,19 +52,18 @@ public class ChocolateFactorySolver extends ContainerSolver { private static final byte STRAY_RABBIT_START = 0; private static final byte STRAY_RABBIT_END = 26; - // TODO: Convert to instance fields in #788 - private static final ObjectArrayList cpsIncreaseFactors = new ObjectArrayList<>(8); - private static long totalChocolate = -1L; - private static double totalCps = -1.0; - private static double totalCpsMultiplier = -1.0; - private static long requiredUntilNextPrestige = -1L; - private static boolean canPrestige = false; - private static boolean reachedMaxPrestige = false; - private static double timeTowerMultiplier = -1.0; - private static boolean isTimeTowerMaxed = false; - private static boolean isTimeTowerActive = false; - private static int bestUpgrade = -1; - private static int bestAffordableUpgrade = -1; + private final ObjectArrayList cpsIncreaseFactors = new ObjectArrayList<>(8); + private long totalChocolate = -1L; + private double totalCps = -1.0; + private double totalCpsMultiplier = -1.0; + private long requiredUntilNextPrestige = -1L; + private boolean canPrestige = false; + private boolean reachedMaxPrestige = false; + private double timeTowerMultiplier = -1.0; + private boolean isTimeTowerMaxed = false; + private boolean isTimeTowerActive = false; + private int bestUpgrade = -1; + private int bestAffordableUpgrade = -1; private static StraySound ding = StraySound.NONE; private static int dingTick = 0; @@ -89,12 +88,14 @@ private static void onTick(MinecraftClient client) { } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return SkyblockerConfigManager.get().helpers.chocolateFactory.enableChocolateFactoryHelper; } + // ======== Container Solver ======== + @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { updateFactoryInfo(slots); List highlights = new ArrayList<>(); @@ -239,160 +240,163 @@ private List getStrayRabbitHighlight(Int2ObjectMap sl return highlights; } - @Override - protected void reset() { - cpsIncreaseFactors.clear(); - totalChocolate = -1L; - totalCps = -1.0; - totalCpsMultiplier = -1.0; - requiredUntilNextPrestige = -1L; - canPrestige = false; - reachedMaxPrestige = false; - timeTowerMultiplier = -1.0; - isTimeTowerMaxed = false; - isTimeTowerActive = false; - bestUpgrade = -1; - bestAffordableUpgrade = -1; - ding = StraySound.NONE; - } - - private enum StraySound { - NONE, - NORMAL, - GOLDEN - } - - private record Rabbit(double cpsIncrease, long cost, int slot) {} + // ======== Tooltip Adder ======== - public static final class Tooltip extends TooltipAdder { - public Tooltip() { - super("^Chocolate Factory$", 0); //The priority doesn't really matter here as this is the only tooltip adder for the Chocolate Factory. - } + @Override + public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { + if (focusedSlot == null) return; - @Override - public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { - if (!SkyblockerConfigManager.get().helpers.chocolateFactory.enableChocolateFactoryHelper || focusedSlot == null) return; + int lineIndex = lines.size(); + //This boolean is used to determine if we should add a smooth line to separate the added information from the rest of the tooltip. + //It should be set to true if there's any information added, false otherwise. + boolean shouldAddLine = false; - int lineIndex = lines.size(); - //This boolean is used to determine if we should add a smooth line to separate the added information from the rest of the tooltip. - //It should be set to true if there's any information added, false otherwise. - boolean shouldAddLine = false; + String lore = ItemUtils.concatenateLore(lines); + Matcher costMatcher = COST_PATTERN.matcher(lore); + OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher); + //Available on all items with a chocolate cost + if (cost.isPresent()) shouldAddLine |= addUpgradeTimerToLore(lines, cost.getAsLong()); - String lore = ItemUtils.concatenateLore(lines); - Matcher costMatcher = COST_PATTERN.matcher(lore); - OptionalLong cost = RegexUtils.getLongFromMatcher(costMatcher); - //Available on all items with a chocolate cost - if (cost.isPresent()) shouldAddLine |= addUpgradeTimerToLore(lines, cost.getAsLong()); + int index = focusedSlot.id; - int index = focusedSlot.id; + //Prestige item + if (index == PRESTIGE_SLOT) { + shouldAddLine |= addPrestigeTimerToLore(lines); + } + //Time tower + else if (index == TIME_TOWER_SLOT) { + shouldAddLine |= addTimeTowerStatsToLore(lines); + } + //Rabbits + else if (index == COACH_SLOT || (index >= RABBITS_START && index <= RABBITS_END)) { + shouldAddLine |= addRabbitStatsToLore(lines, index); + } - //Prestige item - if (index == PRESTIGE_SLOT) { - shouldAddLine |= addPrestigeTimerToLore(lines); - } - //Time tower - else if (index == TIME_TOWER_SLOT) { - shouldAddLine |= addTimeTowerStatsToLore(lines); - } - //Rabbits - else if (index == COACH_SLOT || (index >= RABBITS_START && index <= RABBITS_END)) { - shouldAddLine |= addRabbitStatsToLore(lines, index); - } + //This is an ArrayList, so this operation is probably not very efficient, but logically it's pretty much the only way I can think of + if (shouldAddLine) lines.add(lineIndex, LineSmoothener.createSmoothLine()); + } - //This is an ArrayList, so this operation is probably not very efficient, but logically it's pretty much the only way I can think of - if (shouldAddLine) lines.add(lineIndex, LineSmoothener.createSmoothLine()); - } + private boolean addUpgradeTimerToLore(List lines, long cost) { + if (totalChocolate < 0L || totalCps < 0.0) return false; + lines.add(Text.empty() + .append(Text.literal("Time until upgrade: ").formatted(Formatting.GRAY)) + .append(formatTime((cost - totalChocolate) / totalCps))); + return true; + } - private boolean addUpgradeTimerToLore(List lines, long cost) { - if (totalChocolate < 0L || totalCps < 0.0) return false; + private boolean addPrestigeTimerToLore(List lines) { + if (totalCps < 0.0 || reachedMaxPrestige) return false; + if (requiredUntilNextPrestige > 0 && !canPrestige) { lines.add(Text.empty() - .append(Text.literal("Time until upgrade: ").formatted(Formatting.GRAY)) - .append(formatTime((cost - totalChocolate) / totalCps))); - return true; - } - - private boolean addPrestigeTimerToLore(List lines) { - if (totalCps < 0.0 || reachedMaxPrestige) return false; - if (requiredUntilNextPrestige > 0 && !canPrestige) { - lines.add(Text.empty() - .append(Text.literal("Chocolate until next prestige: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(requiredUntilNextPrestige)).formatted(Formatting.GOLD))); - } - lines.add(Text.empty() //Keep this outside of the `if` to match the format of the upgrade tooltips, that say "Time until upgrade: Now" when it's possible - .append(Text.literal("Time until next prestige: ").formatted(Formatting.GRAY)) - .append(formatTime(requiredUntilNextPrestige / totalCps))); - return true; + .append(Text.literal("Chocolate until next prestige: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(requiredUntilNextPrestige)).formatted(Formatting.GOLD))); } + lines.add(Text.empty() //Keep this outside of the `if` to match the format of the upgrade tooltips, that say "Time until upgrade: Now" when it's possible + .append(Text.literal("Time until next prestige: ").formatted(Formatting.GRAY)) + .append(formatTime(requiredUntilNextPrestige / totalCps))); + return true; + } - private boolean addTimeTowerStatsToLore(List lines) { - if (totalCps < 0.0 || totalCpsMultiplier < 0.0 || timeTowerMultiplier < 0.0) return false; - lines.add(Text.literal("Current stats:").formatted(Formatting.GRAY)); + private boolean addTimeTowerStatsToLore(List lines) { + if (totalCps < 0.0 || totalCpsMultiplier < 0.0 || timeTowerMultiplier < 0.0) return false; + lines.add(Text.literal("Current stats:").formatted(Formatting.GRAY)); + lines.add(Text.empty() + .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(totalCps / totalCpsMultiplier * timeTowerMultiplier)).formatted(Formatting.GOLD))); + lines.add(Text.empty() + .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps : totalCps / totalCpsMultiplier * (timeTowerMultiplier + totalCpsMultiplier))).formatted(Formatting.GOLD))); + if (!isTimeTowerMaxed) { + lines.add(Text.literal("Stats after upgrade:").formatted(Formatting.GRAY)); lines.add(Text.empty() .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(totalCps / totalCpsMultiplier * timeTowerMultiplier)).formatted(Formatting.GOLD))); + .append(Text.literal(DECIMAL_FORMAT.format(totalCps / (totalCpsMultiplier) * (timeTowerMultiplier + 0.1))).formatted(Formatting.GOLD))); lines.add(Text.empty() .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps : totalCps / totalCpsMultiplier * (timeTowerMultiplier + totalCpsMultiplier))).formatted(Formatting.GOLD))); - if (!isTimeTowerMaxed) { - lines.add(Text.literal("Stats after upgrade:").formatted(Formatting.GRAY)); - lines.add(Text.empty() - .append(Text.literal(" CPS increase: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(totalCps / (totalCpsMultiplier) * (timeTowerMultiplier + 0.1))).formatted(Formatting.GOLD))); - lines.add(Text.empty() - .append(Text.literal(" CPS when active: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps / totalCpsMultiplier * (totalCpsMultiplier + 0.1) : totalCps / totalCpsMultiplier * (timeTowerMultiplier + 0.1 + totalCpsMultiplier))).formatted(Formatting.GOLD))); - } - return true; + .append(Text.literal(DECIMAL_FORMAT.format(isTimeTowerActive ? totalCps / totalCpsMultiplier * (totalCpsMultiplier + 0.1) : totalCps / totalCpsMultiplier * (timeTowerMultiplier + 0.1 + totalCpsMultiplier))).formatted(Formatting.GOLD))); } + return true; + } - private boolean addRabbitStatsToLore(List lines, int slot) { - if (cpsIncreaseFactors.isEmpty()) return false; - for (Rabbit rabbit : cpsIncreaseFactors) { - if (rabbit.slot == slot) { - lines.add(Text.empty() - .append(Text.literal("CPS Increase: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cpsIncrease)).formatted(Formatting.GOLD))); - - lines.add(Text.empty() - .append(Text.literal("Cost per CPS: ").formatted(Formatting.GRAY)) - .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cost / rabbit.cpsIncrease)).formatted(Formatting.GOLD))); - - if (rabbit.slot == bestUpgrade) { - if (rabbit.cost <= totalChocolate) { - lines.add(Text.literal("Best upgrade").formatted(Formatting.GREEN)); - } else { - lines.add(Text.literal("Best upgrade, can't afford").formatted(Formatting.YELLOW)); - } - } else if (rabbit.slot == bestAffordableUpgrade && rabbit.cost <= totalChocolate) { - lines.add(Text.literal("Best upgrade you can afford").formatted(Formatting.GREEN)); + private boolean addRabbitStatsToLore(List lines, int slot) { + if (cpsIncreaseFactors.isEmpty()) return false; + for (Rabbit rabbit : cpsIncreaseFactors) { + if (rabbit.slot == slot) { + lines.add(Text.empty() + .append(Text.literal("CPS Increase: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cpsIncrease)).formatted(Formatting.GOLD))); + + lines.add(Text.empty() + .append(Text.literal("Cost per CPS: ").formatted(Formatting.GRAY)) + .append(Text.literal(DECIMAL_FORMAT.format(rabbit.cost / rabbit.cpsIncrease)).formatted(Formatting.GOLD))); + + if (rabbit.slot == bestUpgrade) { + if (rabbit.cost <= totalChocolate) { + lines.add(Text.literal("Best upgrade").formatted(Formatting.GREEN)); + } else { + lines.add(Text.literal("Best upgrade, can't afford").formatted(Formatting.YELLOW)); } - return true; + } else if (rabbit.slot == bestAffordableUpgrade && rabbit.cost <= totalChocolate) { + lines.add(Text.literal("Best upgrade you can afford").formatted(Formatting.GREEN)); } + return true; } - return false; } + return false; + } - private MutableText formatTime(double seconds) { - seconds = Math.ceil(seconds); - if (seconds <= 0) return Text.literal("Now").formatted(Formatting.GREEN); + private MutableText formatTime(double seconds) { + seconds = Math.ceil(seconds); + if (seconds <= 0) return Text.literal("Now").formatted(Formatting.GREEN); - StringBuilder builder = new StringBuilder(); - if (seconds >= 86400) { - builder.append((int) (seconds / 86400)).append("d "); - seconds %= 86400; - } - if (seconds >= 3600) { - builder.append((int) (seconds / 3600)).append("h "); - seconds %= 3600; - } - if (seconds >= 60) { - builder.append((int) (seconds / 60)).append("m "); - seconds %= 60; - } - if (seconds >= 1) { - builder.append((int) seconds).append("s"); - } - return Text.literal(builder.toString()).formatted(Formatting.GOLD); + StringBuilder builder = new StringBuilder(); + if (seconds >= 86400) { + builder.append((int) (seconds / 86400)).append("d "); + seconds %= 86400; } + if (seconds >= 3600) { + builder.append((int) (seconds / 3600)).append("h "); + seconds %= 3600; + } + if (seconds >= 60) { + builder.append((int) (seconds / 60)).append("m "); + seconds %= 60; + } + if (seconds >= 1) { + builder.append((int) seconds).append("s"); + } + return Text.literal(builder.toString()).formatted(Formatting.GOLD); + } + + @Override + public int getPriority() { + return 0; //The priority doesn't really matter here as this is the only tooltip adder for the Chocolate Factory. + } + + // ======== Reset and Other Classes ======== + + @Override + public void reset() { + cpsIncreaseFactors.clear(); + totalChocolate = -1L; + totalCps = -1.0; + totalCpsMultiplier = -1.0; + requiredUntilNextPrestige = -1L; + canPrestige = false; + reachedMaxPrestige = false; + timeTowerMultiplier = -1.0; + isTimeTowerMaxed = false; + isTimeTowerActive = false; + bestUpgrade = -1; + bestAffordableUpgrade = -1; + ding = StraySound.NONE; + } + + private enum StraySound { + NONE, + NORMAL, + GOLDEN } + + private record Rabbit(double cpsIncrease, long cost, int slot) {} } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusHelper.java index d317a2e81e..1a0aa34775 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusHelper.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusHelper.java @@ -3,7 +3,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemStack; @@ -11,19 +11,18 @@ import java.util.ArrayList; import java.util.List; -public class CroesusHelper extends ContainerSolver { - +public class CroesusHelper extends SimpleContainerSolver { public CroesusHelper() { super("^Croesus$"); } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return SkyblockerConfigManager.get().dungeons.croesusHelper; } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { List highlights = new ArrayList<>(); for (Int2ObjectMap.Entry entry : slots.int2ObjectEntrySet()) { ItemStack stack = entry.getValue(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java index 0f459c9d9b..82acc3f2ce 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/CroesusProfit.java @@ -1,16 +1,13 @@ package de.hysky.skyblocker.skyblock.dungeon; -import com.google.gson.JsonObject; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.item.ItemStack; import net.minecraft.text.Text; import net.minecraft.util.Util; - import org.jetbrains.annotations.NotNull; import java.util.ArrayList; @@ -20,19 +17,19 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class CroesusProfit extends ContainerSolver { - private static final Pattern ESSENCE_PATTERN = Pattern.compile("(?[A-Za-z]+) Essence x(?[0-9]+)"); +public class CroesusProfit extends SimpleContainerSolver { + private static final Pattern ESSENCE_PATTERN = Pattern.compile("(?[A-Za-z]+) Essence x(?\\d+)"); public CroesusProfit() { super(".*Catacombs - Floor.*"); } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return SkyblockerConfigManager.get().dungeons.dungeonChestProfit.croesusProfit; } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { List highlights = new ArrayList<>(); ItemStack bestChest = null, secondBestChest = null; double bestValue = 0, secondBestValue = 0; // If negative value of chest - it is out of the question @@ -82,7 +79,7 @@ private double valueChest(@NotNull ItemStack chest) { } else if (lineString.isEmpty()) { processingContents = false; } else if (lineString.contains("Coins") && !processingContents) { - chestPrice = Integer.parseInt(lineString.replaceAll(",", "").replaceAll("\\D", "")); + chestPrice = Integer.parseInt(lineString.replace(",", "").replaceAll("\\D", "")); } if (processingContents) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java index 7a966b4845..6cbb86ec47 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/ColorTerminal.java @@ -1,8 +1,9 @@ package de.hysky.skyblocker.skyblock.dungeon.terminal; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.utils.container.ContainerSolver; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; @@ -16,7 +17,7 @@ import java.util.*; -public final class ColorTerminal extends ContainerSolver implements TerminalSolver { +public final class ColorTerminal extends SimpleContainerSolver implements TerminalSolver { private static final Logger LOGGER = LoggerFactory.getLogger(ColorTerminal.class.getName()); private static final Map colorFromName; private DyeColor targetColor; @@ -27,20 +28,20 @@ public ColorTerminal() { } @Override - protected boolean isEnabled() { + public boolean isEnabled() { targetColor = null; return SkyblockerConfigManager.get().dungeons.terminals.solveColor; } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { - trimEdges(slots, 6); + public List getColors(Int2ObjectMap slots) { + ContainerSolver.trimEdges(slots, 6); List highlights = new ArrayList<>(); String colorString = groups[0]; if (targetColor == null) { targetColor = colorFromName.get(colorString); if (targetColor == null) { - LOGGER.error("[Skyblocker] Couldn't find dye color corresponding to \"" + colorString + "\""); + LOGGER.error("[Skyblocker] Couldn't find dye color corresponding to \"{}\"", colorString); return Collections.emptyList(); } } @@ -54,7 +55,7 @@ protected List getColors(String[] groups, Int2ObjectMap EMPTY = List.of(); public LightsOnTerminal() { @@ -21,17 +21,17 @@ public LightsOnTerminal() { } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return shouldBlockIncorrectClicks(); } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { return EMPTY; } @Override - protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) { + public boolean onClickSlot(int slot, ItemStack stack, int screenId) { return stack.isOf(Items.LIME_STAINED_GLASS_PANE); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/OrderTerminal.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/OrderTerminal.java index ae145993e8..507389c6d2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/OrderTerminal.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/OrderTerminal.java @@ -1,8 +1,9 @@ package de.hysky.skyblocker.skyblock.dungeon.terminal; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.utils.container.ContainerSolver; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -11,8 +12,8 @@ import java.util.Collections; import java.util.List; -public final class OrderTerminal extends ContainerSolver implements TerminalSolver { - private final int PANES_NUM = 14; +public final class OrderTerminal extends SimpleContainerSolver implements TerminalSolver { + private static final int PANES_NUM = 14; private int[] orderedSlots; private int currentNum = Integer.MAX_VALUE; @@ -21,14 +22,14 @@ public OrderTerminal() { } @Override - protected boolean isEnabled() { + public boolean isEnabled() { orderedSlots = null; currentNum = 0; return SkyblockerConfigManager.get().dungeons.terminals.solveOrder; } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { if(orderedSlots == null && !orderSlots(slots)) return Collections.emptyList(); while(currentNum < PANES_NUM && slots.containsKey(orderedSlots[currentNum]) && Items.LIME_STAINED_GLASS_PANE.equals(slots.get(orderedSlots[currentNum]).getItem())) @@ -42,22 +43,21 @@ protected List getColors(String[] groups, Int2ObjectMap slots) { - trimEdges(slots, 4); + ContainerSolver.trimEdges(slots, 4); orderedSlots = new int[PANES_NUM]; for(Int2ObjectMap.Entry slot : slots.int2ObjectEntrySet()) { if(Items.AIR.equals(slot.getValue().getItem())) { orderedSlots = null; return false; } - else - orderedSlots[slot.getValue().getCount() - 1] = slot.getIntKey(); + else orderedSlots[slot.getValue().getCount() - 1] = slot.getIntKey(); } currentNum = 0; return true; } @Override - protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) { + public boolean onClickSlot(int slot, ItemStack stack, int screenId) { if (stack == null || stack.isEmpty()) return false; if (!stack.isOf(Items.RED_STAINED_GLASS_PANE) || stack.getCount() != currentNum + 1) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/StartsWithTerminal.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/StartsWithTerminal.java index 8b0f18018c..893e9f61f0 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/StartsWithTerminal.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/StartsWithTerminal.java @@ -1,8 +1,9 @@ package de.hysky.skyblocker.skyblock.dungeon.terminal; import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.utils.container.ContainerSolver; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; import it.unimi.dsi.fastutil.objects.ObjectSet; @@ -13,7 +14,7 @@ import java.util.List; import java.util.function.Predicate; -public final class StartsWithTerminal extends ContainerSolver implements TerminalSolver { +public final class StartsWithTerminal extends SimpleContainerSolver implements TerminalSolver { private final Int2ObjectOpenHashMap trackedItemStates = new Int2ObjectOpenHashMap<>(); private int lastKnownScreenId = Integer.MIN_VALUE; @@ -22,13 +23,13 @@ public StartsWithTerminal() { } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return SkyblockerConfigManager.get().dungeons.terminals.solveStartsWith; } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { - trimEdges(slots, 6); + public List getColors(Int2ObjectMap slots) { + ContainerSolver.trimEdges(slots, 6); setupState(slots); String prefix = groups[0]; @@ -50,7 +51,7 @@ protected List getColors(String[] groups, Int2ObjectMap usefulSlots) { Predicate> notNullOrEmpty = e -> e.getValue() != null && !e.getValue().isEmpty(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/TerminalSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/TerminalSolver.java index f20c35b5f7..cf384f08b4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/TerminalSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dungeon/terminal/TerminalSolver.java @@ -3,7 +3,6 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; public sealed interface TerminalSolver permits ColorTerminal, LightsOnTerminal, OrderTerminal, StartsWithTerminal { - default boolean shouldBlockIncorrectClicks() { return SkyblockerConfigManager.get().dungeons.terminals.blockIncorrectClicks; } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionHighlight.java b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionHighlight.java index de26809c72..c22a444024 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionHighlight.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/dwarven/CommissionHighlight.java @@ -2,8 +2,8 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.utils.ItemUtils; +import de.hysky.skyblocker.utils.container.SimpleContainerSolver; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; -import de.hysky.skyblocker.utils.render.gui.ContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.component.DataComponentTypes; import net.minecraft.item.ItemStack; @@ -11,19 +11,18 @@ import java.util.ArrayList; import java.util.List; -public class CommissionHighlight extends ContainerSolver { - +public class CommissionHighlight extends SimpleContainerSolver { public CommissionHighlight() { super("^Commissions$"); } @Override - protected boolean isEnabled() { + public boolean isEnabled() { return SkyblockerConfigManager.get().mining.commissionHighlight; } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { List highlights = new ArrayList<>(); for (Int2ObjectMap.Entry entry : slots.int2ObjectEntrySet()) { ItemStack stack = entry.getValue(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/experiment/ChronomatronSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/experiment/ChronomatronSolver.java index 308452ef14..a4d34a1bda 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/experiment/ChronomatronSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/experiment/ChronomatronSolver.java @@ -103,7 +103,7 @@ protected void tick(Screen screen) { } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { List highlights = new ArrayList<>(); if (getState() == State.SHOW && chronomatronSlots.size() > chronomatronCurrentOrdinal) { for (Int2ObjectMap.Entry indexStack : slots.int2ObjectEntrySet()) { @@ -119,8 +119,7 @@ protected List getColors(String[] groups, Int2ObjectMap slots = new HashMap<>(); - protected ExperimentSolver(String containerName) { + protected ExperimentSolver(@NotNull @Language("RegExp") String containerName) { super(containerName); } @@ -36,22 +38,20 @@ public Map getSlots() { } @Override - protected final boolean isEnabled() { + public final boolean isEnabled() { return isEnabled(SkyblockerConfigManager.get().helpers.experiments); } protected abstract boolean isEnabled(HelperConfig.Experiments experimentsConfig); @Override - protected void start(GenericContainerScreen screen) { - super.start(screen); + public void start(GenericContainerScreen screen) { state = State.REMEMBER; ScreenEvents.afterTick(screen).register(this::tick); } @Override - protected void reset() { - super.reset(); + public void reset() { state = State.REMEMBER; slots.clear(); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/experiment/SuperpairsSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/experiment/SuperpairsSolver.java index 5c2ed152eb..f2d4c55dd1 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/experiment/SuperpairsSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/experiment/SuperpairsSolver.java @@ -33,14 +33,12 @@ protected boolean isEnabled(HelperConfig.Experiments experimentsConfig) { } @Override - protected void start(GenericContainerScreen screen) { - super.start(screen); + public void start(GenericContainerScreen screen) { setState(State.SHOW); } @Override - protected void reset() { - super.reset(); + public void reset() { superpairsPrevClickedSlot = 0; superpairsCurrentSlot = null; superpairsDuplicatedSlots.clear(); @@ -63,7 +61,7 @@ protected void tick(Screen screen) { } @Override - protected List getColors(String[] groups, Int2ObjectMap displaySlots) { + public List getColors(Int2ObjectMap displaySlots) { List highlights = new ArrayList<>(); if (getState() == State.SHOW) { for (Int2ObjectMap.Entry indexStack : displaySlots.int2ObjectEntrySet()) { diff --git a/src/main/java/de/hysky/skyblocker/skyblock/experiment/UltrasequencerSolver.java b/src/main/java/de/hysky/skyblocker/skyblock/experiment/UltrasequencerSolver.java index a4d1e4b6d1..f39c1ffebe 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/experiment/UltrasequencerSolver.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/experiment/UltrasequencerSolver.java @@ -2,6 +2,7 @@ import de.hysky.skyblocker.config.configs.HelperConfig; import de.hysky.skyblocker.utils.render.gui.ColorHighlight; +import de.hysky.skyblocker.utils.container.ContainerSolver; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.GenericContainerScreen; @@ -55,7 +56,7 @@ protected void tick(Screen screen) { case WAIT -> { if (genericContainerScreen.getScreenHandler().getInventory().getStack(49).getName().getString().startsWith("Timer: ")) { setState(State.SHOW); - markHighlightsDirty(); + ContainerSolver.markHighlightsDirty(); } } case END -> { @@ -76,7 +77,7 @@ protected void tick(Screen screen) { } @Override - protected List getColors(String[] groups, Int2ObjectMap slots) { + public List getColors(Int2ObjectMap slots) { return getState() == State.SHOW && ultrasequencerNextSlot != 0 ? List.of(ColorHighlight.green(ultrasequencerNextSlot)) : new ArrayList<>(); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SimpleSlotTextAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SimpleSlotTextAdder.java new file mode 100644 index 0000000000..205e48d8f7 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SimpleSlotTextAdder.java @@ -0,0 +1,39 @@ +package de.hysky.skyblocker.skyblock.item.slottext; + +import de.hysky.skyblocker.utils.container.RegexContainerMatcher; +import de.hysky.skyblocker.utils.container.SlotTextAdder; +import org.intellij.lang.annotations.Language; +import org.jetbrains.annotations.NotNull; + +import java.util.regex.Pattern; + +/** + * Simple implementation of a slot text adder. + * Extend this class and add it to {@link SlotTextManager#adders} to add text to any arbitrary slot. + */ +public abstract class SimpleSlotTextAdder extends RegexContainerMatcher implements SlotTextAdder { + /** + * Utility constructor that will compile the given string into a pattern. + * + * @see #SimpleSlotTextAdder(Pattern) + */ + protected SimpleSlotTextAdder(@NotNull @Language("RegExp") String titlePattern) { + super(titlePattern); + } + + /** + * Creates a SlotTextAdder that will be applied to screens with titles that match the given pattern. + * + * @param titlePattern The pattern to match the screen title against. + */ + protected SimpleSlotTextAdder(@NotNull Pattern titlePattern) { + super(titlePattern); + } + + /** + * Creates a SlotTextAdder that will be applied to all screens. + */ + protected SimpleSlotTextAdder() { + super(); + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java deleted file mode 100644 index 71d9aa303b..0000000000 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextAdder.java +++ /dev/null @@ -1,58 +0,0 @@ -package de.hysky.skyblocker.skyblock.item.slottext; - -import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.utils.render.gui.AbstractContainerMatcher; -import net.minecraft.screen.slot.Slot; -import org.intellij.lang.annotations.Language; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.regex.Pattern; - -/** - * Extend this class and add it to {@link SlotTextManager#adders} to add text to any arbitrary slot. - */ -public abstract class SlotTextAdder extends AbstractContainerMatcher { - /** - * Utility constructor that will compile the given string into a pattern. - * - * @see #SlotTextAdder(Pattern) - */ - protected SlotTextAdder(@NotNull @Language("RegExp") String titlePattern) { - super(titlePattern); - } - - /** - * Creates a SlotTextAdder that will be applied to screens with titles that match the given pattern. - * - * @param titlePattern The pattern to match the screen title against. - */ - protected SlotTextAdder(@NotNull Pattern titlePattern) { - super(titlePattern); - } - - /** - * Creates a SlotTextAdder that will be applied to all screens. - */ - protected SlotTextAdder() { - super(); - } - - /** - * This method will be called for each rendered slot. Consider using a switch statement on {@link Slot#id} if you wish to add different text to different slots. - * - * @return A list of positioned text to be rendered. Return {@link List#of()} if no text should be rendered. - * @implNote By minecraft's design, scaled text inexplicably moves around. - * So, limit your text to 3 characters (or roughly less than 20 width) if you want it to not look horrible. - */ - public abstract @NotNull List getText(Slot slot); - - /** - * Override this method to add conditions to enable or disable this adder. - * @return Whether this adder is enabled. - * @implNote The slot text adders only work while in skyblock, so no need to check for that again. - */ - public boolean isEnabled() { - return SkyblockerConfigManager.get().general.itemInfoDisplay.slotText; - } -} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java index aa9bf93952..a28e204c9f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextManager.java @@ -1,13 +1,23 @@ package de.hysky.skyblocker.skyblock.item.slottext; +import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.bazaar.BazaarHelper; import de.hysky.skyblocker.skyblock.item.slottext.adders.*; import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.container.SlotTextAdder; +import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; -import net.minecraft.client.gui.screen.Screen; +import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents; +import net.minecraft.client.font.TextRenderer; +import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.ingame.HandledScreen; +import net.minecraft.client.option.KeyBinding; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; +import org.lwjgl.glfw.GLFW; import java.util.ArrayList; import java.util.List; @@ -35,24 +45,35 @@ public class SlotTextManager { new StatsTuningAdder() }; private static final ArrayList currentScreenAdders = new ArrayList<>(); + private static final KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.skyblocker.slottext", GLFW.GLFW_KEY_LEFT_ALT, "key.categories.skyblocker")); + private static boolean keyHeld = false; private SlotTextManager() { } public static void init() { ScreenEvents.AFTER_INIT.register((client, screen, width, height) -> { - if (screen instanceof HandledScreen && Utils.isOnSkyblock()) { - onScreenChange(screen); + if (screen instanceof HandledScreen handledScreen && Utils.isOnSkyblock()) { + onScreenChange(handledScreen); ScreenEvents.remove(screen).register(ignored -> currentScreenAdders.clear()); } + ScreenKeyboardEvents.afterKeyPress(screen).register((screen1, key, scancode, modifiers) -> { + if (keyBinding.matchesKey(key, scancode)) { + SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextToggled = !SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextToggled; + keyHeld = true; + } + }); + ScreenKeyboardEvents.afterKeyRelease(screen).register((screen1, key, scancode, modifiers) -> { + if (keyBinding.matchesKey(key, scancode)) { + keyHeld = false; + } + }); }); } - private static void onScreenChange(Screen screen) { - final String title = screen.getTitle().getString(); + private static void onScreenChange(HandledScreen screen) { for (SlotTextAdder adder : adders) { - if (!adder.isEnabled()) continue; - if (adder.titlePattern == null || adder.titlePattern.matcher(title).find()) { + if (adder.isEnabled() && adder.test(screen)) { currentScreenAdders.add(adder); } } @@ -66,12 +87,54 @@ private static void onScreenChange(Screen screen) { * The order of the adders remains the same as they were added to the {@link SlotTextManager#adders} array. */ @NotNull - public static List getText(Slot slot) { - if (currentScreenAdders.isEmpty()) return List.of(); + public static List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (currentScreenAdders.isEmpty() || !isEnabled()) return List.of(); for (SlotTextAdder adder : currentScreenAdders) { - List text = adder.getText(slot); + List text = adder.getText(slot, stack, slotId); if (!text.isEmpty()) return text; } return List.of(); } + + public static void renderSlotText(DrawContext context, TextRenderer textRenderer, @NotNull Slot slot) { + renderSlotText(context, textRenderer, slot, slot.getStack(), slot.id, slot.x, slot.y); + } + + public static void renderSlotText(DrawContext context, TextRenderer textRenderer, @Nullable Slot slot, ItemStack stack, int slotId, int x, int y) { + List textList = getText(slot, stack, slotId); + if (textList.isEmpty()) return; + MatrixStack matrices = context.getMatrices(); + + for (SlotText slotText : textList) { + matrices.push(); + matrices.translate(0.0f, 0.0f, 200.0f); + int length = textRenderer.getWidth(slotText.text()); + if (length > 16) { + matrices.scale(16f / length, 16f / length, 1.0f); + switch (slotText.position()) { + case TOP_LEFT, TOP_RIGHT -> matrices.translate(x * length / 16f - x, (y * length / 16.0f) - y, 0.0f); + case BOTTOM_LEFT, BOTTOM_RIGHT -> matrices.translate(x * length / 16f - x, ((y + 16f - textRenderer.fontHeight + 2f + 0.7f) * length / 16.0f) - y, 0.0f); + } + } else { + switch (slotText.position()) { + case TOP_LEFT -> { /*Do Nothing*/ } + case TOP_RIGHT -> matrices.translate(16f - length, 0.0f, 0.0f); + case BOTTOM_LEFT -> matrices.translate(0.0f, 16f - textRenderer.fontHeight + 2f, 0.0f); + case BOTTOM_RIGHT -> matrices.translate(16f - length, 16f - textRenderer.fontHeight + 2f, 0.0f); + } + } + context.drawText(textRenderer, slotText.text(), x, y, 0xFFFFFF, true); + matrices.pop(); + } + } + + public static boolean isEnabled() { + return switch (SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextMode) { + case ENABLED -> true; + case DISABLED -> false; + case PRESS_TO_TOGGLE -> SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextToggled; + case HOLD_TO_HIDE -> !keyHeld; + case HOLD_TO_SHOW -> keyHeld; + }; + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextMode.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextMode.java new file mode 100644 index 0000000000..1f04388808 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/SlotTextMode.java @@ -0,0 +1,23 @@ +package de.hysky.skyblocker.skyblock.item.slottext; + +/** + * Used in {@link SlotTextManager#isEnabled()} to determine whether the slot text should be shown or not. + */ +public enum SlotTextMode { + ENABLED, + HOLD_TO_SHOW, + PRESS_TO_TOGGLE, + HOLD_TO_HIDE, + DISABLED; + + @Override + public String toString() { + return switch (this) { + case ENABLED -> "Enabled"; + case HOLD_TO_SHOW -> "Hold to Show"; + case PRESS_TO_TOGGLE -> "Press to Toggle"; + case HOLD_TO_HIDE -> "Hold to Hide"; + case DISABLED -> "Disabled"; + }; + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/TextPosition.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/TextPosition.java index 052b228d17..59f5e7e894 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/TextPosition.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/TextPosition.java @@ -1,5 +1,8 @@ package de.hysky.skyblocker.skyblock.item.slottext; +/** + * Used in {@link SlotText#position} to determine where the slot text should be rendered. + */ public enum TextPosition { TOP_LEFT, TOP_RIGHT, diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java index eac0a7f043..27856ab846 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/AttributeShardAdder.java @@ -2,7 +2,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import it.unimi.dsi.fastutil.objects.Object2ObjectMap; import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap; @@ -10,12 +10,12 @@ import net.minecraft.nbt.NbtCompound; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; -public class AttributeShardAdder extends SlotTextAdder { +public class AttributeShardAdder extends SimpleSlotTextAdder { private static final Object2ObjectMap ID_2_SHORT_NAME = new Object2ObjectOpenHashMap<>(); static { @@ -70,8 +70,7 @@ public AttributeShardAdder() { } @Override - public @NotNull List getText(Slot slot) { - final ItemStack stack = slot.getStack(); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { NbtCompound customData = ItemUtils.getCustomData(stack); if (!ItemUtils.getItemId(stack).equals("ATTRIBUTE_SHARD")) return List.of(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java index 6c99ebf9ad..ce0e38722a 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CatacombsLevelAdder.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.RomanNumerals; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -9,6 +9,7 @@ import net.minecraft.util.Formatting; import org.apache.commons.lang3.math.NumberUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; @@ -20,17 +21,17 @@ public class CatacombsLevelAdder { private CatacombsLevelAdder() { } - public static class Dungeoneering extends SlotTextAdder { + public static class Dungeoneering extends SimpleSlotTextAdder { private static final Pattern LEVEL_PATTERN = Pattern.compile(".*?(?:(?\\d+)|(?\\S+))? ?✯?"); public Dungeoneering() { super("^Dungeoneering"); } @Override - public @NotNull List getText(Slot slot) { - switch (slot.id) { + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + switch (slotId) { case 12, 29, 30, 31, 32, 33 -> { - Matcher matcher = LEVEL_PATTERN.matcher(slot.getStack().getName().getString()); + Matcher matcher = LEVEL_PATTERN.matcher(stack.getName().getString()); if (!matcher.matches()) return List.of(); String arabic = matcher.group("arabic"); String roman = matcher.group("roman"); @@ -53,17 +54,17 @@ public Dungeoneering() { } } - public static class DungeonClasses extends SlotTextAdder { + public static class DungeonClasses extends SimpleSlotTextAdder { public DungeonClasses() { super("^Dungeon Classes"); //Applies to both screens as they are same in both the placement and the style of the level text. } @Override - public @NotNull List getText(Slot slot) { - switch (slot.id) { + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + switch (slotId) { case 11, 12, 13, 14, 15 -> { - String level = getBracketedLevelFromName(slot.getStack()); + String level = getBracketedLevelFromName(stack); if (!NumberUtils.isDigits(level)) return List.of(); return List.of(SlotText.bottomLeft(Text.literal(level).withColor(0xFFDDC1))); } @@ -74,17 +75,17 @@ public DungeonClasses() { } } - public static class ReadyUp extends SlotTextAdder { + public static class ReadyUp extends SimpleSlotTextAdder { public ReadyUp() { super("^Ready Up"); } @Override - public @NotNull List getText(Slot slot) { - switch (slot.id) { + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + switch (slotId) { case 29, 30, 31, 32, 33 -> { - String level = getBracketedLevelFromName(slot.getStack()); + String level = getBracketedLevelFromName(stack); if (!NumberUtils.isDigits(level)) return List.of(); return List.of(SlotText.bottomLeft(Text.literal(level).withColor(0xFFDDC1))); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CollectionAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CollectionAdder.java index d6ced22a36..66d7f6e1e5 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CollectionAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CollectionAdder.java @@ -1,19 +1,20 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RomanNumerals; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class CollectionAdder extends SlotTextAdder { +public class CollectionAdder extends SimpleSlotTextAdder { private static final Pattern COLLECTION = Pattern.compile("^[\\w ]+ (?[IVXLCDM]+)$"); public CollectionAdder() { @@ -21,8 +22,7 @@ public CollectionAdder() { } @Override - public @NotNull List getText(Slot slot) { - final ItemStack stack = slot.getStack(); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { Matcher matcher = COLLECTION.matcher(stack.getName().getString()); if (matcher.matches()) { int level = RomanNumerals.romanToDecimal(matcher.group("level")); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CommunityShopAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CommunityShopAdder.java index d94d640540..4450c0b3a3 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CommunityShopAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/CommunityShopAdder.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RomanNumerals; import net.minecraft.item.ItemStack; @@ -10,51 +10,50 @@ import net.minecraft.text.Text; import net.minecraft.util.Formatting; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; -public class CommunityShopAdder extends SlotTextAdder { +public class CommunityShopAdder extends SimpleSlotTextAdder { private static final byte CATEGORIES_START = 10; private static final byte CATEGORIES_END = 14; //Inclusive + private static byte currentScreen = -1; // 0 = city projects, 1 = upgrades, 2 = booster cookie, 3 = bits shop, 4 = fire sales, any other number = invalid public CommunityShopAdder() { super("^Community Shop"); } @Override - public @NotNull List getText(Slot slot) { - for (byte i = CATEGORIES_START; i <= CATEGORIES_END; i++) { - if (slot.inventory.getStack(i).isOf(Items.LIME_STAINED_GLASS_PANE)) { //Only the selected category has a lime stained glass pane, the others have a gray one. - return switch (i) { //This is a switch to allow adding more categories easily in the future, if we ever add more. - case 11 -> getTextForUpgradesScreen(slot); - default -> List.of(); - }; - } + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (slotId >= CATEGORIES_START && slotId <= CATEGORIES_END && stack.isOf(Items.LIME_STAINED_GLASS_PANE)) { //Only the selected category has a lime stained glass pane, the others have a gray one. + currentScreen = (byte) (slotId - CATEGORIES_START); + return List.of(); } - return List.of(); + return switch (currentScreen) { //This is a switch statement to allow easily adding other categories in the future. + case 1 -> getTextForUpgradesScreen(stack, slotId); + default -> List.of(); + }; } - private static List getTextForUpgradesScreen(Slot slot) { - final ItemStack stack = slot.getStack(); - switch (slot.id) { - case 30, 31, 32, 33, 34, 38, 39, 40, 41, 42, 43, 44 -> { + private static List getTextForUpgradesScreen(ItemStack stack, int slotId) { + return switch (slotId) { + case 30, 31, 32, 33, 34, 38, 39, 40, 41, 42, 43, 44 -> { String name = stack.getName().getString(); int lastIndex = name.lastIndexOf(' '); String roman = name.substring(lastIndex + 1); // + 1 as we don't want the space - if (!RomanNumerals.isValidRomanNumeral(roman)) return List.of(); + if (!RomanNumerals.isValidRomanNumeral(roman)) yield List.of(); List lore = ItemUtils.getLore(stack); - if (lore.isEmpty()) return List.of(); + if (lore.isEmpty()) yield List.of(); String lastLine = lore.getLast().getString(); - return List.of(SlotText.bottomLeft(switch (lastLine) { + yield List.of(SlotText.bottomLeft(switch (lastLine) { case "Maxed out!" -> Text.literal("Max").withColor(0xfab387); case "Currently upgrading!", "Click to instantly upgrade!" -> Text.literal("⏰").withColor(0xf9e2af).formatted(Formatting.BOLD); case "Click to claim!" -> Text.literal("✅").withColor(0xa6e3a1).formatted(Formatting.BOLD); default -> Text.literal(String.valueOf(RomanNumerals.romanToDecimal(roman))).withColor(0xcba6f7); })); - } - } - return List.of(); + default -> List.of(); + }; } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EnchantmentLevelAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EnchantmentLevelAdder.java index 5530035d21..b4f89cdd6f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EnchantmentLevelAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EnchantmentLevelAdder.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RomanNumerals; import net.minecraft.item.ItemStack; @@ -10,23 +10,22 @@ import net.minecraft.nbt.NbtElement; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; -public class EnchantmentLevelAdder extends SlotTextAdder { +public class EnchantmentLevelAdder extends SimpleSlotTextAdder { public EnchantmentLevelAdder() { super(); } @Override - public @NotNull List getText(Slot slot) { - final ItemStack itemStack = slot.getStack(); - if (!itemStack.isOf(Items.ENCHANTED_BOOK)) return List.of(); - String name = itemStack.getName().getString(); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (!stack.isOf(Items.ENCHANTED_BOOK)) return List.of(); + String name = stack.getName().getString(); if (name.equals("Enchanted Book")) { - NbtCompound nbt = ItemUtils.getCustomData(itemStack); + NbtCompound nbt = ItemUtils.getCustomData(stack); if (nbt.isEmpty() || !nbt.contains("enchantments", NbtElement.COMPOUND_TYPE)) return List.of(); NbtCompound enchantments = nbt.getCompound("enchantments"); if (enchantments.getSize() != 1) return List.of(); //Only makes sense to display the level when there's one enchant. diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EssenceShopAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EssenceShopAdder.java index 65574a5a74..ec0eb346b1 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EssenceShopAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EssenceShopAdder.java @@ -1,13 +1,14 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RomanNumerals; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.text.NumberFormat; import java.util.List; @@ -15,7 +16,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class EssenceShopAdder extends SlotTextAdder { +public class EssenceShopAdder extends SimpleSlotTextAdder { private static final Pattern ESSENCELEVEL = Pattern.compile("^[\\w ]+ (?[IVXLCDM]+)$"); private static final Pattern UNLOCKED = Pattern.compile("UNLOCKED"); private static final Pattern ESSENCE = Pattern.compile("Your \\w+ Essence: (?[\\d,]+)"); @@ -25,9 +26,7 @@ public EssenceShopAdder() { } @Override - public @NotNull List getText(Slot slot) { - final ItemStack stack = slot.getStack(); - + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { Matcher essenceLevelMatcher = ESSENCELEVEL.matcher(stack.getName().getString()); Matcher essenceAmountMatcher = ItemUtils.getLoreLineIfMatch(stack, ESSENCE); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/MinionLevelAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/MinionLevelAdder.java index fc46f15305..b54e6c7376 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/MinionLevelAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/MinionLevelAdder.java @@ -1,30 +1,29 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.RomanNumerals; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class MinionLevelAdder extends SlotTextAdder { +public class MinionLevelAdder extends SimpleSlotTextAdder { private static final Pattern MINION_PATTERN = Pattern.compile(".* Minion ([IVXLCDM]+)"); public MinionLevelAdder() { super(); } @Override - public @NotNull List getText(Slot slot) { - ItemStack itemStack = slot.getStack(); - if (!itemStack.isOf(Items.PLAYER_HEAD)) return List.of(); - Matcher matcher = MINION_PATTERN.matcher(itemStack.getName().getString()); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (!stack.isOf(Items.PLAYER_HEAD)) return List.of(); + Matcher matcher = MINION_PATTERN.matcher(stack.getName().getString()); if (!matcher.matches()) return List.of(); String romanNumeral = matcher.group(1); if (!RomanNumerals.isValidRomanNumeral(romanNumeral)) return List.of(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PetLevelAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PetLevelAdder.java index 3049cd3f54..fbacc65c5b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PetLevelAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PetLevelAdder.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -9,21 +9,21 @@ import net.minecraft.text.Text; import org.apache.commons.lang3.math.NumberUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; -public class PetLevelAdder extends SlotTextAdder { +public class PetLevelAdder extends SimpleSlotTextAdder { public PetLevelAdder() { super(); } @Override - public @NotNull List getText(Slot slot) { - ItemStack itemStack = slot.getStack(); - if (!itemStack.isOf(Items.PLAYER_HEAD)) return List.of(); - String level = CatacombsLevelAdder.getBracketedLevelFromName(itemStack); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (!stack.isOf(Items.PLAYER_HEAD)) return List.of(); + String level = CatacombsLevelAdder.getBracketedLevelFromName(stack); if (!NumberUtils.isDigits(level) || "100".equals(level) || "200".equals(level)) return List.of(); - if (!ItemUtils.getItemId(itemStack).equals("PET")) return List.of(); + if (!ItemUtils.getItemId(stack).equals("PET")) return List.of(); return List.of(SlotText.topLeft(Text.literal(level).withColor(0xFFDDC1))); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PotionLevelAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PotionLevelAdder.java index 1c3ef4bc06..e229bc573b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PotionLevelAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PotionLevelAdder.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; @@ -9,18 +9,18 @@ import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; -public class PotionLevelAdder extends SlotTextAdder { +public class PotionLevelAdder extends SimpleSlotTextAdder { @Override - public @NotNull List getText(Slot slot) { - final ItemStack stack = slot.getStack(); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { NbtCompound customData = ItemUtils.getCustomData(stack); String title = stack.getName().getString(); if (customData.contains("potion_level", NbtElement.INT_TYPE) && !title.contains("Healer Class") && !title.contains("Class Passives")) { if (title.contains("Healer Level ")){ - String level = title.replaceAll("[^0-9]", ""); + String level = title.replaceAll("\\D", ""); return List.of(SlotText.bottomRight(Text.literal(level).withColor(0xFFFFFF))); } else { int level = customData.getInt("potion_level"); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PowerStonesGuideAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PowerStonesGuideAdder.java index 0bb3716528..e3ee5eda89 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PowerStonesGuideAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PowerStonesGuideAdder.java @@ -1,18 +1,19 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class PowerStonesGuideAdder extends SlotTextAdder { +public class PowerStonesGuideAdder extends SimpleSlotTextAdder { private static final Pattern LEARNED = Pattern.compile("Learned: (Yes|Not Yet) (?[✖✔])"); public PowerStonesGuideAdder() { @@ -20,18 +21,13 @@ public PowerStonesGuideAdder() { } @Override - public @NotNull List getText(Slot slot) { - final ItemStack stack = slot.getStack(); - + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { Matcher match = ItemUtils.getLoreLineIfMatch(stack, LEARNED); if (match == null) return List.of(); String symbol = match.group("symbol"); - Text text; - if (symbol.equals("✖")) { - text = Text.literal("✖").withColor(0xFF7276); - } else { - text = Text.literal("✔").withColor(0x90ee90); - } + Text text = symbol.equals("✖") + ? Text.literal("✖").withColor(0xFF7276) + : Text.literal("✔").withColor(0x90ee90); return List.of(SlotText.bottomRight(text)); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PrehistoricEggAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PrehistoricEggAdder.java index ce29297eba..87781e1e24 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PrehistoricEggAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/PrehistoricEggAdder.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -9,26 +9,25 @@ import net.minecraft.nbt.NbtElement; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; -public class PrehistoricEggAdder extends SlotTextAdder { +public class PrehistoricEggAdder extends SimpleSlotTextAdder { @Override - public @NotNull List getText(Slot slot) { - final ItemStack stack = slot.getStack(); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { if (!stack.isOf(Items.PLAYER_HEAD) || !StringUtils.equals(stack.getSkyblockId(), "PREHISTORIC_EGG")) return List.of(); NbtCompound nbt = ItemUtils.getCustomData(stack); if (!nbt.contains("blocks_walked", NbtElement.INT_TYPE)) return List.of(); int walked = nbt.getInt("blocks_walked"); - String walkedstr; - if (walked < 1000) walkedstr = String.valueOf(walked); - else if (walked < 10000) walkedstr = String.format("%.1fk", walked/1000.0f); - else walkedstr = walked / 1000 + "k"; + String walkedStr; + if (walked < 1000) walkedStr = String.valueOf(walked); + else if (walked < 10000) walkedStr = String.format("%.1fk", walked/1000.0f); + else walkedStr = walked / 1000 + "k"; - return List.of(SlotText.bottomLeft(Text.literal(walkedstr).withColor(0xFFDDC1))); + return List.of(SlotText.bottomLeft(Text.literal(walkedStr).withColor(0xFFDDC1))); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/RancherBootsSpeedAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/RancherBootsSpeedAdder.java index 7de5a5be3c..b34e67c11e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/RancherBootsSpeedAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/RancherBootsSpeedAdder.java @@ -1,21 +1,21 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; -import net.minecraft.util.Formatting; import org.apache.commons.lang3.StringUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class RancherBootsSpeedAdder extends SlotTextAdder { +public class RancherBootsSpeedAdder extends SimpleSlotTextAdder { private static final Pattern SPEED_PATTERN = Pattern.compile("Current Speed Cap: (\\d+) ?(\\d+)?"); public RancherBootsSpeedAdder() { @@ -23,11 +23,10 @@ public RancherBootsSpeedAdder() { } @Override - public @NotNull List getText(Slot slot) { - final ItemStack itemStack = slot.getStack(); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { // V null-safe equals. - if (!itemStack.isOf(Items.LEATHER_BOOTS) && !StringUtils.equals(itemStack.getSkyblockId(), "RANCHERS_BOOTS")) return List.of(); - Matcher matcher = ItemUtils.getLoreLineIfMatch(slot.getStack(), SPEED_PATTERN); + if (!stack.isOf(Items.LEATHER_BOOTS) && !StringUtils.equals(stack.getSkyblockId(), "RANCHERS_BOOTS")) return List.of(); + Matcher matcher = ItemUtils.getLoreLineIfMatch(stack, SPEED_PATTERN); if (matcher == null) return List.of(); String speed = matcher.group(2); if (speed == null) speed = matcher.group(1); //2nd group only matches when the speed cap is set to a number beyond the player's actual speed cap. diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/SkillLevelAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/SkillLevelAdder.java index 18dbd2f796..5ffce34ad4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/SkillLevelAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/SkillLevelAdder.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RomanNumerals; import net.minecraft.item.ItemStack; @@ -9,20 +9,20 @@ import net.minecraft.text.Text; import net.minecraft.util.Formatting; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; -public class SkillLevelAdder extends SlotTextAdder { +public class SkillLevelAdder extends SimpleSlotTextAdder { public SkillLevelAdder() { super("^Your Skills"); } @Override - public @NotNull List getText(Slot slot) { - switch (slot.id) { + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + switch (slotId) { case 19, 20, 21, 22, 23, 24, 25, 29, 30, 31, 32 -> { //These are the slots that contain the skill items. Note that they aren't continuous, as there are 2 rows. - String name = slot.getStack().getName().getString(); - final ItemStack stack = slot.getStack(); + String name = stack.getName().getString(); int lastIndex = name.lastIndexOf(' '); if (lastIndex == -1) return List.of(SlotText.bottomLeft(Text.literal("0").formatted(Formatting.LIGHT_PURPLE))); //Skills without any levels don't display any roman numerals. Probably because 0 doesn't exist. String romanNumeral = name.substring(lastIndex + 1); //+1 because we don't need the space itself diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/SkyblockLevelAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/SkyblockLevelAdder.java index 0fc07922fc..aa7b577ef4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/SkyblockLevelAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/SkyblockLevelAdder.java @@ -1,24 +1,26 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; +import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.apache.commons.lang3.math.NumberUtils; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; -public class SkyblockLevelAdder extends SlotTextAdder { +public class SkyblockLevelAdder extends SimpleSlotTextAdder { public SkyblockLevelAdder() { super("^SkyBlock Menu"); } @Override - public @NotNull List getText(Slot slot) { - if (slot.getIndex() != 22) return List.of(); - List lore = ItemUtils.getLore(slot.getStack()); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (slotId != 22) return List.of(); + List lore = ItemUtils.getLore(stack); if (lore.isEmpty()) return List.of(); List siblings = lore.getFirst().getSiblings(); if (siblings.size() < 3) return List.of(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/StatsTuningAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/StatsTuningAdder.java index 3079d8f2c6..5c175b1ba4 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/StatsTuningAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/StatsTuningAdder.java @@ -1,18 +1,19 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; -public class StatsTuningAdder extends SlotTextAdder { +public class StatsTuningAdder extends SimpleSlotTextAdder { private static final Pattern STATHAS = Pattern.compile("Stat has: (?\\d+) (points|point)"); private static final Pattern UNASSIGNEDPOINTS = Pattern.compile("Unassigned Points: (?\\d+)!!!"); @@ -21,9 +22,7 @@ public StatsTuningAdder() { } @Override - public @NotNull List getText(Slot slot) { - final ItemStack stack = slot.getStack(); - + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { Matcher statMatcher = ItemUtils.getLoreLineIfMatch(stack, STATHAS); Matcher unassignedMatcher = ItemUtils.getLoreLineIfMatch(stack, UNASSIGNEDPOINTS); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/YourEssenceAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/YourEssenceAdder.java index ec1bd561d4..98dd98073f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/YourEssenceAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/YourEssenceAdder.java @@ -1,12 +1,13 @@ package de.hysky.skyblocker.skyblock.item.slottext.adders; import de.hysky.skyblocker.skyblock.item.slottext.SlotText; -import de.hysky.skyblocker.skyblock.item.slottext.SlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.text.NumberFormat; import java.util.List; @@ -14,7 +15,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class YourEssenceAdder extends SlotTextAdder { +public class YourEssenceAdder extends SimpleSlotTextAdder { private static final Pattern ESSENCE = Pattern.compile("You currently own (?[\\d,]+)"); public YourEssenceAdder() { @@ -22,8 +23,7 @@ public YourEssenceAdder() { } @Override - public @NotNull List getText(Slot slot) { - final ItemStack stack = slot.getStack(); + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { String name = stack.getName().getString(); if (name.contains("Essence")) { List lore = ItemUtils.getLore(stack); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/BackpackPreview.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/BackpackPreview.java index cad1eaaba7..3fb52b3a84 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/BackpackPreview.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/BackpackPreview.java @@ -7,6 +7,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.item.ItemProtection; import de.hysky.skyblocker.skyblock.item.ItemRarityBackgrounds; +import de.hysky.skyblocker.skyblock.item.slottext.SlotTextManager; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.Utils; import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; @@ -15,7 +16,6 @@ import net.minecraft.client.gui.DrawContext; import net.minecraft.client.gui.screen.Screen; import net.minecraft.client.gui.screen.ingame.HandledScreen; -import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.util.math.MatrixStack; import net.minecraft.inventory.Inventory; import net.minecraft.inventory.SimpleInventory; @@ -50,6 +50,8 @@ public class BackpackPreview { private static final Storage[] storages = new Storage[STORAGE_SIZE]; + private BackpackPreview() {} + /** * The profile id of the currently loaded backpack preview. */ @@ -119,7 +121,7 @@ private static void saveStorage(int index) { writer.write(new StringNbtWriter().apply(Storage.CODEC.encodeStart(getOps(), storages[index]).getOrThrow())); storages[index].markClean(); } catch (Exception e) { - LOGGER.error("Failed to save backpack preview file: {}", storageFile.getFileName().toString(), e); + LOGGER.error("Failed to save backpack preview file: {}", storageFile.getFileName(), e); } } @@ -171,6 +173,7 @@ public static boolean renderPreview(DrawContext context, Screen screen, int inde context.drawItem(currentStack, itemX, itemY); context.drawItemInSlot(textRenderer, currentStack, itemX, itemY); + SlotTextManager.renderSlotText(context, textRenderer, null, currentStack, i, itemX, itemY); } matrices.pop(); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/SimpleTooltipAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/SimpleTooltipAdder.java new file mode 100644 index 0000000000..565fecbbea --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/SimpleTooltipAdder.java @@ -0,0 +1,57 @@ +package de.hysky.skyblocker.skyblock.item.tooltip; + +import de.hysky.skyblocker.utils.container.RegexContainerMatcher; +import de.hysky.skyblocker.utils.container.TooltipAdder; +import org.intellij.lang.annotations.Language; +import org.jetbrains.annotations.NotNull; + +import java.util.regex.Pattern; + +/** + * Simple implementation of a tooltip adder. + * Extend this class and add it to {@link TooltipManager#adders} to add additional text to tooltips. + */ +public abstract class SimpleTooltipAdder extends RegexContainerMatcher implements TooltipAdder { + /** + * The priority of this adder. Lower priority means it will be applied first. + * @apiNote Consider adding this as a parameter to your class' constructor and + * setting it from {@link TooltipManager#adders} to make it easy to read and maintain. + */ + private final int priority; + + /** + * Utility constructor that will compile the given string into a pattern. + * + * @see #SimpleTooltipAdder(Pattern, int) + */ + protected SimpleTooltipAdder(@NotNull @Language("RegExp") String titlePattern, int priority) { + super(titlePattern); + this.priority = priority; + } + + /** + * Creates a TooltipAdder that will be applied to screens with titles that match the given pattern. + * + * @param titlePattern The pattern to match the screen title against. + * @param priority The priority of this adder. Lower priority means it will be applied first. + */ + protected SimpleTooltipAdder(@NotNull Pattern titlePattern, int priority) { + super(titlePattern); + this.priority = priority; + } + + /** + * Creates a TooltipAdder that will be applied to all screens. + * + * @param priority The priority of this adder. Lower priority means it will be applied first. + */ + protected SimpleTooltipAdder(int priority) { + super(); + this.priority = priority; + } + + @Override + public int getPriority() { + return priority; + } +} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java deleted file mode 100644 index f3395def4f..0000000000 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipAdder.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.hysky.skyblocker.skyblock.item.tooltip; - -import de.hysky.skyblocker.utils.render.gui.AbstractContainerMatcher; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.slot.Slot; -import net.minecraft.text.Text; -import org.intellij.lang.annotations.Language; -import org.jetbrains.annotations.Nullable; - -import java.util.List; -import java.util.regex.Pattern; - -/** - * Extend this class and add it to {@link TooltipManager#adders} to add additional text to tooltips. - */ -public abstract class TooltipAdder extends AbstractContainerMatcher { - /** - * The priority of this adder. Lower priority means it will be applied first. - * @apiNote Consider taking this value on your class' constructor and setting it from {@link TooltipManager#adders} to make it easy to read and maintain. - */ - public final int priority; - - protected TooltipAdder(@Language("RegExp") String titlePattern, int priority) { - super(titlePattern); - this.priority = priority; - } - - protected TooltipAdder(Pattern titlePattern, int priority) { - super(titlePattern); - this.priority = priority; - } - - /** - * Creates a TooltipAdder that will be applied to all screens. - */ - protected TooltipAdder(int priority) { - super(); - this.priority = priority; - } - - /** - * @implNote The first element of the lines list holds the item's display name, - * as it's a list of all lines that will be displayed in the tooltip. - */ - public abstract void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines); -} diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipInfoType.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipInfoType.java index 46f4cb589f..d8327383fc 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipInfoType.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipInfoType.java @@ -117,16 +117,6 @@ public boolean hasOrNullWarning(String memberName) { } else return data.has(memberName); } - /** - * Checks if the tooltip is enabled and the data has the given member name and sends a warning message if data is null. - * - * @param memberName the member name to check - * @return whether the tooltip is enabled and the data has the given member name or not - */ - public boolean isTooltipEnabledAndHasOrNullWarning(String memberName) { - return isTooltipEnabled() && hasOrNullWarning(memberName); - } - /** * Downloads the data if it is enabled. * diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java index c3399b58f7..ce40d06c31 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/TooltipManager.java @@ -4,8 +4,8 @@ import de.hysky.skyblocker.skyblock.bazaar.ReorderHelper; 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; @@ -24,8 +24,8 @@ public class TooltipManager { private static final TooltipAdder[] adders = new TooltipAdder[]{ new LineSmoothener(), // Applies before anything else new SupercraftReminder(), - new ChocolateFactorySolver.Tooltip(), - new ReorderHelper.Tooltip(), + new ChocolateFactorySolver(), + new ReorderHelper(), new NpcPriceTooltip(1), new BazaarPriceTooltip(2), new LBinTooltip(3), @@ -59,14 +59,13 @@ public static void init() { } private static void onScreenChange(Screen screen) { - final String title = screen.getTitle().getString(); currentScreenAdders.clear(); for (TooltipAdder adder : adders) { - if (adder.titlePattern == null || adder.titlePattern.matcher(title).find()) { + if (adder.isEnabled() && adder.test(screen)) { currentScreenAdders.add(adder); } } - currentScreenAdders.sort(Comparator.comparingInt(adder -> adder.priority)); + currentScreenAdders.sort(Comparator.comparingInt(TooltipAdder::getPriority)); } /** diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AccessoryTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AccessoryTooltip.java index caed0e0e40..a5e135013e 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AccessoryTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AccessoryTooltip.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; import de.hysky.skyblocker.skyblock.item.tooltip.AccessoriesHelper; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import it.unimi.dsi.fastutil.Pair; import net.minecraft.item.ItemStack; @@ -13,7 +13,7 @@ import java.util.List; -public class AccessoryTooltip extends TooltipAdder { +public class AccessoryTooltip extends SimpleTooltipAdder { public AccessoryTooltip(int priority) { super(priority); } @@ -21,7 +21,7 @@ public AccessoryTooltip(int priority) { @Override public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { final String internalID = stack.getSkyblockId(); - if (TooltipInfoType.ACCESSORIES.isTooltipEnabledAndHasOrNullWarning(internalID)) { + if (TooltipInfoType.ACCESSORIES.hasOrNullWarning(internalID)) { Pair report = AccessoriesHelper.calculateReport4Accessory(internalID); if (report.left() != AccessoriesHelper.AccessoryReport.INELIGIBLE) { @@ -42,4 +42,9 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List } } } + + @Override + public boolean isEnabled() { + return TooltipInfoType.ACCESSORIES.isTooltipEnabled(); + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AvgBinTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AvgBinTooltip.java index d7a56b9535..e81879af52 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AvgBinTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/AvgBinTooltip.java @@ -1,9 +1,8 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; -import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.config.configs.GeneralConfig; import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -13,7 +12,7 @@ import java.util.List; -public class AvgBinTooltip extends TooltipAdder { +public class AvgBinTooltip extends SimpleTooltipAdder { public AvgBinTooltip(int priority) { super(priority); } @@ -24,40 +23,44 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List String internalID = stack.getSkyblockId(); if (neuName == null || internalID == null) return; - if (SkyblockerConfigManager.get().general.itemTooltip.enableAvgBIN) { - if (TooltipInfoType.ONE_DAY_AVERAGE.getData() == null || TooltipInfoType.THREE_DAY_AVERAGE.getData() == null) { - ItemTooltip.nullWarning(); - } else { + if (TooltipInfoType.ONE_DAY_AVERAGE.getData() == null || TooltipInfoType.THREE_DAY_AVERAGE.getData() == null) { + ItemTooltip.nullWarning(); + } else { /* We are skipping check average prices for potions, runes and enchanted books because there is no data for their in API. */ - if (!neuName.isEmpty() && LBinTooltip.lbinExist) { - GeneralConfig.Average type = ItemTooltip.config.avg; + if (!neuName.isEmpty() && LBinTooltip.lbinExist) { + GeneralConfig.Average type = ItemTooltip.config.avg; - // "No data" line because of API not keeping old data, it causes NullPointerException - if (type == GeneralConfig.Average.ONE_DAY || type == GeneralConfig.Average.BOTH) { - lines.add( - Text.literal(String.format("%-19s", "1 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(TooltipInfoType.ONE_DAY_AVERAGE.getData().get(neuName) == null - ? Text.literal("No data").formatted(Formatting.RED) - : ItemTooltip.getCoinsMessage(TooltipInfoType.ONE_DAY_AVERAGE.getData().get(neuName).getAsDouble(), stack.getCount()) - ) - ); - } - if (type == GeneralConfig.Average.THREE_DAY || type == GeneralConfig.Average.BOTH) { - lines.add( - Text.literal(String.format("%-19s", "3 Day Avg. Price:")) - .formatted(Formatting.GOLD) - .append(TooltipInfoType.THREE_DAY_AVERAGE.getData().get(neuName) == null - ? Text.literal("No data").formatted(Formatting.RED) - : ItemTooltip.getCoinsMessage(TooltipInfoType.THREE_DAY_AVERAGE.getData().get(neuName).getAsDouble(), stack.getCount()) - ) - ); - } + // "No data" line because of API not keeping old data, it causes NullPointerException + if (type == GeneralConfig.Average.ONE_DAY || type == GeneralConfig.Average.BOTH) { + lines.add( + Text.literal(String.format("%-19s", "1 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(TooltipInfoType.ONE_DAY_AVERAGE.getData().get(neuName) == null + ? Text.literal("No data").formatted(Formatting.RED) + : ItemTooltip.getCoinsMessage(TooltipInfoType.ONE_DAY_AVERAGE.getData().get(neuName).getAsDouble(), stack.getCount()) + ) + ); + } + if (type == GeneralConfig.Average.THREE_DAY || type == GeneralConfig.Average.BOTH) { + lines.add( + Text.literal(String.format("%-19s", "3 Day Avg. Price:")) + .formatted(Formatting.GOLD) + .append(TooltipInfoType.THREE_DAY_AVERAGE.getData().get(neuName) == null + ? Text.literal("No data").formatted(Formatting.RED) + : ItemTooltip.getCoinsMessage(TooltipInfoType.THREE_DAY_AVERAGE.getData().get(neuName).getAsDouble(), stack.getCount()) + ) + ); } } } } + + @Override + public boolean isEnabled() { + //Both 1 day and 3 day averages use the same config option, so we only need to check one + return TooltipInfoType.THREE_DAY_AVERAGE.isTooltipEnabled(); + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/BazaarPriceTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/BazaarPriceTooltip.java index d2fa563bd2..658c50a9e3 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/BazaarPriceTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/BazaarPriceTooltip.java @@ -2,7 +2,7 @@ import com.google.gson.JsonObject; import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -13,7 +13,7 @@ import java.util.List; -public class BazaarPriceTooltip extends TooltipAdder { +public class BazaarPriceTooltip extends SimpleTooltipAdder { public static boolean bazaarExist = false; public BazaarPriceTooltip(int priority) { @@ -30,7 +30,7 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List if (name.startsWith("ISSHINY_")) name = "SHINY_" + internalID; - if (TooltipInfoType.BAZAAR.isTooltipEnabledAndHasOrNullWarning(name)) { + if (TooltipInfoType.BAZAAR.hasOrNullWarning(name)) { int amount; if (lines.get(1).getString().endsWith("Sack")) { //The amount is in the 2nd sibling of the 3rd line of the lore. here V @@ -54,4 +54,9 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List bazaarExist = true; } } + + @Override + public boolean isEnabled() { + return TooltipInfoType.BAZAAR.isTooltipEnabled(); + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/ColorTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/ColorTooltip.java index 7546d37ae0..8d9d8fbb14 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/ColorTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/ColorTooltip.java @@ -1,6 +1,6 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import de.hysky.skyblocker.utils.Constants; import de.hysky.skyblocker.utils.ItemUtils; @@ -18,17 +18,22 @@ import java.util.List; -public class ColorTooltip extends TooltipAdder { +public class ColorTooltip extends SimpleTooltipAdder { private static final Logger LOGGER = LoggerFactory.getLogger(ColorTooltip.class); public ColorTooltip(int priority) { super(priority); } + @Override + public boolean isEnabled() { + return TooltipInfoType.COLOR.isTooltipEnabled(); + } + @Override public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { final String internalID = stack.getSkyblockId(); - if (TooltipInfoType.COLOR.isTooltipEnabledAndHasOrNullWarning(internalID) && stack.contains(DataComponentTypes.DYED_COLOR)) { + if (TooltipInfoType.COLOR.hasOrNullWarning(internalID) && stack.contains(DataComponentTypes.DYED_COLOR)) { //DyedColorComponent#getColor can be ARGB so we mask out the alpha bits int dyeColor = stack.get(DataComponentTypes.DYED_COLOR).rgb() & 0x00FFFFFF; String colorHex = String.format("%06X", dyeColor); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/CraftPriceTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/CraftPriceTooltip.java index f7af446eb0..20b6b9623f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/CraftPriceTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/CraftPriceTooltip.java @@ -3,7 +3,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.config.configs.GeneralConfig; import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import de.hysky.skyblocker.utils.NEURepoManager; import io.github.moulberry.repo.data.NEUIngredient; @@ -18,12 +18,11 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; -public class CraftPriceTooltip extends TooltipAdder { +public class CraftPriceTooltip extends SimpleTooltipAdder { protected static final Logger LOGGER = LoggerFactory.getLogger(CraftPriceTooltip.class.getName()); private static final Map cachedCraftCosts = new ConcurrentHashMap<>(); private static final int MAX_RECURSION_DEPTH = 15; @@ -34,8 +33,6 @@ public CraftPriceTooltip(int priority) { @Override public void addToTooltip(@Nullable Slot focusedSloFt, ItemStack stack, List lines) { - if (SkyblockerConfigManager.get().general.itemTooltip.enableCraftingCost == GeneralConfig.Craft.OFF) return; - String internalID = stack.getSkyblockId(); if (stack.getNeuName() == null || internalID == null) return; @@ -112,4 +109,9 @@ private double getItemCost(NEURecipe recipe, int depth) { public static void clearCache() { cachedCraftCosts.clear(); } + + @Override + public boolean isEnabled() { + return SkyblockerConfigManager.get().general.itemTooltip.enableCraftingCost != GeneralConfig.Craft.OFF; + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/DungeonQualityTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/DungeonQualityTooltip.java index 0b1d993d40..f6efc2f2af 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/DungeonQualityTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/DungeonQualityTooltip.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NbtCompound; @@ -12,14 +12,13 @@ import java.util.List; -public class DungeonQualityTooltip extends TooltipAdder { +public class DungeonQualityTooltip extends SimpleTooltipAdder { public DungeonQualityTooltip(int priority) { super(priority); } @Override public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { - if (!SkyblockerConfigManager.get().general.itemTooltip.dungeonQuality) return; NbtCompound customData = ItemUtils.getCustomData(stack); if (customData == null || !customData.contains("baseStatBoostPercentage")) return; int baseStatBoostPercentage = customData.getInt("baseStatBoostPercentage"); @@ -40,7 +39,7 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List } } - final String getItemTierFloor(int tier) { + private String getItemTierFloor(int tier) { return switch (tier) { case 0 -> "E"; case 1 -> "F1"; @@ -56,4 +55,9 @@ final String getItemTierFloor(int tier) { default -> "Unknown"; }; } + + @Override + public boolean isEnabled() { + return SkyblockerConfigManager.get().general.itemTooltip.dungeonQuality; + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java index 5a7051d3cf..bc478d5050 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/EssenceShopPrice.java @@ -3,7 +3,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.utils.ItemUtils; import de.hysky.skyblocker.utils.RegexUtils; import it.unimi.dsi.fastutil.objects.Object2LongArrayMap; @@ -20,7 +20,7 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -public class EssenceShopPrice extends TooltipAdder { +public class EssenceShopPrice extends SimpleTooltipAdder { private static final Pattern ESSENCE_PATTERN = Pattern.compile("Cost (?[\\d,]+) (?[A-Za-z]+) Essence"); private static final NumberFormat DECIMAL_FORMAT = NumberFormat.getInstance(Locale.US); private static final String[] ESSENCE_TYPES = {"WITHER", "SPIDER", "UNDEAD", "DRAGON", "GOLD", "DIAMOND", "ICE", "CRIMSON"}; @@ -45,8 +45,6 @@ public static void refreshEssencePrices(JsonObject data) { //Todo: maybe move the price value right after the essence amount ex: "1,500 Wither Essence (645k coins)" @Override public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { - if (!SkyblockerConfigManager.get().general.itemTooltip.showEssenceCost) return; - String lore = ItemUtils.concatenateLore(lines); Matcher essenceMatcher = ESSENCE_PATTERN.matcher(lore); OptionalLong cost = RegexUtils.getLongFromMatcher(essenceMatcher); @@ -64,4 +62,9 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List .append(Text.literal(")").formatted(Formatting.GRAY)) ); } + + @Override + public boolean isEnabled() { + return SkyblockerConfigManager.get().general.itemTooltip.showEssenceCost; + } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/LBinTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/LBinTooltip.java index e6930c32bd..aa90bf09b2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/LBinTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/LBinTooltip.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -11,13 +11,18 @@ import java.util.List; -public class LBinTooltip extends TooltipAdder { +public class LBinTooltip extends SimpleTooltipAdder { public static boolean lbinExist = false; public LBinTooltip(int priority) { super(priority); } + @Override + public boolean isEnabled() { + return TooltipInfoType.LOWEST_BINS.isTooltipEnabled(); + } + @Override public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { lbinExist = false; @@ -30,7 +35,7 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List // bazaarOpened & bazaarExist check for lbin, because Skytils keeps some bazaar item data in lbin api - if (TooltipInfoType.LOWEST_BINS.isTooltipEnabledAndHasOrNullWarning(name) && !BazaarPriceTooltip.bazaarExist) { + if (TooltipInfoType.LOWEST_BINS.hasOrNullWarning(name) && !BazaarPriceTooltip.bazaarExist) { lines.add(Text.literal(String.format("%-19s", "Lowest BIN Price:")) .formatted(Formatting.GOLD) .append(ItemTooltip.getCoinsMessage(TooltipInfoType.LOWEST_BINS.getData().get(name).getAsDouble(), stack.getCount()))); diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/LineSmoothener.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/LineSmoothener.java index 0e99783450..347abdadab 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/LineSmoothener.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/LineSmoothener.java @@ -1,6 +1,6 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; import net.minecraft.text.Text; @@ -9,7 +9,7 @@ import java.util.List; -public class LineSmoothener extends TooltipAdder { +public class LineSmoothener extends SimpleTooltipAdder { //This is static to not create a new text object for each line in every item private static final Text BUMPY_LINE = Text.literal("-----------------").formatted(Formatting.DARK_GRAY, Formatting.STRIKETHROUGH); @@ -17,6 +17,11 @@ public static Text createSmoothLine() { return Text.literal(" ").formatted(Formatting.DARK_GRAY, Formatting.STRIKETHROUGH, Formatting.BOLD); } + @Override + public boolean isEnabled() { + return true; + } + public LineSmoothener() { super(Integer.MIN_VALUE); } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MotesTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MotesTooltip.java index a0aa8d94eb..42348b781b 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MotesTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MotesTooltip.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -13,7 +13,7 @@ import java.util.List; import java.util.Locale; -public class MotesTooltip extends TooltipAdder { +public class MotesTooltip extends SimpleTooltipAdder { public MotesTooltip(int priority) { super(priority); } @@ -21,13 +21,18 @@ public MotesTooltip(int priority) { @Override public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { final String internalID = stack.getSkyblockId(); - if (internalID != null && TooltipInfoType.MOTES.isTooltipEnabledAndHasOrNullWarning(internalID)) { + if (internalID != null && TooltipInfoType.MOTES.hasOrNullWarning(internalID)) { lines.add(Text.literal(String.format("%-20s", "Motes Price:")) .formatted(Formatting.LIGHT_PURPLE) .append(getMotesMessage(TooltipInfoType.MOTES.getData().get(internalID).getAsInt(), stack.getCount()))); } } + @Override + public boolean isEnabled() { + return TooltipInfoType.MOTES.isTooltipEnabled(); + } + private static Text getMotesMessage(int price, int count) { float motesMultiplier = SkyblockerConfigManager.get().otherLocations.rift.mcGrubberStacks * 0.05f + 1; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MuseumTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MuseumTooltip.java index 5c21d2dfa4..6a53dbdb7f 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MuseumTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/MuseumTooltip.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; import de.hysky.skyblocker.skyblock.item.MuseumItemCache; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; @@ -13,15 +13,20 @@ import java.util.List; -public class MuseumTooltip extends TooltipAdder { +public class MuseumTooltip extends SimpleTooltipAdder { public MuseumTooltip(int priority) { super(priority); } + @Override + public boolean isEnabled() { + return TooltipInfoType.MUSEUM.isTooltipEnabled(); + } + @Override public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { final String internalID = stack.getSkyblockId(); - if (TooltipInfoType.MUSEUM.isTooltipEnabledAndHasOrNullWarning(internalID)) { + if (TooltipInfoType.MUSEUM.hasOrNullWarning(internalID)) { String itemCategory = TooltipInfoType.MUSEUM.getData().get(internalID).getAsString(); String format = switch (itemCategory) { case "Weapons" -> "%-18s"; diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/NpcPriceTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/NpcPriceTooltip.java index d556c9b2a1..17cb80e337 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/NpcPriceTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/NpcPriceTooltip.java @@ -1,7 +1,7 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; import de.hysky.skyblocker.skyblock.item.tooltip.ItemTooltip; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import net.minecraft.item.ItemStack; import net.minecraft.screen.slot.Slot; @@ -12,15 +12,20 @@ import java.util.List; -public class NpcPriceTooltip extends TooltipAdder { +public class NpcPriceTooltip extends SimpleTooltipAdder { public NpcPriceTooltip(int priority) { super(priority); } + @Override + public boolean isEnabled() { + return TooltipInfoType.NPC.isTooltipEnabled(); + } + @Override public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { final String internalID = stack.getSkyblockId(); - if (internalID != null && TooltipInfoType.NPC.isTooltipEnabledAndHasOrNullWarning(internalID)) { + if (internalID != null && TooltipInfoType.NPC.hasOrNullWarning(internalID)) { int amount; if (lines.get(1).getString().endsWith("Sack")) { //The amount is in the 2nd sibling of the 3rd line of the lore. here V diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/ObtainedDateTooltip.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/ObtainedDateTooltip.java index 9f405c58e2..31aa3de414 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/ObtainedDateTooltip.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/ObtainedDateTooltip.java @@ -1,6 +1,6 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.skyblock.item.tooltip.TooltipInfoType; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; @@ -18,7 +18,7 @@ import java.util.List; import java.util.Locale; -public class ObtainedDateTooltip extends TooltipAdder { +public class ObtainedDateTooltip extends SimpleTooltipAdder { private static final DateTimeFormatter OBTAINED_DATE_FORMATTER = DateTimeFormatter.ofPattern("MMMM d, yyyy").withZone(ZoneId.systemDefault()).localizedBy(Locale.ENGLISH); private static final DateTimeFormatter OLD_OBTAINED_DATE_FORMAT = DateTimeFormatter.ofPattern("M/d/yy h:m a").withZone(ZoneId.of("UTC")).localizedBy(Locale.ENGLISH); @@ -27,15 +27,17 @@ public ObtainedDateTooltip(int priority) { } @Override - public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { - if (TooltipInfoType.OBTAINED.isTooltipEnabled()) { - String timestamp = getTimestamp(stack); + public boolean isEnabled() { + return TooltipInfoType.OBTAINED.isTooltipEnabled(); + } - if (!timestamp.isEmpty()) { - lines.add(Text.empty() - .append(Text.literal(String.format("%-21s", "Obtained: ")).formatted(Formatting.LIGHT_PURPLE)) - .append(Text.literal(timestamp).formatted(Formatting.RED))); - } + @Override + public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines) { + String timestamp = getTimestamp(stack); + if (!timestamp.isEmpty()) { + lines.add(Text.empty() + .append(Text.literal(String.format("%-21s", "Obtained: ")).formatted(Formatting.LIGHT_PURPLE)) + .append(Text.literal(timestamp).formatted(Formatting.RED))); } } diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/SupercraftReminder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/SupercraftReminder.java index 47d2bd48d4..c34e165066 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/SupercraftReminder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/tooltip/adders/SupercraftReminder.java @@ -1,6 +1,6 @@ package de.hysky.skyblocker.skyblock.item.tooltip.adders; -import de.hysky.skyblocker.skyblock.item.tooltip.TooltipAdder; +import de.hysky.skyblocker.skyblock.item.tooltip.SimpleTooltipAdder; import de.hysky.skyblocker.utils.ItemUtils; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; @@ -12,7 +12,7 @@ import java.util.List; import java.util.regex.Pattern; -public class SupercraftReminder extends TooltipAdder { +public class SupercraftReminder extends SimpleTooltipAdder { private static final byte SUPERCRAFT_SLOT = 32; private static final byte RECIPE_RESULT_SLOT = 25; @@ -29,4 +29,9 @@ public void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List if (lines.get(lines.size() - 2).getString().equals("Recipe not unlocked!")) index--; //Place it right below the "Right-Click to set amount" line lines.add(index, Text.literal("Shift-Click to maximize the amount!").formatted(Formatting.GOLD)); } + + @Override + public boolean isEnabled() { + return true; + } } diff --git a/src/main/java/de/hysky/skyblocker/utils/Utils.java b/src/main/java/de/hysky/skyblocker/utils/Utils.java index 042095d1dd..4de32710ce 100644 --- a/src/main/java/de/hysky/skyblocker/utils/Utils.java +++ b/src/main/java/de/hysky/skyblocker/utils/Utils.java @@ -3,6 +3,7 @@ import com.google.gson.JsonObject; import com.google.gson.JsonParser; import com.mojang.util.UndashedUuid; +import de.hysky.skyblocker.debug.Debug; import de.hysky.skyblocker.events.SkyblockEvents; import de.hysky.skyblocker.mixins.accessors.MessageHandlerAccessor; import de.hysky.skyblocker.skyblock.item.MuseumItemCache; @@ -17,7 +18,6 @@ import net.azureaaron.hmapi.network.packet.s2c.HypixelS2CPacket; import net.azureaaron.hmapi.network.packet.v1.s2c.LocationUpdateS2CPacket; import net.fabricmc.fabric.api.client.message.v1.ClientReceiveMessageEvents; -import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.client.network.PlayerListEntry; @@ -239,9 +239,8 @@ public static void update() { public static void updatePlayerPresenceFromScoreboard(MinecraftClient client) { List sidebar = STRING_SCOREBOARD; - FabricLoader fabricLoader = FabricLoader.getInstance(); if (client.world == null || client.isInSingleplayer() || sidebar.isEmpty()) { - if (fabricLoader.isDevelopmentEnvironment()) { + if (Debug.debugEnabled()) { sidebar = Collections.emptyList(); } else { isOnSkyblock = false; @@ -249,13 +248,13 @@ public static void updatePlayerPresenceFromScoreboard(MinecraftClient client) { } } - if (sidebar.isEmpty() && !fabricLoader.isDevelopmentEnvironment()) return; + if (sidebar.isEmpty() && !Debug.debugEnabled()) return; - if (fabricLoader.isDevelopmentEnvironment() || isConnectedToHypixel(client)) { + if (Debug.debugEnabled() || isConnectedToHypixel(client)) { if (!isOnHypixel) { isOnHypixel = true; } - if (fabricLoader.isDevelopmentEnvironment() || sidebar.getFirst().contains("SKYBLOCK") || sidebar.getFirst().contains("SKIBLOCK")) { + if (Debug.debugEnabled() || sidebar.getFirst().contains("SKYBLOCK") || sidebar.getFirst().contains("SKIBLOCK")) { if (!isOnSkyblock) { if (!isInjected) { isInjected = true; diff --git a/src/main/java/de/hysky/skyblocker/utils/container/ContainerMatcher.java b/src/main/java/de/hysky/skyblocker/utils/container/ContainerMatcher.java new file mode 100644 index 0000000000..159f399e30 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/container/ContainerMatcher.java @@ -0,0 +1,20 @@ +package de.hysky.skyblocker.utils.container; + +import net.minecraft.client.gui.screen.Screen; +import org.jetbrains.annotations.NotNull; + +import java.util.function.Predicate; + +public interface ContainerMatcher extends Predicate { + /** + * 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 + */ + @Override + boolean test(@NotNull Screen screen); + + /** + * @return {@code true} if this matcher is enabled, {@code false} otherwise + */ + boolean isEnabled(); +} diff --git a/src/main/java/de/hysky/skyblocker/utils/container/ContainerSolver.java b/src/main/java/de/hysky/skyblocker/utils/container/ContainerSolver.java new file mode 100644 index 0000000000..c616204964 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/container/ContainerSolver.java @@ -0,0 +1,38 @@ +package de.hysky.skyblocker.utils.container; + +import de.hysky.skyblocker.SkyblockerMod; +import de.hysky.skyblocker.utils.Resettable; +import de.hysky.skyblocker.utils.render.gui.ColorHighlight; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import net.minecraft.client.gui.screen.ingame.GenericContainerScreen; +import net.minecraft.item.ItemStack; + +import java.util.List; + +public interface ContainerSolver extends ContainerMatcher, Resettable { + List getColors(Int2ObjectMap slots); + + default void start(GenericContainerScreen screen) {} + + @Override + default void reset() {} + + default boolean onClickSlot(int slot, ItemStack stack, int screenId) { + return false; + } + + static void markHighlightsDirty() { + SkyblockerMod.getInstance().containerSolverManager.markDirty(); + } + + static void trimEdges(Int2ObjectMap slots, int rows) { + for (int i = 0; i < rows; i++) { + slots.remove(9 * i); + slots.remove(9 * i + 8); + } + for (int i = 1; i < 8; i++) { + slots.remove(i); + slots.remove((rows - 1) * 9 + i); + } + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/container/ContainerSolverManager.java b/src/main/java/de/hysky/skyblocker/utils/container/ContainerSolverManager.java new file mode 100644 index 0000000000..b67b9edf8e --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/container/ContainerSolverManager.java @@ -0,0 +1,154 @@ +package de.hysky.skyblocker.utils.container; + +import com.mojang.blaze3d.systems.RenderSystem; +import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor; +import de.hysky.skyblocker.skyblock.accessories.newyearcakes.NewYearCakeBagHelper; +import de.hysky.skyblocker.skyblock.accessories.newyearcakes.NewYearCakesHelper; +import de.hysky.skyblocker.skyblock.bazaar.ReorderHelper; +import de.hysky.skyblocker.skyblock.chocolatefactory.ChocolateFactorySolver; +import de.hysky.skyblocker.skyblock.dungeon.CroesusHelper; +import de.hysky.skyblocker.skyblock.dungeon.CroesusProfit; +import de.hysky.skyblocker.skyblock.dungeon.terminal.ColorTerminal; +import de.hysky.skyblocker.skyblock.dungeon.terminal.LightsOnTerminal; +import de.hysky.skyblocker.skyblock.dungeon.terminal.OrderTerminal; +import de.hysky.skyblocker.skyblock.dungeon.terminal.StartsWithTerminal; +import de.hysky.skyblocker.skyblock.dwarven.CommissionHighlight; +import de.hysky.skyblocker.skyblock.experiment.ChronomatronSolver; +import de.hysky.skyblocker.skyblock.experiment.SuperpairsSolver; +import de.hysky.skyblocker.skyblock.experiment.UltrasequencerSolver; +import de.hysky.skyblocker.utils.Utils; +import de.hysky.skyblocker.utils.render.gui.ColorHighlight; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; +import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; +import net.minecraft.client.gui.DrawContext; +import net.minecraft.client.gui.screen.ingame.GenericContainerScreen; +import net.minecraft.client.util.math.MatrixStack; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; +import org.jetbrains.annotations.NotNull; + +import java.util.List; + +/** + * Manager class for {@link SimpleContainerSolver}s like terminal solvers and experiment solvers. To add a new gui solver, extend {@link SimpleContainerSolver} and register it in {@link #ContainerSolverManager()}. + */ +public class ContainerSolverManager { + private final ContainerSolver[] solvers; + private ContainerSolver currentSolver = null; + private List highlights; + /** + * Useful for keeping track of a solver's state in a Screen instance, such as if Hypixel closes & reopens a screen after every click (as they do with terminals). + */ + private int screenId = 0; + + public ContainerSolverManager() { + solvers = new ContainerSolver[]{ + new ColorTerminal(), + new OrderTerminal(), + new StartsWithTerminal(), + new LightsOnTerminal(), + new CroesusHelper(), + new CroesusProfit(), + new ChronomatronSolver(), + new CommissionHighlight(), + new SuperpairsSolver(), + UltrasequencerSolver.INSTANCE, + new NewYearCakeBagHelper(), + NewYearCakesHelper.INSTANCE, + new ChocolateFactorySolver(), + new ReorderHelper() + }; + } + + public ContainerSolver getCurrentSolver() { + return currentSolver; + } + + public void init() { + ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> { + if (Utils.isOnSkyblock() && screen instanceof GenericContainerScreen genericContainerScreen) { + ScreenEvents.afterRender(screen).register((screen1, context, mouseX, mouseY, delta) -> { + MatrixStack matrices = context.getMatrices(); + matrices.push(); + matrices.translate(((HandledScreenAccessor) genericContainerScreen).getX(), ((HandledScreenAccessor) genericContainerScreen).getY(), 300); + onDraw(context, genericContainerScreen.getScreenHandler().slots.subList(0, genericContainerScreen.getScreenHandler().getRows() * 9)); + matrices.pop(); + }); + ScreenEvents.remove(screen).register(screen1 -> clearScreen()); + onSetScreen(genericContainerScreen); + } else { + clearScreen(); + } + }); + } + + public void onSetScreen(@NotNull GenericContainerScreen screen) { + String screenName = screen.getTitle().getString(); + for (ContainerSolver solver : solvers) { + if (solver.isEnabled()) { + if (solver instanceof SimpleContainerSolver containerSolver && containerSolver.test(screenName)) { + ++screenId; + currentSolver = containerSolver; + currentSolver.start(screen); + markDirty(); + + return; + } else if (solver.test(screen)) { + ++screenId; + currentSolver = solver; + currentSolver.start(screen); + markDirty(); + + return; + } + } + } + clearScreen(); + } + + public void clearScreen() { + if (currentSolver != null) { + currentSolver.reset(); + currentSolver = null; + } + } + + public void markDirty() { + highlights = null; + } + + /** + * @return Whether the click should be disallowed. + */ + public boolean onSlotClick(int slot, ItemStack stack) { + if (currentSolver != null) { + return currentSolver.onClickSlot(slot, stack, screenId); + } + + return false; + } + + public void onDraw(DrawContext context, List slots) { + if (currentSolver == null) + return; + if (highlights == null) + highlights = currentSolver.getColors(slotMap(slots)); + RenderSystem.enableDepthTest(); + RenderSystem.colorMask(true, true, true, false); + for (ColorHighlight highlight : highlights) { + Slot slot = slots.get(highlight.slot()); + int color = highlight.color(); + context.fill(slot.x, slot.y, slot.x + 16, slot.y + 16, color); + } + RenderSystem.colorMask(true, true, true, true); + } + + private Int2ObjectMap slotMap(List slots) { + Int2ObjectMap slotMap = new Int2ObjectRBTreeMap<>(); + for (int i = 0; i < slots.size(); i++) { + slotMap.put(i, slots.get(i).getStack()); + } + return slotMap; + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/container/RegexContainerMatcher.java b/src/main/java/de/hysky/skyblocker/utils/container/RegexContainerMatcher.java new file mode 100644 index 0000000000..4f9d49aeaa --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/container/RegexContainerMatcher.java @@ -0,0 +1,68 @@ +package de.hysky.skyblocker.utils.container; + +import de.hysky.skyblocker.skyblock.ChestValue; +import net.minecraft.client.gui.screen.Screen; +import org.intellij.lang.annotations.Language; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +/** + * A regex implementation of {@link ContainerMatcher} that matches the title of the screen. + */ +public abstract class RegexContainerMatcher implements ContainerMatcher { + /** + * The title of the screen must match this pattern for this to be applied. Null means it will be applied to all screens. + * + * @implNote Don't end your regex with a {@code $} as {@link ChestValue} appends text to the end of the title, + * so the regex will stop matching if the player uses chest value. + */ + @Nullable + public final Pattern titlePattern; + + @Nullable + public String[] groups = null; + + @Override + public boolean test(@NotNull Screen screen) { + return test(screen.getTitle().getString()); + } + + public boolean test(@NotNull String title) { + if (titlePattern == null) return true; + Matcher matcher = titlePattern.matcher(title); + if (matcher.matches()) { + int groupCount = matcher.groupCount(); + if (groupCount >= 1) { //No need to initialize the array if there are no groups + groups = new String[groupCount]; + for (int i = 0; i < groupCount; i++) { + groups[i] = matcher.group(i + 1); // +1 because first group is the whole match, which is useless + } + } + return true; + } + return false; + } + + protected RegexContainerMatcher() { + this((Pattern) null); + } + + protected RegexContainerMatcher(@NotNull @Language("RegExp") String titlePattern) { + this(Pattern.compile(titlePattern)); + } + + protected RegexContainerMatcher(@Nullable Pattern titlePattern) { + this.titlePattern = titlePattern; + } + + public @Nullable Pattern getTitlePattern() { + return titlePattern; + } + + public final @Nullable String[] getGroups() { + return groups; + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/container/SimpleContainerSolver.java b/src/main/java/de/hysky/skyblocker/utils/container/SimpleContainerSolver.java new file mode 100644 index 0000000000..7d8b74173d --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/container/SimpleContainerSolver.java @@ -0,0 +1,38 @@ +package de.hysky.skyblocker.utils.container; + +import org.intellij.lang.annotations.Language; +import org.jetbrains.annotations.NotNull; + +import java.util.regex.Pattern; + +/** + * Simple implementation of a container solver. Extend this class to add a new gui solver, + * like terminal solvers or experiment solvers and add it to {@link ContainerSolverManager#solvers}. + */ +public abstract class SimpleContainerSolver extends RegexContainerMatcher implements ContainerSolver { + /** + * Utility constructor that will compile the given string into a pattern. + * + * @see #SimpleContainerSolver(Pattern) + */ + protected SimpleContainerSolver(@NotNull @Language("RegExp") String titlePattern) { + super(titlePattern); + } + + /** + * Creates a ContainerSolver that will be applied to screens with titles that match the given pattern. + * + * @param titlePattern The pattern to match the screen title against. + */ + protected SimpleContainerSolver(@NotNull Pattern titlePattern) { + super(titlePattern); + } + + // A container solver that applies to every screen doesn't make sense, + // so we don't provide a constructor for that and force getTitlePattern to be @NotNull + @Override + public @NotNull Pattern getTitlePattern() { + assert super.getTitlePattern() != null; + return super.getTitlePattern(); + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/container/SlotTextAdder.java b/src/main/java/de/hysky/skyblocker/utils/container/SlotTextAdder.java new file mode 100644 index 0000000000..72f925470e --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/container/SlotTextAdder.java @@ -0,0 +1,30 @@ +package de.hysky.skyblocker.utils.container; + +import de.hysky.skyblocker.config.SkyblockerConfigManager; +import de.hysky.skyblocker.skyblock.item.slottext.SlotText; +import de.hysky.skyblocker.skyblock.item.slottext.SlotTextMode; +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public interface SlotTextAdder extends ContainerMatcher { + + /** + * This method will be called for each rendered slot. Consider using a switch statement on {@code slotId} if you wish to limit the text to specific slots. + * + * @return A list of positioned text to be rendered. Return {@link List#of()} if no text should be rendered. + * @implNote By minecraft's design, scaled text inexplicably moves around. + * It's also not anti-aliased, so it looks horribly jagged and unreadable when scaled down too much. + * So, limit your text to 3 characters (or roughly less than 20 width) if you want it to not look horrible. + */ + @NotNull + List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId); + + @Override + default boolean isEnabled() { + return SkyblockerConfigManager.get().general.itemInfoDisplay.slotTextMode != SlotTextMode.DISABLED; + } +} diff --git a/src/main/java/de/hysky/skyblocker/utils/container/TooltipAdder.java b/src/main/java/de/hysky/skyblocker/utils/container/TooltipAdder.java new file mode 100644 index 0000000000..2ff3fdf1c4 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/container/TooltipAdder.java @@ -0,0 +1,18 @@ +package de.hysky.skyblocker.utils.container; + +import net.minecraft.item.ItemStack; +import net.minecraft.screen.slot.Slot; +import net.minecraft.text.Text; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +public interface TooltipAdder extends ContainerMatcher { + /** + * @implNote The first element of the lines list holds the item's display name, + * as it's a list of all lines that will be displayed in the tooltip. + */ + void addToTooltip(@Nullable Slot focusedSlot, ItemStack stack, List lines); + + int getPriority(); +} diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java deleted file mode 100644 index bf25521819..0000000000 --- a/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java +++ /dev/null @@ -1,29 +0,0 @@ -package de.hysky.skyblocker.utils.render.gui; - -import de.hysky.skyblocker.skyblock.ChestValue; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.util.regex.Pattern; - -public abstract class AbstractContainerMatcher { - /** - * The title of the screen must match this pattern for this to be applied. Null means it will be applied to all screens. - * @implNote Don't end your regex with a {@code $} as {@link ChestValue} appends text to the end of the title, - * so the regex will stop matching if the player uses chest value. - */ - @Nullable - public final Pattern titlePattern; - - protected AbstractContainerMatcher() { - this((Pattern) null); - } - - protected AbstractContainerMatcher(@NotNull String titlePattern) { - this(Pattern.compile(titlePattern)); - } - - protected AbstractContainerMatcher(@Nullable Pattern titlePattern) { - this.titlePattern = titlePattern; - } -} diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java deleted file mode 100644 index 9a9d090709..0000000000 --- a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java +++ /dev/null @@ -1,52 +0,0 @@ -package de.hysky.skyblocker.utils.render.gui; - -import de.hysky.skyblocker.SkyblockerMod; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import net.minecraft.client.gui.screen.ingame.GenericContainerScreen; -import net.minecraft.item.ItemStack; -import org.intellij.lang.annotations.Language; - -import java.util.List; -import java.util.regex.Pattern; - -/** - * Abstract class for gui solvers. Extend this class to add a new gui solver, like terminal solvers or experiment solvers. - */ -public abstract class ContainerSolver extends AbstractContainerMatcher { - protected ContainerSolver(@Language("RegExp") String titlePattern) { - super(titlePattern); - } - - protected abstract boolean isEnabled(); - - public final Pattern getName() { - return titlePattern; - } - - protected void start(GenericContainerScreen screen) { - } - - protected void reset() { - } - - protected void markHighlightsDirty() { - SkyblockerMod.getInstance().containerSolverManager.markDirty(); - } - - protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[] groups) { - return false; - } - - protected abstract List getColors(String[] groups, Int2ObjectMap slots); - - protected final void trimEdges(Int2ObjectMap slots, int rows) { - for (int i = 0; i < rows; i++) { - slots.remove(9 * i); - slots.remove(9 * i + 8); - } - for (int i = 1; i < 8; i++) { - slots.remove(i); - slots.remove((rows - 1) * 9 + i); - } - } -} diff --git a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolverManager.java b/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolverManager.java deleted file mode 100644 index 79cc78f577..0000000000 --- a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolverManager.java +++ /dev/null @@ -1,157 +0,0 @@ -package de.hysky.skyblocker.utils.render.gui; - -import com.mojang.blaze3d.systems.RenderSystem; -import de.hysky.skyblocker.mixins.accessors.HandledScreenAccessor; -import de.hysky.skyblocker.skyblock.accessories.newyearcakes.NewYearCakeBagHelper; -import de.hysky.skyblocker.skyblock.accessories.newyearcakes.NewYearCakesHelper; -import de.hysky.skyblocker.skyblock.bazaar.ReorderHelper; -import de.hysky.skyblocker.skyblock.chocolatefactory.ChocolateFactorySolver; -import de.hysky.skyblocker.skyblock.dungeon.CroesusHelper; -import de.hysky.skyblocker.skyblock.dungeon.CroesusProfit; -import de.hysky.skyblocker.skyblock.dungeon.terminal.ColorTerminal; -import de.hysky.skyblocker.skyblock.dungeon.terminal.LightsOnTerminal; -import de.hysky.skyblocker.skyblock.dungeon.terminal.OrderTerminal; -import de.hysky.skyblocker.skyblock.dungeon.terminal.StartsWithTerminal; -import de.hysky.skyblocker.skyblock.dwarven.CommissionHighlight; -import de.hysky.skyblocker.skyblock.experiment.ChronomatronSolver; -import de.hysky.skyblocker.skyblock.experiment.SuperpairsSolver; -import de.hysky.skyblocker.skyblock.experiment.UltrasequencerSolver; -import de.hysky.skyblocker.utils.Utils; -import it.unimi.dsi.fastutil.ints.Int2ObjectMap; -import it.unimi.dsi.fastutil.ints.Int2ObjectRBTreeMap; -import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; -import net.minecraft.client.gui.DrawContext; -import net.minecraft.client.gui.screen.ingame.GenericContainerScreen; -import net.minecraft.client.util.math.MatrixStack; -import net.minecraft.item.ItemStack; -import net.minecraft.screen.slot.Slot; -import org.jetbrains.annotations.NotNull; - -import java.util.List; -import java.util.regex.Matcher; -import java.util.regex.Pattern; - -/** - * Manager class for {@link ContainerSolver}s like terminal solvers and experiment solvers. To add a new gui solver, extend {@link ContainerSolver} and register it in {@link #ContainerSolverManager()}. - */ -public class ContainerSolverManager { - private static final Pattern PLACEHOLDER_PATTERN = Pattern.compile(""); - private final ContainerSolver[] solvers; - private ContainerSolver currentSolver = null; - private String[] groups; - private List highlights; - /** - * Useful for keeping track of a solver's state in a Screen instance, such as if Hypixel closes & reopens a screen after every click (as they do with terminals). - */ - private int screenId = 0; - - public ContainerSolverManager() { - solvers = new ContainerSolver[]{ - new ColorTerminal(), - new OrderTerminal(), - new StartsWithTerminal(), - new LightsOnTerminal(), - new CroesusHelper(), - new CommissionHighlight(), - new CroesusProfit(), - new ChronomatronSolver(), - new SuperpairsSolver(), - UltrasequencerSolver.INSTANCE, - new NewYearCakeBagHelper(), - NewYearCakesHelper.INSTANCE, - new ChocolateFactorySolver(), - new ReorderHelper() - }; - } - - public ContainerSolver getCurrentSolver() { - return currentSolver; - } - - public void init() { - ScreenEvents.BEFORE_INIT.register((client, screen, scaledWidth, scaledHeight) -> { - if (Utils.isOnSkyblock() && screen instanceof GenericContainerScreen genericContainerScreen) { - ScreenEvents.afterRender(screen).register((screen1, context, mouseX, mouseY, delta) -> { - MatrixStack matrices = context.getMatrices(); - matrices.push(); - matrices.translate(((HandledScreenAccessor) genericContainerScreen).getX(), ((HandledScreenAccessor) genericContainerScreen).getY(), 300); - onDraw(context, genericContainerScreen.getScreenHandler().slots.subList(0, genericContainerScreen.getScreenHandler().getRows() * 9)); - matrices.pop(); - }); - ScreenEvents.remove(screen).register(screen1 -> clearScreen()); - onSetScreen(genericContainerScreen); - } else { - clearScreen(); - } - }); - } - - public void onSetScreen(@NotNull GenericContainerScreen screen) { - String screenName = screen.getTitle().getString(); - Matcher matcher = PLACEHOLDER_PATTERN.matcher(screenName); - for (ContainerSolver solver : solvers) { - if (solver.isEnabled()) { - matcher.usePattern(solver.getName()); - matcher.reset(); - if (matcher.matches()) { - ++screenId; - currentSolver = solver; - groups = new String[matcher.groupCount()]; - for (int i = 0; i < groups.length; i++) { - groups[i] = matcher.group(i + 1); - } - currentSolver.start(screen); - markDirty(); - - return; - } - } - } - clearScreen(); - } - - public void clearScreen() { - if (currentSolver != null) { - currentSolver.reset(); - currentSolver = null; - } - } - - public void markDirty() { - highlights = null; - } - - /** - * @return Whether the click should be disallowed. - */ - public boolean onSlotClick(int slot, ItemStack stack) { - if (currentSolver != null) { - return currentSolver.onClickSlot(slot, stack, screenId, groups); - } - - return false; - } - - public void onDraw(DrawContext context, List slots) { - if (currentSolver == null) - return; - if (highlights == null) - highlights = currentSolver.getColors(groups, slotMap(slots)); - RenderSystem.enableDepthTest(); - RenderSystem.colorMask(true, true, true, false); - for (ColorHighlight highlight : highlights) { - Slot slot = slots.get(highlight.slot()); - int color = highlight.color(); - context.fill(slot.x, slot.y, slot.x + 16, slot.y + 16, color); - } - RenderSystem.colorMask(true, true, true, true); - } - - private Int2ObjectMap slotMap(List slots) { - Int2ObjectMap slotMap = new Int2ObjectRBTreeMap<>(); - for (int i = 0; i < slots.size(); i++) { - slotMap.put(i, slots.get(i).getStack()); - } - return slotMap; - } -} diff --git a/src/main/resources/assets/skyblocker/lang/en_us.json b/src/main/resources/assets/skyblocker/lang/en_us.json index 875b45ddb3..2c19e03629 100644 --- a/src/main/resources/assets/skyblocker/lang/en_us.json +++ b/src/main/resources/assets/skyblocker/lang/en_us.json @@ -10,6 +10,7 @@ "key.skyblocker.toggleA": "Toggle tab HUD to screen A", "key.wikiLookup": "Wiki Lookup", "key.itemProtection": "Protect Item", + "key.skyblocker.slottext": "Slot Text", "text.skyblocker.open": "Open", "text.skyblocker.quit_config": "Changes Not Saved", @@ -27,6 +28,9 @@ "skyblocker.config.title": "Skyblocker Settings", + "skyblocker.config.shortcutToKeybindsSettings": "Edit Keybind", + "skyblocker.config.shortcutToKeybindsSettings.@Text": "Click... (Opens up Keybinds Options)", + "skyblocker.config.crimsonIsle": "Crimson Isle", "skyblocker.config.crimsonIsle.kuudra": "Kuudra",