Search in sources :

Example 56 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project RFTools by McJty.

the class NBTMatchingRecipe method checkMatch.

/**
 * Checks if the region of a crafting inventory is match for the recipe.
 */
private boolean checkMatch(InventoryCrafting inventoryCrafting, int x, int y, boolean reversed) {
    for (int col = 0; col < 3; ++col) {
        for (int row = 0; row < 3; ++row) {
            int i1 = col - x;
            int j1 = row - y;
            ItemStack itemstack = ItemStack.EMPTY;
            String[] nbt = null;
            if (i1 >= 0 && j1 >= 0 && i1 < this.recipeWidth && j1 < this.recipeHeight) {
                int idx;
                if (reversed) {
                    idx = this.recipeWidth - i1 - 1 + j1 * this.recipeWidth;
                } else {
                    idx = i1 + j1 * this.recipeWidth;
                }
                Ingredient ingredient = this.recipeItems.get(idx);
                if (ingredient.getMatchingStacks().length > 0) {
                    // @todo recipes most likely wrong!
                    itemstack = ingredient.getMatchingStacks()[0];
                } else {
                    itemstack = ItemStack.EMPTY;
                }
                nbt = this.matchingNBTs[idx];
            }
            ItemStack itemstack1 = inventoryCrafting.getStackInRowAndColumn(col, row);
            if (!itemstack1.isEmpty() || !itemstack.isEmpty()) {
                if (itemstack1.isEmpty() || itemstack.isEmpty()) {
                    return false;
                }
                if (itemstack.getItem() != itemstack1.getItem()) {
                    return false;
                }
                if (itemstack.getMetadata() != 32767 && itemstack.getMetadata() != itemstack1.getMetadata()) {
                    return false;
                }
                NBTTagCompound compound = itemstack.getTagCompound();
                NBTTagCompound compound1 = itemstack1.getTagCompound();
                if (nbt != null) {
                    if (compound == null && compound1 != null) {
                        return false;
                    }
                    if (compound != null && compound1 == null) {
                        return false;
                    }
                    if (compound != null) {
                        for (String tagName : nbt) {
                            NBTBase tag = compound.getTag(tagName);
                            NBTBase tag1 = compound1.getTag(tagName);
                            if (tag == null && tag1 != null) {
                                return false;
                            }
                            if (tag != null && tag1 == null) {
                                return false;
                            }
                            if (tag != null) {
                                if (!tag.equals(tag1)) {
                                    return false;
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return true;
}
Also used : NBTBase(net.minecraft.nbt.NBTBase) Ingredient(net.minecraft.item.crafting.Ingredient) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack)

Example 57 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Binnie by ForestryMC.

the class RegistryRecipe method rotateIngredients.

private void rotateIngredients() {
    int offset = 0;
    for (int i = 0; i < input.size(); i++) {
        Ingredient ingredient = input.get(i);
        if (ingredient instanceof OreIngredient) {
            RotatedOreIngredient rotatedOreIngredient = new RotatedOreIngredient("binnie_database", offset);
            input.set(i, rotatedOreIngredient);
            offset++;
        }
    }
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) OreIngredient(net.minecraftforge.oredict.OreIngredient) OreIngredient(net.minecraftforge.oredict.OreIngredient)

Aggregations

Ingredient (net.minecraft.item.crafting.Ingredient)57 ItemStack (net.minecraft.item.ItemStack)49 ResourceLocation (net.minecraft.util.ResourceLocation)12 ArrayList (java.util.ArrayList)10 JsonElement (com.google.gson.JsonElement)8 JsonObject (com.google.gson.JsonObject)7 List (java.util.List)7 IRecipe (net.minecraft.item.crafting.IRecipe)7 JsonArray (com.google.gson.JsonArray)6 Block (net.minecraft.block.Block)6 Item (net.minecraft.item.Item)6 HashMap (java.util.HashMap)5 IBlockState (net.minecraft.block.state.IBlockState)5 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)5 FluidStack (net.minecraftforge.fluids.FluidStack)5 JsonParser (com.google.gson.JsonParser)4 File (java.io.File)4 FileNotFoundException (java.io.FileNotFoundException)4 FileReader (java.io.FileReader)4 EntityItem (net.minecraft.entity.item.EntityItem)4