aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/de/hysky/skyblocker/skyblock/item/slottext/adders/StatsTuningAdder.java
blob: 5c175b1ba400ce52e47ba58c72f57db00e850a63 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package de.hysky.skyblocker.skyblock.item.slottext.adders;

import de.hysky.skyblocker.skyblock.item.slottext.SlotText;
import de.hysky.skyblocker.skyblock.item.slottext.SimpleSlotTextAdder;
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;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StatsTuningAdder extends SimpleSlotTextAdder {
    private static final Pattern STATHAS = Pattern.compile("Stat has: (?<points>\\d+) (points|point)");
    private static final Pattern UNASSIGNEDPOINTS = Pattern.compile("Unassigned Points: (?<points>\\d+)!!!");

    public StatsTuningAdder() {
        super("^Stats Tuning");
    }

    @Override
    public @NotNull List<SlotText> getText(@Nullable Slot slot, @NotNull ItemStack stack, int slotId) {
        Matcher statMatcher = ItemUtils.getLoreLineIfMatch(stack, STATHAS);
        Matcher unassignedMatcher = ItemUtils.getLoreLineIfMatch(stack, UNASSIGNEDPOINTS);

        if (stack.getName().getString().equals("Stats Tuning")) {
            if (unassignedMatcher == null) return List.of();
            String unassignedPoints = unassignedMatcher.group("points");
            return List.of(SlotText.bottomRight(Text.literal(unassignedPoints).withColor(0xFFDDC1)));
        }

        if (statMatcher == null) return List.of();
        String assignedPoints = statMatcher.group("points");
        if (assignedPoints.equals("0")) return List.of();
        return List.of(SlotText.bottomRight(Text.literal(assignedPoints).withColor(0xFFDDC1)));

    }
}