Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package net.minecraft.src;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Method;
- public class GenuineForgeCompat {
- public static boolean init;
- public static boolean forgeInstalled;
- public static Class minecraftForge;
- public static Class achievementPage;
- public static Method ladder;
- public static Method loot;
- public static Method achieve;
- public static boolean forgeLadderHook(Block block, World world, int x, int y, int z) {
- if (!init)
- load();
- if (block == null || !forgeInstalled)
- return false;
- try {
- return (Boolean) ladder.invoke(block, world, x, y, z);
- }
- catch (IllegalArgumentException e) { }
- catch (IllegalAccessException e) { }
- catch (InvocationTargetException e) { }
- return false;
- }
- public static void forgeAddDungeonLoot(ItemStack item, float rarity) {
- if (!init)
- load();
- try {
- loot.invoke(null, item, rarity);
- }
- catch (IllegalArgumentException e) { }
- catch (IllegalAccessException e) { }
- catch (InvocationTargetException e) { }
- }
- public static void forgeAddAchievementPage(String name, Achievement... achievements) {
- if (!init)
- load();
- try {
- Object page = achievementPage.getConstructor(String.class, Achievement[].class).newInstance(name, achievements);
- achieve.invoke(null, page);
- }
- catch (SecurityException e) { }
- catch (NoSuchMethodException e) { }
- catch (IllegalArgumentException e) { }
- catch (InstantiationException e) { }
- catch (IllegalAccessException e) { }
- catch (InvocationTargetException e) { }
- }
- public static void load() {
- if (init)
- return;
- forgeInstalled = ModLoader.isModLoaded("mod_MinecraftForge") || ModLoader.isModLoaded("net.minecraft.src.mod_MinecraftForge");
- if (forgeInstalled) {
- minecraftForge = defineClass("forge.MinecraftForge", "net.minecraft.src.forge.MinecraftForge");
- achievementPage = defineClass("forge.AchievementPage", "net.minecraft.src.forge.AchievementPage");
- if (minecraftForge != null) {
- ladder = defineMethod(Block.class, "isLadder", World.class, int.class, int.class, int.class);
- loot = defineMethod(minecraftForge, "addDungeonLoot", ItemStack.class, float.class);
- achieve = defineMethod(minecraftForge, "registerAchievementPage", achievementPage);
- }
- }
- init = true;
- }
- private static Class defineClass(String... classNames) {
- for (String name : classNames) {
- try {
- return Class.forName(name);
- }
- catch (ClassNotFoundException e) { }
- }
- return null;
- }
- private static Method defineMethod(Class class1, String methodName, Class... args) {
- try {
- return class1.getDeclaredMethod(methodName, args);
- }
- catch (SecurityException e) { }
- catch (NoSuchMethodException e) { }
- return null;
- }
- }
Advertisement