Search in sources :

Example 1 with MixPredicate

use of net.minecraft.potion.PotionHelper.MixPredicate in project Random-Things by lumien231.

the class ModRecipes method addGlowingMushroomRecipes.

public static void addGlowingMushroomRecipes() {
    try {
        Field listField = PotionHelper.class.getDeclaredField(MCPNames.field("field_185213_a"));
        ReflectionUtil.makeModifiable(listField);
        Field inputField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185198_a"));
        ReflectionUtil.makeModifiable(inputField);
        Field reagentField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185199_b"));
        ReflectionUtil.makeModifiable(reagentField);
        Field outputField = MixPredicate.class.getDeclaredField(MCPNames.field("field_185200_c"));
        ReflectionUtil.makeModifiable(outputField);
        List<PotionHelper.MixPredicate<PotionType>> conversionList = (List<MixPredicate<PotionType>>) listField.get(null);
        List<MixPredicate<PotionType>> toAdd = new ArrayList<MixPredicate<PotionType>>();
        for (MixPredicate<PotionType> p : conversionList) {
            Ingredient reagent = (Ingredient) reagentField.get(p);
            if (reagent.test(new ItemStack(Items.GLOWSTONE_DUST))) {
                PotionType input = (PotionType) inputField.get(p);
                PotionType output = (PotionType) outputField.get(p);
                toAdd.add(new MixPredicate<PotionType>(input, Ingredient.fromItem(Item.getItemFromBlock(ModBlocks.glowingMushroom)), output));
            }
        }
        RandomThings.instance.logger.log(Level.DEBUG, "Added " + toAdd.size() + " Glowing Mushroom Recipes");
        conversionList.addAll(toAdd);
    } catch (Exception e) {
        RandomThings.instance.logger.log(Level.ERROR, "Couldn't add glowing mushroom potion recipes, please report this as a bug");
        e.printStackTrace();
    }
}
Also used : Field(java.lang.reflect.Field) Ingredient(net.minecraft.item.crafting.Ingredient) ItemIngredient(lumien.randomthings.item.ItemIngredient) ArrayList(java.util.ArrayList) MixPredicate(net.minecraft.potion.PotionHelper.MixPredicate) ArrayList(java.util.ArrayList) NonNullList(net.minecraft.util.NonNullList) List(java.util.List) PotionType(net.minecraft.potion.PotionType) ItemStack(net.minecraft.item.ItemStack)

Aggregations

Field (java.lang.reflect.Field)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ItemIngredient (lumien.randomthings.item.ItemIngredient)1 ItemStack (net.minecraft.item.ItemStack)1 Ingredient (net.minecraft.item.crafting.Ingredient)1 MixPredicate (net.minecraft.potion.PotionHelper.MixPredicate)1 PotionType (net.minecraft.potion.PotionType)1 NonNullList (net.minecraft.util.NonNullList)1