aboutsummaryrefslogtreecommitdiff
path: root/src/Java/gtPlusPlus/xmod/eio/handler/HandlerTooltip_EIO.java
blob: ae0ca232b7cfce05df3cbf7e84025beb0d64b312 (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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package gtPlusPlus.xmod.eio.handler;

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

public class HandlerTooltip_EIO {

	Item mIngot;
	ItemStack mPulsatingIron;
	ItemStack mConductiveIron;
	ItemStack mRedstoneAlloy;
	ItemStack mElectricalSteel;
	ItemStack mEnergeticAlloy;
	ItemStack mVibrantAlloy;
	ItemStack mSoularium;
	ItemStack mDarkIron;

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

			//Is the EIO Ingot Item null?
			//If it is, reflect in.
			if (mIngot == null){				
				Class<?> oMainClass;
				try {
					oMainClass = Class.forName("crazypants.enderio.EnderIO");
					Class<?> oIngotClass = Class.forName("crazypants.enderio.material.ItemAlloy");
					Object oAlloy = ReflectionUtils.getField(oMainClass, "itemAlloy");				
					if (oAlloy != null && oIngotClass.isInstance(oAlloy)){
						mIngot = (Item) oAlloy;			
					}
				}
				catch (ClassNotFoundException | NoSuchFieldException e) {}
			}			

			//If EIO Item Is not Null, see if the ItemStacks for the ingots are null
			//if they stacks are null, set the stack using the item set via reflection.
			//The meta data is based on the oridinals of the materials in the EIO enum.
			if (mIngot != null){
				if (mElectricalSteel == null){
					mElectricalSteel = ItemUtils.simpleMetaStack(mIngot, 0, 1);
				}
				if (mEnergeticAlloy == null){
					mEnergeticAlloy = ItemUtils.simpleMetaStack(mIngot, 1, 1);
				}
				if (mVibrantAlloy == null){
					mVibrantAlloy = ItemUtils.simpleMetaStack(mIngot, 2, 1);
				}
				if (mRedstoneAlloy == null){
					mRedstoneAlloy = ItemUtils.simpleMetaStack(mIngot, 3, 1);
				}
				if (mConductiveIron == null){
					mConductiveIron = ItemUtils.simpleMetaStack(mIngot, 4, 1);
				}
				if (mPulsatingIron == null){
					mPulsatingIron = ItemUtils.simpleMetaStack(mIngot, 5, 1);
				}
				if (mDarkIron == null){
					mDarkIron = ItemUtils.simpleMetaStack(mIngot, 6, 1);
				}
				if (mSoularium == null){
					mSoularium = ItemUtils.simpleMetaStack(mIngot, 7, 1);
				}

				try {
					
					//If the Item is an instance of ItemAlloy.class then proceed
					if (Class.forName("crazypants.enderio.material.ItemAlloy").isInstance(event.itemStack.getItem())){
						
						//If stacks match, add a tooltip.
						if (event.itemStack == mElectricalSteel){
							event.toolTip.add(MaterialEIO.ELECTRICAL_STEEL.vChemicalFormula);						
						}
						else if (event.itemStack == mEnergeticAlloy){
							event.toolTip.add(MaterialEIO.ENERGETIC_ALLOY.vChemicalFormula);						
						}
						else if (event.itemStack == mVibrantAlloy){
							event.toolTip.add(MaterialEIO.VIBRANT_ALLOY.vChemicalFormula);						
						}
						else if (event.itemStack == mRedstoneAlloy){
							event.toolTip.add(MaterialEIO.REDSTONE_ALLOY.vChemicalFormula);						
						}
						else if (event.itemStack == mConductiveIron){
							event.toolTip.add(MaterialEIO.CONDUCTIVE_IRON.vChemicalFormula);						
						}
						else if (event.itemStack == mPulsatingIron){
							event.toolTip.add(MaterialEIO.PULSATING_IRON.vChemicalFormula);						
						}
						else if (event.itemStack == mDarkIron){
							event.toolTip.add(Materials.DarkSteel.mChemicalFormula);						
						}
						else if (event.itemStack == mSoularium){
							event.toolTip.add(MaterialEIO.SOULARIUM.vChemicalFormula);						
						}
					}
				}
				
				catch (ClassNotFoundException e) {
				}
				
				
			}
		}

	}

}