Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more slot text adders #1025

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 17 additions & 5 deletions src/main/java/de/hysky/skyblocker/skyblock/WardrobeKeybinds.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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\\)");
Expand Down Expand Up @@ -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<SlotText> 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.*;
Expand Down Expand Up @@ -47,7 +48,10 @@ public class SlotTextManager {
new PowerStonesGuideAdder(),
new BazaarHelper(),
new StatsTuningAdder(),
ChocolateFactorySolver.INSTANCE
ChocolateFactorySolver.INSTANCE,
new EvolvingItemAdder(),
new NewYearCakeAdder(),
WardrobeKeybinds.INSTANCE
};
private static final ArrayList<SlotTextAdder> currentScreenAdders = new ArrayList<>();
private static final KeyBinding keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding("key.skyblocker.slottext", GLFW.GLFW_KEY_LEFT_ALT, "key.categories.skyblocker"));
Expand Down
Original file line number Diff line number Diff line change
@@ -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<SlotText> 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<SlotText> actualLogic(ItemStack stack, String equal) {
List<Text> lore = ItemUtils.getLore(stack);
if (lore.isEmpty()) return List.of();
for (Text line : lore) {
List<Text> 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();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
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.item.Items;
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<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) {
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));
}
}