From 6a1543f66d5e17ec38c71abeb52fbdc674be860c Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Mon, 21 Oct 2024 07:02:20 +0300 Subject: [PATCH 1/5] Add EvolvingItemAdder --- .../item/slottext/SlotTextManager.java | 3 +- .../slottext/adders/EvolvingItemAdder.java | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EvolvingItemAdder.java 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 2d8c4b9fe9..8edff43445 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 @@ -47,7 +47,8 @@ public class SlotTextManager { new PowerStonesGuideAdder(), new BazaarHelper(), new StatsTuningAdder(), - ChocolateFactorySolver.INSTANCE + ChocolateFactorySolver.INSTANCE, + new EvolvingItemAdder() }; 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/skyblock/item/slottext/adders/EvolvingItemAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EvolvingItemAdder.java new file mode 100644 index 0000000000..8c21334758 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/EvolvingItemAdder.java @@ -0,0 +1,64 @@ +package de.hysky.skyblocker.skyblock.item.slottext.adders; + +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SlotText; +import de.hysky.skyblocker.utils.ItemUtils; +import de.hysky.skyblocker.utils.RegexUtils; +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; +import java.util.Locale; +import java.util.OptionalDouble; +import java.util.regex.Matcher; +import java.util.regex.Pattern; + +// Evolving items are those that get upgraded after holding them in your inventory for a certain amount of time. +public class EvolvingItemAdder extends SimpleSlotTextAdder { + private static final Pattern BONUS_PATTERN = Pattern.compile("\\+?([\\d.]+)"); + private static final NumberFormat NUMBER_FORMAT = NumberFormat.getInstance(Locale.US); + + public EvolvingItemAdder() { + super(); + } + + @Override + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + switch (stack.getSkyblockId()) { + case "NEW_BOTTLE_OF_JYRRE", "DARK_CACAO_TRUFFLE" -> { + return actualLogic(stack, "Current Bonus: "); + } + case "TRAINING_WEIGHTS" -> { + return actualLogic(stack, "Strength Gain: "); + } + // This is the old item called "Lost Bottle of Jyrre" now, this version of the item can't evolve + // but its intelligence bonus similarly increases as it's held. + // It's unobtainable but there are still some in the game. + case "BOTTLE_OF_JYRRE" -> { + return actualLogic(stack, "Intelligence Bonus: "); + } + } + return List.of(); + } + + // This method was extracted to avoid duplicating the whole method multiple times with just 1 different string equality check. + private List actualLogic(ItemStack stack, String equal) { + List lore = ItemUtils.getLore(stack); + if (lore.isEmpty()) return List.of(); + for (Text line : lore) { + List siblings = line.getSiblings(); + if (siblings.size() < 2) continue; + if (siblings.getFirst().getString().equals(equal)) { + Text bonus = siblings.get(1); + Matcher matcher = BONUS_PATTERN.matcher(bonus.getString()); + OptionalDouble result = RegexUtils.findDoubleFromMatcher(matcher); + if (result.isPresent()) return SlotText.bottomLeftList(Text.literal(NUMBER_FORMAT.format(result.getAsDouble())).setStyle(bonus.getStyle())); + } + } + return List.of(); + } +} From 0e3449ee44274cc68c425e65a23137b769ad75ff Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Mon, 21 Oct 2024 07:16:26 +0300 Subject: [PATCH 2/5] Add NewYearCakeAdder This is untested due to an ongoing maintenance of skyblock --- .../slottext/adders/NewYearCakeAdder.java | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/NewYearCakeAdder.java diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/NewYearCakeAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/NewYearCakeAdder.java new file mode 100644 index 0000000000..a218f0eae0 --- /dev/null +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/NewYearCakeAdder.java @@ -0,0 +1,22 @@ +package de.hysky.skyblocker.skyblock.item.slottext.adders; + +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SlotText; +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; + +public class NewYearCakeAdder extends SimpleSlotTextAdder { + @Override + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (stack.getSkyblockId().equals("NEW_YEAR_CAKE")) { + return SlotText.bottomLeftList(Text.literal(String.valueOf(ItemUtils.getCustomData(stack).getInt("new_years_cake"))).withColor(0xCBA6F7)); + } + return List.of(); + } +} From 8ae2271b8bca33c2153c8b9b4343e1b586bb62ed Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Mon, 21 Oct 2024 07:24:00 +0300 Subject: [PATCH 3/5] Add NewYearCakeAdder to the adders array in SlotTextManager --- .../skyblocker/skyblock/item/slottext/SlotTextManager.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) 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 8edff43445..fcfb4611a4 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 @@ -48,7 +48,8 @@ public class SlotTextManager { new BazaarHelper(), new StatsTuningAdder(), ChocolateFactorySolver.INSTANCE, - new EvolvingItemAdder() + new EvolvingItemAdder(), + new NewYearCakeAdder() }; 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")); From 9b0f50232080853c6584b738d8aec89a676840bd Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Mon, 21 Oct 2024 12:49:50 +0300 Subject: [PATCH 4/5] Fix NewYearCakeAdder and change its color as well --- .../skyblock/item/slottext/adders/NewYearCakeAdder.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/NewYearCakeAdder.java b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/NewYearCakeAdder.java index a218f0eae0..f81c0df8cf 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/NewYearCakeAdder.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/NewYearCakeAdder.java @@ -4,6 +4,7 @@ import de.hysky.skyblocker.skyblock.item.slottext.SlotText; 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 org.jetbrains.annotations.NotNull; @@ -14,9 +15,9 @@ public class NewYearCakeAdder extends SimpleSlotTextAdder { @Override public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { - if (stack.getSkyblockId().equals("NEW_YEAR_CAKE")) { - return SlotText.bottomLeftList(Text.literal(String.valueOf(ItemUtils.getCustomData(stack).getInt("new_years_cake"))).withColor(0xCBA6F7)); - } - return List.of(); + if (!stack.isOf(Items.CAKE)) return List.of(); + int year = ItemUtils.getCustomData(stack).getInt("new_years_cake"); + if (year <= 0) return List.of(); + return SlotText.bottomLeftList(Text.literal(String.valueOf(year)).withColor(0x74c7ec)); } } From 82f1056516a42aaa8e2f6c65760eb1d3ce09bef9 Mon Sep 17 00:00:00 2001 From: Rime <81419447+Emirlol@users.noreply.github.com> Date: Tue, 22 Oct 2024 02:51:08 +0300 Subject: [PATCH 5/5] Add wardrobe slot text --- .../skyblocker/skyblock/WardrobeKeybinds.java | 22 ++++++++++++++----- .../item/slottext/SlotTextManager.java | 4 +++- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/hysky/skyblocker/skyblock/WardrobeKeybinds.java b/src/main/java/de/hysky/skyblocker/skyblock/WardrobeKeybinds.java index 795acf1ce1..3aa5ffc7e2 100644 --- a/src/main/java/de/hysky/skyblocker/skyblock/WardrobeKeybinds.java +++ b/src/main/java/de/hysky/skyblocker/skyblock/WardrobeKeybinds.java @@ -2,7 +2,8 @@ import de.hysky.skyblocker.annotations.Init; import de.hysky.skyblocker.config.SkyblockerConfigManager; -import de.hysky.skyblocker.utils.container.RegexContainerMatcher; +import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder; +import de.hysky.skyblocker.skyblock.item.slottext.SlotText; import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents; import net.fabricmc.fabric.api.client.screen.v1.ScreenKeyboardEvents; import net.fabricmc.fabric.api.client.screen.v1.ScreenMouseEvents; @@ -11,14 +12,18 @@ import net.minecraft.client.option.KeyBinding; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; +import net.minecraft.screen.slot.Slot; import net.minecraft.screen.slot.SlotActionType; +import net.minecraft.text.Text; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.lwjgl.glfw.GLFW; +import java.util.List; import java.util.function.Predicate; -@SuppressWarnings("unused") -public class WardrobeKeybinds extends RegexContainerMatcher { - private static final WardrobeKeybinds INSTANCE = new WardrobeKeybinds(); +public class WardrobeKeybinds extends SimpleSlotTextAdder { + public static final WardrobeKeybinds INSTANCE = new WardrobeKeybinds(); public WardrobeKeybinds() { super("Wardrobe \\([12]/2\\)"); @@ -51,13 +56,20 @@ private static boolean allowInput(MinecraftClient client, HandledScreen handl i += 9 * 4; ItemStack itemStack = handledScreen.getScreenHandler().getSlot(i).getStack(); // Check if the item in the slot is a swap/unequip item before going further. - // This prevents usage when the inventory hasn't loaded fully or when the slot pressed is locked (which would be meaningless to click) + // This prevents usage when the inventory hasn't loaded fully or when the slot pressed is locked or when the slot has no armor (which would be meaningless to click) if (!itemStack.isOf(Items.PINK_DYE) && !itemStack.isOf(Items.LIME_DYE)) return true; assert client.interactionManager != null; client.interactionManager.clickSlot(handledScreen.getScreenHandler().syncId, i, GLFW.GLFW_MOUSE_BUTTON_1, SlotActionType.PICKUP, client.player); return false; } + @Override + public @NotNull List getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) { + if (!stack.isOf(Items.PINK_DYE) && !stack.isOf(Items.LIME_DYE)) return List.of(); + if (!(slotId >= 36 && slotId <= 44)) return List.of(); + return SlotText.bottomLeftList(Text.literal(String.valueOf(slotId - 35)).withColor(0x74c7ec)); + } + @Override public boolean isEnabled() { return SkyblockerConfigManager.get().helpers.enableWardrobeHelper; 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 fcfb4611a4..da1dc6fe62 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 @@ -2,6 +2,7 @@ import de.hysky.skyblocker.annotations.Init; 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.item.slottext.adders.*; @@ -49,7 +50,8 @@ public class SlotTextManager { new StatsTuningAdder(), ChocolateFactorySolver.INSTANCE, new EvolvingItemAdder(), - new NewYearCakeAdder() + new NewYearCakeAdder(), + WardrobeKeybinds.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"));