diff options
Diffstat (limited to 'src/main/java/de/hysky/skyblocker/utils')
3 files changed, 35 insertions, 8 deletions
diff --git a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java index b1708404..46950fc4 100644 --- a/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java +++ b/src/main/java/de/hysky/skyblocker/utils/ItemUtils.java @@ -18,6 +18,7 @@ import it.unimi.dsi.fastutil.ints.IntIntPair; import it.unimi.dsi.fastutil.longs.LongBooleanPair; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.component.ComponentChanges; +import net.minecraft.component.ComponentHolder; import net.minecraft.component.DataComponentTypes; import net.minecraft.component.type.LoreComponent; import net.minecraft.component.type.NbtComponent; @@ -62,7 +63,7 @@ public class ItemUtils { } @SuppressWarnings("deprecation") - public static NbtCompound getCustomData(@NotNull ItemStack stack) { + public static NbtCompound getCustomData(@NotNull ComponentHolder stack) { return stack.getOrDefault(DataComponentTypes.CUSTOM_DATA, NbtComponent.DEFAULT).getNbt(); } @@ -104,7 +105,7 @@ public class ItemUtils { * @param stack the item stack to get the UUID from * @return the UUID of the item stack, or an empty string if the item stack is null or does not have a UUID */ - public static String getItemUuid(@NotNull ItemStack stack) { + public static String getItemUuid(@NotNull ComponentHolder stack) { return getCustomData(stack).getString(UUID); } 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 new file mode 100644 index 00000000..38864ec4 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/AbstractContainerMatcher.java @@ -0,0 +1,28 @@ +package de.hysky.skyblocker.utils.render.gui; + +import de.hysky.skyblocker.skyblock.ChestValue; +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; + + public AbstractContainerMatcher() { + this((Pattern) null); + } + + public AbstractContainerMatcher(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 index 0417dc3c..81c9ebec 100644 --- a/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java +++ b/src/main/java/de/hysky/skyblocker/utils/render/gui/ContainerSolver.java @@ -11,17 +11,15 @@ 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 { - private final Pattern containerName; - - protected ContainerSolver(String containerName) { - this.containerName = Pattern.compile(containerName); +public abstract class ContainerSolver extends AbstractContainerMatcher { + protected ContainerSolver(String titlePattern) { + super(titlePattern); } protected abstract boolean isEnabled(); public final Pattern getName() { - return containerName; + return titlePattern; } protected void start(GenericContainerScreen screen) { |