diff --git a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java index 86693e4..075ff36 100644 --- a/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java +++ b/src/main/java/xyz/pixelatedw/finalbeta/WyHelper.java @@ -2,6 +2,7 @@ package xyz.pixelatedw.finalbeta; import java.lang.management.ManagementFactory; import java.lang.reflect.Field; +import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.time.Duration; import java.util.HashMap; @@ -37,12 +38,30 @@ public class WyHelper { return INSTANCE; } else { try { - Field f = Minecraft.class.getDeclaredFields()[1]; - f.setAccessible(true); - return (Minecraft) f.get(null); - } catch (SecurityException | IllegalArgumentException | IllegalAccessException e) { + Field field = null; + + try { + field = Minecraft.class.getDeclaredField("instance"); + } catch (NoSuchFieldException ex) { + try { + field = Minecraft.class.getDeclaredField("field_2791"); + } catch (NoSuchFieldException | SecurityException e) { + e.printStackTrace(); + } + } catch (Exception e) { + e.printStackTrace(); + } + + if (field == null) { + return null; + } + + field.setAccessible(true); + return (Minecraft) field.get(null); + } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } + return null; } } @@ -70,15 +89,31 @@ public class WyHelper { } public static void registerWhiteWoolRecipe() { - Method method = RecipeRegistry.class.getDeclaredMethods()[2]; - method.setAccessible(true); + Method method = null; try { - // Makes new recipes for all colored wools so they can be dyed back white using bone meal + method = RecipeRegistry.class.getDeclaredMethod("addShapelessRecipe", ItemInstance.class, Object[].class); + } catch (NoSuchMethodException ex) { + try { + method = RecipeRegistry.class.getDeclaredMethod("method_542", ItemInstance.class, Object[].class); + } catch (NoSuchMethodException | SecurityException e) { + e.printStackTrace(); + } + } + + if (method == null) { + return; + } + + try { + method.setAccessible(true); + + // Makes new recipes for all colored wools so they can be dyed back + // white using bone meal for (int colorId = 0; colorId < 16; ++colorId) { method.invoke(RecipeRegistry.getInstance(), new ItemInstance(Tile.WOOL, 1, 0), new Object[]{ new ItemInstance(Tile.WOOL, 1, WoolTile.method_2(colorId)), new ItemInstance(ItemType.dyePowder, 1, 15)}); } - } catch (Exception ex) { + } catch (SecurityException | IllegalAccessException | IllegalArgumentException | InvocationTargetException ex) { ex.printStackTrace(); } }