Search in sources :

Example 1 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project Totemic by TeamTotemic.

the class PageCraftingRecipe method renderCraftingRecipe.

@SideOnly(Side.CLIENT)
private void renderCraftingRecipe(IGuiLexiconEntry gui) {
    int x = 0;
    int y = 0;
    for (Ingredient ingredient : recipe.getIngredients()) {
        if (ingredient != Ingredient.EMPTY) {
            ItemStack[] stacks = ingredient.getMatchingStacks();
            renderItemAtGridPos(gui, 1 + x, 1 + y, stacks[recipeIndex % stacks.length], true);
        }
        x++;
        if (x >= recipeWidth) {
            x = 0;
            y++;
        }
    }
    renderItemAtGridPos(gui, 2, 0, recipe.getRecipeOutput(), false);
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project GregTech by GregTechCE.

the class MetaItemShapedRecipeFactory method parse.

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    String group = JsonUtils.getString(json, "group", "");
    Map<Character, Ingredient> ingMap = Maps.newHashMap();
    for (Entry<String, JsonElement> entry : JsonUtils.getJsonObject(json, "key").entrySet()) {
        if (entry.getKey().length() != 1)
            throw new JsonSyntaxException("Invalid key entry: '" + entry.getKey() + "' is an invalid symbol (must be 1 character only).");
        if (" ".equals(entry.getKey()))
            throw new JsonSyntaxException("Invalid key entry: ' ' is a reserved symbol.");
        ingMap.put(entry.getKey().toCharArray()[0], CraftingHelper.getIngredient(entry.getValue(), context));
    }
    ingMap.put(' ', Ingredient.EMPTY);
    JsonArray patternJ = JsonUtils.getJsonArray(json, "pattern");
    if (patternJ.size() == 0)
        throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
    String[] pattern = new String[patternJ.size()];
    for (int x = 0; x < pattern.length; ++x) {
        String line = JsonUtils.getString(patternJ.get(x), "pattern[" + x + "]");
        if (x > 0 && pattern[0].length() != line.length())
            throw new JsonSyntaxException("Invalid pattern: each row must  be the same imageWidth");
        pattern[x] = line;
    }
    ShapedPrimer primer = new ShapedPrimer();
    primer.width = pattern[0].length();
    primer.height = pattern.length;
    primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true);
    primer.input = NonNullList.withSize(primer.width * primer.height, Ingredient.EMPTY);
    Set<Character> keys = Sets.newHashSet(ingMap.keySet());
    keys.remove(' ');
    int x = 0;
    for (String line : pattern) {
        for (char chr : line.toCharArray()) {
            Ingredient ing = ingMap.get(chr);
            if (ing == null)
                throw new JsonSyntaxException("Pattern references symbol '" + chr + "' but it's not defined in the key");
            primer.input.set(x++, ing);
            keys.remove(chr);
        }
    }
    if (!keys.isEmpty())
        throw new JsonSyntaxException("Key defines symbols that aren't used in pattern: " + keys);
    JsonObject result = JsonUtils.getJsonObject(json, "result");
    String name = JsonUtils.getString(result, "name");
    int amount = JsonUtils.getInt(result, "amount", 1);
    ItemStack stack = ItemStack.EMPTY;
    for (MetaItem<?> item : MetaItems.ITEMS) {
        MetaItem<?>.MetaValueItem value = item.getItem(name);
        if (value != null) {
            stack = value.getStackForm(amount);
        }
    }
    return new ShapedOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), stack, primer);
}
Also used : MetaItem(gregtech.api.items.metaitem.MetaItem) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) JsonObject(com.google.gson.JsonObject) JsonArray(com.google.gson.JsonArray) ShapedPrimer(net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer) JsonSyntaxException(com.google.gson.JsonSyntaxException) Ingredient(net.minecraft.item.crafting.Ingredient) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Example 3 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project GregTech by GregTechCE.

the class MetaItemShapelessRecipeFactory method parse.

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    String group = JsonUtils.getString(json, "group", "");
    NonNullList<Ingredient> ings = NonNullList.create();
    for (JsonElement ele : JsonUtils.getJsonArray(json, "ingredients")) ings.add(CraftingHelper.getIngredient(ele, context));
    if (ings.isEmpty())
        throw new JsonParseException("No ingredients for shapeless recipe");
    JsonObject result = JsonUtils.getJsonObject(json, "result");
    String name = JsonUtils.getString(result, "name");
    int amount = JsonUtils.getInt(result, "amount", 1);
    ItemStack stack = ItemStack.EMPTY;
    for (MetaItem<?> item : MetaItems.ITEMS) {
        MetaItem<?>.MetaValueItem value = item.getItem(name);
        if (value != null) {
            stack = value.getStackForm(amount);
        }
    }
    return new ShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), ings, stack);
}
Also used : MetaItem(gregtech.api.items.metaitem.MetaItem) JsonObject(com.google.gson.JsonObject) JsonParseException(com.google.gson.JsonParseException) Ingredient(net.minecraft.item.crafting.Ingredient) JsonElement(com.google.gson.JsonElement) ResourceLocation(net.minecraft.util.ResourceLocation) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ItemStack(net.minecraft.item.ItemStack)

Example 4 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project RFToolsDimensions 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 5 with Ingredient

use of net.minecraft.item.crafting.Ingredient in project SilentGems by SilentChaos512.

the class ItemToolSoul method addRecipes.

@Override
public void addRecipes(RecipeMaker recipes) {
    if (ModRecipes.ADD_SOUL_RECIPES) {
        // FIXME? JEI only shows wheat souls?
        NonNullList<ItemStack> listSouls = NonNullList.create();
        ModItems.soulGem.getSubItems(ModItems.soulGem.getCreativeTab(), listSouls);
        Ingredient ingSouls = Ingredient.fromStacks(listSouls.toArray(new ItemStack[listSouls.size()]));
        recipe = recipes.addShaped("tool_soul", new ItemStack(this), " s ", "scs", " s ", 's', ingSouls, 'c', ModItems.craftingMaterial.soulShell);
    }
}
Also used : Ingredient(net.minecraft.item.crafting.Ingredient) ItemStack(net.minecraft.item.ItemStack)

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