aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java
blob: 1e961096604148c6c981eba7e0e58559aa41613f (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
package gtPlusPlus.xmod.eio.handler;

import static gtPlusPlus.core.lib.CORE.ConfigSwitches.disableEnderIOIngotTooltips;

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import gregtech.api.enums.Materials;
import gtPlusPlus.core.lib.LoadedMods;
import gtPlusPlus.core.util.reflect.ReflectionUtils;
import gtPlusPlus.xmod.eio.material.MaterialEIO;
import java.lang.reflect.Field;
import net.minecraft.item.Item;
import net.minecraftforge.event.entity.player.ItemTooltipEvent;

public class HandlerTooltip_EIO {

    private static Item mIngot;
    Class oMainClass;
    Class oIngotClass;

    @SubscribeEvent
    public void onItemTooltip(ItemTooltipEvent event) {
        // Is EIO loaded?
        if (!disableEnderIOIngotTooltips && LoadedMods.EnderIO) {

            // Is the EIO Ingot Item null?
            // If it is, reflect in.
            if (mIngot == null) {
                try {
                    oMainClass = ReflectionUtils.getClass("crazypants.enderio.EnderIO");
                    oIngotClass = ReflectionUtils.getClass("crazypants.enderio.material.ItemAlloy");
                    if (oMainClass != null && oIngotClass != null) {
                        Field oAlloyField = ReflectionUtils.getField(oMainClass, "itemAlloy");
                        Object oAlloy = oAlloyField.get(oMainClass);
                        if (oAlloy != null) {
                            if (oIngotClass.isInstance(oAlloy) || Item.class.isInstance(oAlloy)) {
                                mIngot = (Item) oAlloy;
                            }
                        }
                    }
                } catch (Throwable e) {
                }
            }

            if (mIngot != null) {
                // If the Item is an instance of ItemAlloy.class then proceed
                if (event.itemStack.getItem() == mIngot
                        || oIngotClass.isInstance(event.itemStack.getItem())
                        || event.itemStack.getUnlocalizedName().toLowerCase().contains("item.itemAlloy")) {

                    // If stacks match, add a tooltip.
                    if (mIngot != null) {
                        if (event.itemStack.getItem() == mIngot) {
                            if (event.itemStack.getItemDamage() == 0) {
                                event.toolTip.add(MaterialEIO.ELECTRICAL_STEEL.vChemicalFormula);
                            } else if (event.itemStack.getItemDamage() == 1) {
                                event.toolTip.add(MaterialEIO.ENERGETIC_ALLOY.vChemicalFormula);
                            } else if (event.itemStack.getItemDamage() == 2) {
                                event.toolTip.add(MaterialEIO.VIBRANT_ALLOY.vChemicalFormula);
                            } else if (event.itemStack.getItemDamage() == 3) {
                                event.toolTip.add(MaterialEIO.REDSTONE_ALLOY.vChemicalFormula);
                            } else if (event.itemStack.getItemDamage() == 4) {
                                event.toolTip.add(MaterialEIO.CONDUCTIVE_IRON.vChemicalFormula);
                            } else if (event.itemStack.getItemDamage() == 5) {
                                event.toolTip.add(MaterialEIO.PULSATING_IRON.vChemicalFormula);
                            } else if (event.itemStack.getItemDamage() == 6) {
                                event.toolTip.add(Materials.DarkSteel.mChemicalFormula);
                            } else if (event.itemStack.getItemDamage() == 7) {
                                event.toolTip.add(MaterialEIO.SOULARIUM.vChemicalFormula);
                            }
                        }
                    }
                }
            }
        }
    }
}