Skip to content

Commit

Permalink
Take max perk level into consideration
Browse files Browse the repository at this point in the history
  • Loading branch information
Emirlol committed Feb 22, 2025
1 parent 6f80bf6 commit ae47bbb
Showing 1 changed file with 17 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
package de.hysky.skyblocker.skyblock.item.slottext.adders;

import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class HotmPerkLevelAdder extends SimpleSlotTextAdder {
private static final ConfigInformation CONFIG_INFORMATION = new ConfigInformation(
"hotm_perk_level",
"skyblocker.config.uiAndVisuals.slotText.hotmPerkLevel");
private static final Pattern LEVEL = Pattern.compile("Level (?<level>\\d+)/(?<max>\\d+)");
private static final Pattern LEVEL = Pattern.compile("Level (?<level>\\d+)/?(?<max>\\d+)?");

public HotmPerkLevelAdder() {
super("^Heart of the Mountain$", CONFIG_INFORMATION);
Expand All @@ -28,22 +27,19 @@ public HotmPerkLevelAdder() {
@Override
@NotNull
public List<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) {
if (slotId >= 0 && slotId <= 44 && !stack.isOf(Items.COAL)) {
List<Text> lore = ItemUtils.getLore(stack);
if (slotId < 0 || slotId > 44 || stack.isOf(Items.COAL)) return List.of();

if (!lore.isEmpty()) {
String levelLine = lore.getFirst().getString();
Matcher matcher = LEVEL.matcher(levelLine);
List<Text> lore = ItemUtils.getLore(stack);
if (lore.isEmpty()) return List.of();

if (matcher.matches()) {
int level = Integer.parseInt(matcher.group("level"));
int max = Integer.parseInt(matcher.group("max"));
String levelLine = lore.getFirst().getString();
Matcher matcher = LEVEL.matcher(levelLine);
if (!matcher.matches()) return List.of();

return SlotText.bottomRightList(Text.literal(String.valueOf(level)).withColor(level == max ? SlotText.GOLD : SlotText.CREAM));
}
}
}
String level = matcher.group("level");
// The `/<max>` part is removed when the level is max, so the group being null means it's maxed
boolean isMaxed = matcher.group("max") == null;

return List.of();
return SlotText.bottomRightList(Text.literal(level).withColor(isMaxed ? SlotText.GOLD : SlotText.CREAM));
}
}

0 comments on commit ae47bbb

Please sign in to comment.