aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/me/Danker/features/GemstonesLore.java
blob: b16edaf239f9d5841faf48fcfef3cd91418b9e8e (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
70
71
72
73
74
75
76
77
78
79
80
package me.Danker.features;

import me.Danker.commands.ToggleCommand;
import me.Danker.events.ModInitEvent;
import me.Danker.utils.Utils;
import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class GemstonesLore {

    static Map<String, EnumChatFormatting> gemstoneColours = new HashMap<>();

    @SubscribeEvent
    public void init(ModInitEvent event) {
        gemstoneColours.put("Amber", EnumChatFormatting.GOLD);
        gemstoneColours.put("Sapphire", EnumChatFormatting.AQUA);
        gemstoneColours.put("Jasper", EnumChatFormatting.LIGHT_PURPLE);
        gemstoneColours.put("Amethyst", EnumChatFormatting.DARK_PURPLE);
        gemstoneColours.put("Topaz", EnumChatFormatting.YELLOW);
        gemstoneColours.put("Jade", EnumChatFormatting.GREEN);
        gemstoneColours.put("Ruby", EnumChatFormatting.RED);
        gemstoneColours.put("Opal", EnumChatFormatting.WHITE);
    }

    @SubscribeEvent(priority = EventPriority.HIGHEST)
    public void onTooltip(ItemTooltipEvent event) {
        if (!Utils.inSkyblock) return;
        if (event.toolTip == null) return;

        ItemStack item = event.itemStack;
        if (ToggleCommand.gemstoneLore) {
            if (item.hasTagCompound()) {
                NBTTagCompound tags = item.getSubCompound("ExtraAttributes", false);
                if (tags != null) {
                    if (tags.hasKey("gems")) {
                        NBTTagCompound gems = tags.getCompoundTag("gems");
                        Set<String> set = gems.getKeySet();

                        if (set.size() == 0) return;

                        int index = Minecraft.getMinecraft().gameSettings.advancedItemTooltips ? 4 : 2;

                        event.toolTip.add(event.toolTip.size() - index, "");
                        event.toolTip.add(event.toolTip.size() - index, "Gemstones Applied:");

                        for (String gem : set) {
                            char last = gem.charAt(gem.length() - 1);
                            if (!Character.isDigit(last)) continue;

                            String gemstone = "  " + Utils.capitalizeString(gems.getString(gem)) + " ";
                            if (gem.startsWith("UNIVERSAL_") || gem.startsWith("MINING_") || gem.startsWith("COMBAT_") || gem.startsWith("DEFENSIVE_")) {
                                gemstone += Utils.capitalizeString(gems.getString(gem + "_gem"));
                            } else {
                                gemstone += Utils.capitalizeString(gem.substring(0, gem.indexOf("_")));
                            }

                            for (String colour : gemstoneColours.keySet()) {
                                if (gemstone.contains(colour)) {
                                    gemstone = gemstoneColours.get(colour) + gemstone;
                                }
                            }

                            event.toolTip.add(event.toolTip.size() - index, gemstone);
                        }
                    }
                }
            }
        }
    }

}