Search in sources :

Example 11 with ItemTool

use of net.minecraft.item.ItemTool 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)

Aggregations

ItemTool (net.minecraft.item.ItemTool)11 Item (net.minecraft.item.Item)9 ItemStack (net.minecraft.item.ItemStack)6 ItemSword (net.minecraft.item.ItemSword)5 ItemHoe (net.minecraft.item.ItemHoe)4 IBlockState (net.minecraft.block.state.IBlockState)3 Minecraft (net.minecraft.client.Minecraft)2 FontRenderer (net.minecraft.client.gui.FontRenderer)2 ItemArmor (net.minecraft.item.ItemArmor)2 ItemAxe (net.minecraft.item.ItemAxe)2 ItemBow (net.minecraft.item.ItemBow)2 ItemFishingRod (net.minecraft.item.ItemFishingRod)2 ItemPickaxe (net.minecraft.item.ItemPickaxe)2 WeightedItemStack (cavern.util.WeightedItemStack)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Collection (java.util.Collection)1 Entry (java.util.Map.Entry)1 Optional (java.util.Optional)1 Set (java.util.Set)1 UUID (java.util.UUID)1