Search in sources :

Example 1 with IngredientNBT

use of net.minecraftforge.common.crafting.IngredientNBT in project Adventurers-Toolbox by the-realest-stu.

the class ModRecipes method getToolHeadSchematicRecipe.

private static IRecipe getToolHeadSchematicRecipe(ItemStack output, String material, String type, int cost) {
    NonNullList<Ingredient> inputs = NonNullList.withSize(cost + 1, Ingredient.EMPTY);
    ItemStack schematic = new ItemStack(ModItems.schematic);
    NBTTagCompound nbt = new NBTTagCompound();
    nbt.setString(ItemSchematic.type_tag, type);
    schematic.setTagCompound(nbt);
    Ingredient schematicIngredient = new IngredientNBT(schematic) {
    };
    inputs.set(0, schematicIngredient);
    for (int i = 1; i <= cost; i++) {
        inputs.set(i, new OreIngredient(material));
    }
    return new ShapelessOreRecipe(null, inputs, output);
}
Also used : IngredientNBT(net.minecraftforge.common.crafting.IngredientNBT) Ingredient(net.minecraft.item.crafting.Ingredient) OreIngredient(net.minecraftforge.oredict.OreIngredient) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) OreIngredient(net.minecraftforge.oredict.OreIngredient) ItemStack(net.minecraft.item.ItemStack)

Example 2 with IngredientNBT

use of net.minecraftforge.common.crafting.IngredientNBT 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

ItemStack (net.minecraft.item.ItemStack)2 Ingredient (net.minecraft.item.crafting.Ingredient)2 IngredientNBT (net.minecraftforge.common.crafting.IngredientNBT)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 ItemSword (net.minecraft.item.ItemSword)1 ItemTool (net.minecraft.item.ItemTool)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 World (net.minecraft.world.World)1 OreIngredient (net.minecraftforge.oredict.OreIngredient)1 ShapelessOreRecipe (net.minecraftforge.oredict.ShapelessOreRecipe)1 IForgeRegistryModifiable (net.minecraftforge.registries.IForgeRegistryModifiable)1