2012-11-06 16:44:14 +01:00
|
|
|
package mekanism.api;
|
|
|
|
|
2012-12-20 22:53:39 +01:00
|
|
|
import net.minecraft.creativetab.CreativeTabs;
|
2012-11-06 16:44:14 +01:00
|
|
|
|
2012-11-07 21:01:46 +01:00
|
|
|
/**
|
2012-11-21 16:14:35 +01:00
|
|
|
* Class used to indirectly reference the Mekanism creative tab.
|
2012-11-07 21:01:46 +01:00
|
|
|
* @author AidanBrady
|
|
|
|
*
|
|
|
|
*/
|
2012-11-06 16:44:14 +01:00
|
|
|
public final class TabProxy
|
|
|
|
{
|
2012-11-07 21:01:46 +01:00
|
|
|
/** The 'Mekanism' class where the tab instance is stored. */
|
2012-11-06 16:44:14 +01:00
|
|
|
public static Class Mekanism;
|
|
|
|
|
2012-11-07 21:01:46 +01:00
|
|
|
/**
|
|
|
|
* Attempts to get the Mekanism creative tab instance from the 'Mekanism' class. Will return
|
2012-11-21 16:14:35 +01:00
|
|
|
* the tab if the mod is loaded, but otherwise will return the defined 'preferred' creative tab. This way
|
|
|
|
* you don't need to worry about NPEs!
|
2013-04-19 21:43:00 +02:00
|
|
|
* @return Mekanism creative tab if can, otherwise preferred tab
|
2012-11-07 21:01:46 +01:00
|
|
|
*/
|
2012-11-15 21:04:12 +01:00
|
|
|
public static CreativeTabs tabMekanism(CreativeTabs preferred)
|
2012-11-06 16:44:14 +01:00
|
|
|
{
|
|
|
|
try {
|
|
|
|
if(Mekanism == null)
|
|
|
|
{
|
|
|
|
Mekanism = Class.forName("mekanism.common.Mekanism");
|
|
|
|
}
|
|
|
|
|
|
|
|
Object ret = Mekanism.getField("tabMekanism").get(null);
|
|
|
|
|
|
|
|
if(ret instanceof CreativeTabs)
|
|
|
|
{
|
|
|
|
return (CreativeTabs)ret;
|
|
|
|
}
|
2013-03-11 18:49:01 +01:00
|
|
|
|
|
|
|
return preferred;
|
2012-11-06 16:44:14 +01:00
|
|
|
} catch(Exception e) {
|
|
|
|
System.err.println("[Mekanism] Error retrieving Mekanism creative tab.");
|
2012-11-15 21:04:12 +01:00
|
|
|
return preferred;
|
2012-11-06 16:44:14 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|