aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/PetColours.java
blob: 7192f07febf9deb6ad70d10fda1f608b57892cbf (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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package me.Danker.features;

import me.Danker.commands.ToggleCommand;
import me.Danker.events.GuiChestBackgroundDrawnEvent;
import me.Danker.utils.RenderUtils;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StringUtils;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.regex.Pattern;

public class PetColours {

    static Pattern petPattern = Pattern.compile("\\[Lvl [\\d]{1,3}]");
    public static int PET_1_TO_9;
    public static int PET_10_TO_19;
    public static int PET_20_TO_29;
    public static int PET_30_TO_39;
    public static int PET_40_TO_49;
    public static int PET_50_TO_59;
    public static int PET_60_TO_69;
    public static int PET_70_TO_79;
    public static int PET_80_TO_89;
    public static int PET_90_TO_99;
    public static int PET_100;

    @SubscribeEvent
    public void onGuiRender(GuiChestBackgroundDrawnEvent event) {
        if (ToggleCommand.petColoursToggled) {
            for (Slot slot : event.slots) {
                ItemStack item = slot.getStack();
                if (item == null) continue;
                String name = item.getDisplayName();
                if (petPattern.matcher(StringUtils.stripControlCodes(name)).find()) {
                    if (name.endsWith("aHealer") || name.endsWith("aMage") || name.endsWith("aBerserk") || name.endsWith("aArcher") || name.endsWith("aTank"))
                        continue;
                    int colour;
                    int petLevel = Integer.parseInt(item.getDisplayName().substring(item.getDisplayName().indexOf(" ") + 1, item.getDisplayName().indexOf("]")));
                    if (petLevel == 100 || petLevel == 200) {
                        colour = PET_100;
                    } else if ((petLevel < 100 && petLevel >= 90) || petLevel >= 190) {
                        colour = PET_90_TO_99;
                    } else if ((petLevel < 100 && petLevel >= 80) || petLevel >= 180) {
                        colour = PET_80_TO_89;
                    } else if ((petLevel < 100 && petLevel >= 70) || petLevel >= 170) {
                        colour = PET_70_TO_79;
                    } else if ((petLevel < 100 && petLevel >= 60) || petLevel >= 160) {
                        colour = PET_60_TO_69;
                    } else if ((petLevel < 100 && petLevel >= 50) || petLevel >= 150) {
                        colour = PET_50_TO_59;
                    } else if ((petLevel < 100 && petLevel >= 40) || petLevel >= 140) {
                        colour = PET_40_TO_49;
                    } else if ((petLevel < 100 && petLevel >= 30) || petLevel >= 130) {
                        colour = PET_30_TO_39;
                    } else if ((petLevel < 100 && petLevel >= 20) || petLevel >= 120) {
                        colour = PET_20_TO_29;
                    } else if ((petLevel < 100 && petLevel >= 10) || petLevel >= 110) {
                        colour = PET_10_TO_19;
                    } else {
                        colour = PET_1_TO_9;
                    }
                    RenderUtils.drawOnSlot(event.chestSize, slot.xDisplayPosition, slot.yDisplayPosition, colour + 0xBF000000);
                }
            }
        }
    }

}