diff options
Diffstat (limited to 'src/Java/gtPlusPlus/xmod')
-rw-r--r-- | src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java | 73 | ||||
-rw-r--r-- | src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java | 137 |
2 files changed, 210 insertions, 0 deletions
diff --git a/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java b/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java new file mode 100644 index 0000000000..9075666b8b --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/galacticraft/handler/HandlerTooltip_GC.java @@ -0,0 +1,73 @@ +package gtPlusPlus.xmod.galacticraft.handler; + +import java.lang.reflect.Field; + +import cpw.mods.fml.common.eventhandler.SubscribeEvent; +import net.minecraft.block.Block; +import net.minecraft.item.Item; +import gtPlusPlus.core.item.chemistry.RocketFuels; +import gtPlusPlus.core.lib.LoadedMods; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraftforge.event.entity.player.ItemTooltipEvent; +import net.minecraftforge.fluids.Fluid; + +public class HandlerTooltip_GC { + + private static Item mItemBlock; + private static Block mBlock; + private static Class<?> oMainClass; + private static Class<?> oFuelLoaderClass; + private static String[] mFuelNames; + + @SubscribeEvent + public void onItemTooltip(ItemTooltipEvent event) { + if (LoadedMods.GalacticraftCore) { + + if (mBlock == null) { + try { + Class<?> GCBlocks = Class.forName("micdoodle8.mods.galacticraft.core.blocks.GCBlocks"); + if (GCBlocks != null) { + oMainClass = GCBlocks; + + Class<?> GCFuelLoader = Class + .forName("micdoodle8.mods.galacticraft.core.blocks.BlockFuelLoader"); + + if (GCFuelLoader != null) { + oFuelLoaderClass = GCFuelLoader; + } + + Field aField = ReflectionUtils.getField(GCBlocks, "fuelLoader"); + if (aField != null) { + Block aBlock = (Block) aField.get(null); + if (aBlock != null) { + mBlock = aBlock; + mItemBlock = Item.getItemFromBlock(mBlock); + } + } + } + } catch (Throwable t) { + } + } + if (mFuelNames == null || mFuelNames.length == 0) { + mFuelNames = new String[RocketFuels.mValidRocketFuels.size()]; + int slot = 0; + for (Fluid f : RocketFuels.mValidRocketFuels.values()) { + mFuelNames[slot++] = f.getLocalizedName(); + } + } + if (mItemBlock != null) { + Item aTempItem = event.itemStack.getItem(); + Block aTempBlock = Block.getBlockFromItem(aTempItem); + if (aTempItem == mItemBlock || oFuelLoaderClass.isInstance(aTempBlock) + || event.itemStack.getUnlocalizedName().toLowerCase().contains("fuelloader")) { + int aTier = 0; + for (String s : mFuelNames) { + if (s != null) { + event.toolTip.add("Tier "+aTier+": "+s); + } + } + } + } + } + } +} diff --git a/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java b/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java new file mode 100644 index 0000000000..df8521be9d --- /dev/null +++ b/src/Java/gtPlusPlus/xmod/galacticraft/util/GalacticUtils.java @@ -0,0 +1,137 @@ +package gtPlusPlus.xmod.galacticraft.util; + +import java.lang.reflect.InvocationTargetException; +import java.lang.reflect.Method; + +import gregtech.api.enums.Materials; +import gtPlusPlus.core.item.chemistry.RocketFuels; +import gtPlusPlus.core.util.minecraft.FluidUtils; +import gtPlusPlus.core.util.reflect.ReflectionUtils; +import net.minecraft.entity.Entity; +import net.minecraftforge.fluids.FluidStack; + +public class GalacticUtils { + + static final private Class<?> aTieredRocket; + static final private Class<?> aLandingPad; + static final private Class<?> aBuggyPad; + static final private Class<?> aIDockable; + static final private Class<?> aIFuelable; + static final private Method getRocketTier; + static final private Method getRocket; + static final private Method getBuggy; + + static { + Class<?> a1, a2, a3, a4, a5; + Method m1, m2, m3; + try { + a1 = Class.forName("micdoodle8.mods.galacticraft.api.prefab.entity.EntityTieredRocket"); + a2 = Class.forName("micdoodle8.mods.galacticraft.core.tile.TileEntityLandingPad"); + a3 = Class.forName("micdoodle8.mods.galacticraft.core.tile.TileEntityBuggyFueler"); + a4 = Class.forName("micdoodle8.mods.galacticraft.api.entity.IDockable"); + a5 = Class.forName("micdoodle8.mods.galacticraft.api.entity.IFuelable"); + m1 = ReflectionUtils.getMethod(a1, "getRocketTier"); + m2 = ReflectionUtils.getMethod(a2, "getDockedEntity"); + m3 = ReflectionUtils.getMethod(a3, "getDockedEntity"); + } + catch (Throwable t) { + a1 = null; + a2 = null; + a3 = null; + a4 = null; + a5 = null; + m1 = null; + m2 = null; + m3 = null; + } + aTieredRocket = a1; + aLandingPad = a2; + aBuggyPad = a3; + aIDockable = a4; + aIFuelable = a5; + getRocketTier = m1; + getRocket = m2; + getBuggy = m3; + } + + + public static int getRocketTier(Entity aEntity) { + if (aTieredRocket.isInstance(aEntity)) { + if (getRocketTier != null) { + try { + return (int) getRocketTier.invoke(aEntity, new Object[] {}); + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + } + return -1; + } + + public static int getRocketTier(Object aEntity) { + if (aIFuelable.isInstance(aEntity)) { + if (aLandingPad.isInstance(aEntity)) { + Object rocket; + try { + rocket = getRocket.invoke(aLandingPad, new Object[] {}); + if (aIDockable.isInstance(rocket) && rocket != null) { + return getRocketTier((Entity) rocket); + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + else if (aBuggyPad.isInstance(aEntity)) { + Object buggy; + try { + buggy = getBuggy.invoke(aBuggyPad, new Object[] {}); + if (aIDockable.isInstance(buggy) && buggy != null) { + return 0; + } + } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { + } + } + } + return -1; + } + + public static boolean isFuelValidForTier(int aTier, FluidStack aFuel) { + FluidStack aValidForThisTier = getValidFuelForTier(aTier); + if (aFuel.isFluidEqual(aValidForThisTier)) { + return true; + } + return false; + } + + + + public static FluidStack getValidFuelForTier(Entity aEntity) { + if (aTieredRocket.isInstance(aEntity)) { + return getValidFuelForTier(getRocketTier(aEntity)); + } + else { + return null; + } + } + + public static FluidStack getValidFuelForTier(int aTier) { + if (aTier > 0 && aTier <= 2) { + return FluidUtils.getFluidStack(RocketFuels.RP1_Plus_Liquid_Oxygen, 1000); + } + else if (aTier >= 3 && aTier <= 5) { + return FluidUtils.getFluidStack(RocketFuels.Dense_Hydrazine_Mix, 1000); + } + else if (aTier >= 6 && aTier <= 7) { + return FluidUtils.getFluidStack(RocketFuels.Monomethylhydrazine_Plus_Nitric_Acid, 1000); + } + else if (aTier >= 8 && aTier <= 10) { + return FluidUtils.getFluidStack(RocketFuels.Unsymmetrical_Dimethylhydrazine_Plus_Nitrogen_Tetroxide, 1000); + } + else { + if (aTier == 0) { + return Materials.Fuel.getFluid(1000); + } + return null; + } + + } + +} |