ModTweaker/src/main/java/modtweaker2/helpers/ForgeHelper.java

53 lines
1.9 KiB
Java
Raw Normal View History

package modtweaker2.helpers;
2015-01-11 20:59:45 +01:00
2015-07-07 12:00:17 +02:00
import static modtweaker2.helpers.ReflectionHelper.getConstructor;
import static modtweaker2.helpers.ReflectionHelper.getFinalObject;
2015-07-07 12:00:17 +02:00
import static modtweaker2.helpers.ReflectionHelper.getInstance;
import static modtweaker2.helpers.ReflectionHelper.getStaticObject;
2015-01-11 20:59:45 +01:00
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StatCollector;
import net.minecraftforge.common.ChestGenHooks;
import net.minecraftforge.common.ForgeHooks;
2016-02-27 13:21:27 +01:00
import net.minecraftforge.fml.client.FMLClientHandler;
import net.minecraftforge.fml.common.FMLCommonHandler;
import net.minecraftforge.fml.relauncher.Side;
2015-01-11 20:59:45 +01:00
public class ForgeHelper {
2015-07-07 12:00:17 +02:00
@SuppressWarnings("rawtypes")
2015-01-11 20:59:45 +01:00
public static Map translate = null;
2015-07-07 12:00:17 +02:00
@SuppressWarnings("rawtypes")
2015-01-11 20:59:45 +01:00
public static List seeds = null;
public static HashMap<String, ChestGenHooks> loot = null;
static {
try {
seeds = getStaticObject(ForgeHooks.class, "seedList");
loot = getStaticObject(ChestGenHooks.class, "chestInfo");
translate = getFinalObject(getStaticObject(StatCollector.class, "localizedName", "field_74839_a"), "languageList", "field_74816_c");
2016-02-27 13:21:27 +01:00
} catch (Exception e) {
}
2015-01-11 20:59:45 +01:00
}
2015-07-07 12:00:17 +02:00
private ForgeHelper() {
}
2015-01-11 20:59:45 +01:00
public static Object getSeedEntry(ItemStack stack, int weight) {
2016-02-27 13:21:27 +01:00
Object seedEntry = getInstance(getConstructor("net.minecraftforge.common.ForgeHooks$SeedEntry", ItemStack.class, int.class), stack, weight);
2015-07-07 12:00:17 +02:00
if (seedEntry == null) {
2015-01-11 20:59:45 +01:00
throw new NullPointerException("Failed to instantiate SeedEntry");
}
2015-07-07 12:00:17 +02:00
return seedEntry;
2015-01-11 20:59:45 +01:00
}
public static boolean isLangActive(String lang) {
2016-02-27 13:21:27 +01:00
return FMLCommonHandler.instance().getSide() == Side.SERVER ? null : FMLClientHandler.instance().getCurrentLanguage().equals(lang);
2015-01-11 20:59:45 +01:00
}
}