Skip to content

Commit

Permalink
Merge pull request #788 from Emirlol/container-matcher-refactor
Browse files Browse the repository at this point in the history
Refactor container matcher implementations into interfaces
  • Loading branch information
kevinthegreat1 authored Jul 25, 2024
2 parents 7f91ba4 + eb2ac7c commit 55349c5
Show file tree
Hide file tree
Showing 73 changed files with 1,117 additions and 865 deletions.
2 changes: 1 addition & 1 deletion src/main/java/de/hysky/skyblocker/SkyblockerMod.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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.<Boolean>createBuilder()
.option(Option.<SlotTextMode>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.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.itemInfoDisplay.attributeShardInfo"))
Expand Down Expand Up @@ -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.<Boolean>createBuilder()
.name(Text.translatable("skyblocker.config.general.wikiLookup.officialWiki"))
.description(OptionDescription.of(Text.translatable("skyblocker.config.general.wikiLookup.officialWiki.@Tooltip")))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand Down
33 changes: 4 additions & 29 deletions src/main/java/de/hysky/skyblocker/mixins/HandledScreenMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,17 @@
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;
import de.hysky.skyblocker.skyblock.quicknav.QuickNav;
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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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<SlotText> 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);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@

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;
import net.minecraft.screen.slot.Slot;

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<ColorHighlight> getColors(String[] groups, Int2ObjectMap<ItemStack> slots) {
public List<ColorHighlight> getColors(Int2ObjectMap<ItemStack> slots) {
MinecraftClient client = MinecraftClient.getInstance();
if (client.player != null) {
for (Slot slot : client.player.currentScreenHandler.slots) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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 (?<year>\\d+)\\)");
private static final Pattern NEW_YEAR_CAKE_PURCHASE = Pattern.compile("You purchased New Year Cake \\(Year (?<year>\\d+)\\) for .+ coins!");
private static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US);
Expand Down Expand Up @@ -49,7 +49,7 @@ public static int getCakeYear(Pattern pattern, String name) {
}

@Override
protected boolean isEnabled() {
public boolean isEnabled() {
return SkyblockerConfigManager.get().helpers.enableNewYearCakesHelper;
}

Expand All @@ -65,7 +65,7 @@ private void onChatMessage(Text message, boolean overlay) {
}

@Override
protected List<ColorHighlight> getColors(String[] groups, Int2ObjectMap<ItemStack> slots) {
public List<ColorHighlight> getColors(Int2ObjectMap<ItemStack> slots) {
String profile = Utils.getProfile();
if (cakes.isEmpty() || !cakes.containsKey(profile) || cakes.containsKey(profile) && cakes.get(profile).isEmpty()) return List.of();
List<ColorHighlight> highlights = new ArrayList<>();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -27,14 +28,19 @@ public BazaarHelper() {
}

@Override
public @NotNull List<SlotText> 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<SlotText> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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\\.");

Expand All @@ -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;
Expand All @@ -49,25 +49,24 @@ protected boolean onClickSlot(int slot, ItemStack stack, int screenId, String[]
}

@Override
protected List<ColorHighlight> getColors(String[] groups, Int2ObjectMap<ItemStack> slots) {
public List<ColorHighlight> getColors(Int2ObjectMap<ItemStack> 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<Text> 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<Text> 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;
}
}
Loading

0 comments on commit 55349c5

Please sign in to comment.