Search in sources :

Example 1 with IForgeRegistryModifiable

use of net.minecraftforge.registries.IForgeRegistryModifiable in project Adventurers-Toolbox by the-realest-stu.

the class CommonProxy method processRecipes.

protected void processRecipes() {
    if (ForgeRegistries.RECIPES instanceof IForgeRegistryModifiable) {
        IForgeRegistryModifiable registry = (IForgeRegistryModifiable) ForgeRegistries.RECIPES;
        Entry<ResourceLocation, IRecipe>[] recipeEntries = ForgeRegistries.RECIPES.getEntries().toArray(new Entry[ForgeRegistries.RECIPES.getEntries().size()]);
        for (int recipeIndex = 0; recipeIndex < recipeEntries.length; recipeIndex++) {
            Entry<ResourceLocation, IRecipe> recipeEntry = recipeEntries[recipeIndex];
            IRecipe recipe = recipeEntry.getValue();
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            Item output = recipe.getRecipeOutput().getItem();
            String rp = output.getRegistryName().getResourcePath();
            if ((output instanceof ItemHoe || output instanceof ItemAxe || output instanceof ItemSpade || output instanceof ItemPickaxe || output instanceof ItemSword) || (output instanceof ItemTool && (rp.contains("pick") || rp.contains("axe") || rp.contains("shovel") || rp.contains("spade"))) || (output instanceof ItemTool && (output.getRegistryName().getResourceDomain().equals("thermalfoundation") && rp.contains("hammer")))) {
                String materialName = output instanceof ItemHoe ? ((ItemHoe) output).getMaterialName() : output instanceof ItemSword ? ((ItemSword) output).getToolMaterialName() : ((ItemTool) output).getToolMaterialName();
                if (Materials.canReplaceMaterial(materialName, recipe.getRecipeOutput())) {
                    // System.out.println(materialName);
                    registry.remove(recipeEntry.getKey());
                    registry.register(new IRecipe() {

                        private ResourceLocation registryName;

                        @Override
                        public IRecipe setRegistryName(ResourceLocation name) {
                            this.registryName = name;
                            return this;
                        }

                        @Override
                        public ResourceLocation getRegistryName() {
                            return this.registryName;
                        }

                        @Override
                        public Class<IRecipe> getRegistryType() {
                            return IRecipe.class;
                        }

                        @Override
                        public boolean matches(InventoryCrafting inv, World worldIn) {
                            return false;
                        }

                        @Override
                        public ItemStack getCraftingResult(InventoryCrafting inv) {
                            return ItemStack.EMPTY;
                        }

                        @Override
                        public boolean canFit(int width, int height) {
                            return false;
                        }

                        @Override
                        public ItemStack getRecipeOutput() {
                            return ItemStack.EMPTY;
                        }
                    }.setRegistryName(recipeEntry.getKey()));
                    removed_recipes.add(recipeEntry.getKey());
                } else {
                    System.out.println(output.getRegistryName() + " -> " + materialName);
                }
            } else {
                for (int i = 0; i < ingredients.size(); i++) {
                    ItemStack[] matchingStacks = ingredients.get(i).getMatchingStacks();
                    boolean flag = false;
                    Item ingredientItem = null;
                    for (int j = 0; j < matchingStacks.length && !flag; j++) {
                        Item item = matchingStacks[j].getItem();
                        if (!getToolReplacement(item).isEmpty()) {
                            ingredientItem = item;
                            flag = true;
                        }
                    }
                    if (flag && ingredientItem != null && !getToolReplacement(ingredientItem).isEmpty()) {
                        ingredients.set(i, new IngredientNBT(getToolReplacement(ingredientItem)) {
                        });
                    }
                }
            }
        }
    }
}
Also used : ItemSword(net.minecraft.item.ItemSword) ItemAxe(net.minecraft.item.ItemAxe) IForgeRegistryModifiable(net.minecraftforge.registries.IForgeRegistryModifiable) ItemTool(net.minecraft.item.ItemTool) IngredientNBT(net.minecraftforge.common.crafting.IngredientNBT) IRecipe(net.minecraft.item.crafting.IRecipe) InventoryCrafting(net.minecraft.inventory.InventoryCrafting) World(net.minecraft.world.World) Item(net.minecraft.item.Item) ItemHoe(net.minecraft.item.ItemHoe) Entry(java.util.Map.Entry) Ingredient(net.minecraft.item.crafting.Ingredient) ItemSpade(net.minecraft.item.ItemSpade) ResourceLocation(net.minecraft.util.ResourceLocation) ItemPickaxe(net.minecraft.item.ItemPickaxe) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IForgeRegistryModifiable

use of net.minecraftforge.registries.IForgeRegistryModifiable in project harvestcraft by MatrexsVigil.

the class RecipeRemoval method registerRecipes.

@SubscribeEvent
public static void registerRecipes(RegistryEvent.Register<IRecipe> event) {
    ResourceLocation bread = new ResourceLocation("minecraft:bread");
    IForgeRegistryModifiable modRegistry = (IForgeRegistryModifiable) event.getRegistry();
    modRegistry.remove(bread);
    ResourceLocation rabbitstew = new ResourceLocation("minecraft:rabbit_stew");
    modRegistry.remove(rabbitstew);
    ResourceLocation beetrootsoup = new ResourceLocation("minecraft:beetroot_soup");
    modRegistry.remove(beetrootsoup);
    ResourceLocation mushroomstew = new ResourceLocation("minecraft:mushroom_stew");
    modRegistry.remove(mushroomstew);
    ResourceLocation cookie = new ResourceLocation("minecraft:cookie");
    modRegistry.remove(cookie);
    ResourceLocation pumpkinpie = new ResourceLocation("minecraft:pumpkin_pie");
    modRegistry.remove(pumpkinpie);
    ResourceLocation bakedpotato = new ResourceLocation("minecraft:baked_potato");
    modRegistry.remove(bakedpotato);
}
Also used : IForgeRegistryModifiable(net.minecraftforge.registries.IForgeRegistryModifiable) ResourceLocation(net.minecraft.util.ResourceLocation) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

ResourceLocation (net.minecraft.util.ResourceLocation)2 IForgeRegistryModifiable (net.minecraftforge.registries.IForgeRegistryModifiable)2 Entry (java.util.Map.Entry)1 InventoryCrafting (net.minecraft.inventory.InventoryCrafting)1 Item (net.minecraft.item.Item)1 ItemAxe (net.minecraft.item.ItemAxe)1 ItemHoe (net.minecraft.item.ItemHoe)1 ItemPickaxe (net.minecraft.item.ItemPickaxe)1 ItemSpade (net.minecraft.item.ItemSpade)1 ItemStack (net.minecraft.item.ItemStack)1 ItemSword (net.minecraft.item.ItemSword)1 ItemTool (net.minecraft.item.ItemTool)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 Ingredient (net.minecraft.item.crafting.Ingredient)1 World (net.minecraft.world.World)1 IngredientNBT (net.minecraftforge.common.crafting.IngredientNBT)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1