From 92d852c1107ff9d8da7a7fb612e5804fa1d871f4 Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Thu, 26 Jun 2025 05:06:22 +0300 Subject: Add attribute level helper (#1399) --- .../skyblock/hunting/AttributeLevelHelper.java | 47 ++++++++++++++++++++++ .../skyblock/item/slottext/SlotTextManager.java | 4 +- .../skyblocker/utils/container/SlotTextAdder.java | 16 +++++--- 3 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/hunting/AttributeLevelHelper.java (limited to 'src/main/java/de') diff --git a/src/main/java/de/hysky/skyblocker/skyblock/hunting/AttributeLevelHelper.java b/src/main/java/de/hysky/skyblocker/skyblock/hunting/AttributeLevelHelper.java new file mode 100644 index 00000000..e409cf5a --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/hunting/AttributeLevelHelper.java @@ -0,0 +1,47 @@ +package de.hysky.skyblocker.skyblock.hunting; + +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SlotText; +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 org.apache.commons.lang3.StringUtils; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +import java.util.List; + +//TODO: Add required amount of shards to reach max level in the tooltip via a TooltipAdder implementation once people get enough shards to figure them out +// It can be seen by clicking on the attribute but that's too much effort, we could bring that up a layer, into the tooltip of the attribute +public class AttributeLevelHelper extends SimpleSlotTextAdder { + public static final AttributeLevelHelper INSTANCE = new AttributeLevelHelper(); + private static final ConfigInformation CONFIG_INFORMATION = new ConfigInformation("attribute_levels", + "skyblocker.config.uiAndVisuals.slotText.attributeLevels", + "skyblocker.config.uiAndVisuals.slotText.attributeLevels.@Tooltip"); + + + private AttributeLevelHelper() { + super("Attribute Menu", CONFIG_INFORMATION); + } + + @Override + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (slot == null || stack.isEmpty()) return List.of(); + if (slot.id <= 9 || slot.id >= 44) return List.of(); // Don't need to process the first row and the last row + if (stack.isOf(Items.BLACK_STAINED_GLASS_PANE)) return List.of(); + + Text customName = stack.getCustomName(); + if (customName == null) return List.of(); + + String itemName = customName.getString(); + String levelText = StringUtils.substringAfterLast(itemName, " "); + if (levelText.isEmpty() || !RomanNumerals.isValidRomanNumeral(levelText)) return List.of(); + + int level = RomanNumerals.romanToDecimal(levelText); + if (level < 1 || level > 10) return List.of(); // Should not go beyond these bounds, but just in case. + + return SlotText.bottomRightList(Text.literal(String.valueOf(level)).withColor(level == 10 ? SlotText.GOLD : SlotText.CREAM)); + } +} 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 d68f6e27..6c6b19ab 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 @@ -5,6 +5,7 @@ import de.hysky.skyblocker.config.SkyblockerConfigManager; import de.hysky.skyblocker.skyblock.WardrobeKeybinds; import de.hysky.skyblocker.skyblock.bazaar.BazaarHelper; import de.hysky.skyblocker.skyblock.chocolatefactory.ChocolateFactorySolver; +import de.hysky.skyblocker.skyblock.hunting.AttributeLevelHelper; import de.hysky.skyblocker.skyblock.item.slottext.adders.*; import de.hysky.skyblocker.skyblock.profileviewer.ProfileViewerScreen; import de.hysky.skyblocker.utils.Utils; @@ -58,7 +59,8 @@ public class SlotTextManager { new EvolvingItemAdder(), new NewYearCakeAdder(), WardrobeKeybinds.INSTANCE, - new SkyblockGuideAdder() + new SkyblockGuideAdder(), + AttributeLevelHelper.INSTANCE }; 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")); diff --git a/src/main/java/de/hysky/skyblocker/utils/container/SlotTextAdder.java b/src/main/java/de/hysky/skyblocker/utils/container/SlotTextAdder.java index fb9f21e5..9f619466 100644 --- a/src/main/java/de/hysky/skyblocker/utils/container/SlotTextAdder.java +++ b/src/main/java/de/hysky/skyblocker/utils/container/SlotTextAdder.java @@ -15,6 +15,7 @@ import org.jetbrains.annotations.Nullable; import java.util.List; import java.util.Objects; +import java.util.stream.Stream; public interface SlotTextAdder extends ContainerMatcher { @@ -40,7 +41,7 @@ public interface SlotTextAdder extends ContainerMatcher { return null; } - record ConfigInformation(String id, Text name, @Nullable Text description) { + record ConfigInformation(String id, Text name, @Nullable OptionDescription description) { public ConfigInformation(String id, Text name) { this(id, name, null); } @@ -49,17 +50,22 @@ public interface SlotTextAdder extends ContainerMatcher { this(id, Text.translatable(name)); } - public ConfigInformation(String id, @Translatable String name, @Translatable String description) { - this(id, Text.translatable(name), Text.translatable(description)); + public ConfigInformation(String id, @Translatable String name, @Translatable String... descriptionLines) { + this(id, name, Stream.of(descriptionLines).map(Text::translatable).toArray(Text[]::new)); + } + + // Additional constructor in case the description lines have any formatting + public ConfigInformation(String id, @Translatable String name, Text... descriptionLines) { + this(id, Text.translatable(name), OptionDescription.of(descriptionLines)); } public Option getOption(SkyblockerConfig config) { return Option.createBuilder() .name(name) - .description(description != null ? OptionDescription.of(description) : OptionDescription.EMPTY) + .description(description != null ? description : OptionDescription.EMPTY) .binding(true, () -> config.uiAndVisuals.slotText.textEnabled.getOrDefault(id, true), - newValue -> config.uiAndVisuals.slotText.textEnabled.put(id, (boolean) newValue)) + newValue -> config.uiAndVisuals.slotText.textEnabled.put(id, newValue.booleanValue())) .controller(ConfigUtils::createBooleanController) .build(); } -- cgit