Java 类net.minecraft.item.crafting.Ingredient 实例源码

项目:Minecoprocessors    文件:ItemBookCode.java   
@SubscribeEvent
public static void registerRecipes(final RegistryEvent.Register<IRecipe> event) {
  NonNullList<Ingredient> lst = NonNullList.create();
  lst.add(Ingredient.fromItem(Items.WRITABLE_BOOK));
  lst.add(Ingredient.fromItem(BlockMinecoprocessor.ITEM_INSTANCE));
  event.getRegistry().register(new ShapelessRecipes("", new ItemStack(ItemBookCode.INSTANCE), lst) {
    @Override
    public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv) {
      NonNullList<ItemStack> l = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY);

      for (int i = 0; i < l.size(); ++i) {
        ItemStack stack = inv.getStackInSlot(i);

        if (stack.getItem() == BlockMinecoprocessor.ITEM_INSTANCE) {
          ItemStack returnStack = stack.copy();
          returnStack.setCount(1);
          l.set(i, returnStack);
          return l;
        }
      }

      throw new RuntimeException("Item to return not found in inventory");
    }
  }.setRegistryName(ItemBookCode.REGISTRY_NAME));
}
项目:Bewitchment    文件:Ritual.java   
/**
 * Constructs a new ritual. To be registered within the registry
 *
 * @param input       a NonNullList<ItemStack> with all and every itemstack required to be a valid ritual
 * @param output      a NonNullList<ItemStack> with all and every itemstack that should get dropped on the ground when the ritual stops
 * @param timeInTicks the time in ticks that the ritual takes to stop. Negative values will have the ritual going on indefinitely. Zero means that the effect/crafting is applied immediately
 * @param circles     is the byte annotation to define what circles are needed. It follows this pattern 332211TT where 33, 22, 11 are the glyph type of the nth circle, and TT the number of required circles, 0 being 1, 2 being 3. 3 (11) will always return a failed circle
 */
public Ritual(ResourceLocation registryName, @Nonnull NonNullList<Ingredient> input, @Nonnull NonNullList<ItemStack> output, int timeInTicks, int circles, int altarStartingPower, int powerPerTick) {
    this.time = timeInTicks;

    for (int i = 0; i < input.size(); i++) {
        Ingredient ing = input.get(i);
        if (ing.getMatchingStacks().length == 0)
            throw new IllegalArgumentException("Ritual inputs must be valid: ingredient #" + i + " for " + registryName + " has no matching items");
    }

    this.input = input;
    this.output = output;
    this.circles = circles;
    this.altarStartingPower = altarStartingPower;
    this.tickPower = powerPerTick;
    setRegistryName(registryName);
    if (input.size() == 0) throw new IllegalArgumentException("Cannot have an empty input in a ritual");
}
项目:Torched    文件:RecipeTorchGun.java   
@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");
    if(ings.size() > 9)
        throw new JsonParseException("Too many ingredients for shapeless recipe");

    ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
    return new RecipeTorchGun(group, itemstack, ings);
}
项目:Got-Wood    文件:GotWood.java   
@SubscribeEvent
public void registerSpecialRecipes(RegistryEvent.Register<IRecipe> event) {
    if (ConfigurationHandler.retrieveSaplingsMode == 2) {
        ResourceLocation group = new ResourceLocation(GotWood.ID);
        GameRegistry.addShapelessRecipe(new ResourceLocation("oak_seed"), group, new ItemStack(Blocks.SAPLING, 1, 0), Ingredient.fromStacks(new ItemStack(ItemRegistry.oak_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("spruce_seed"), group, new ItemStack(Blocks.SAPLING, 1, 1), Ingredient.fromStacks(new ItemStack(ItemRegistry.spruce_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("birch_seed"), group, new ItemStack(Blocks.SAPLING, 1, 2), Ingredient.fromStacks(new ItemStack(ItemRegistry.birch_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("jungle_seed"), group, new ItemStack(Blocks.SAPLING, 1, 3), Ingredient.fromStacks(new ItemStack(ItemRegistry.jungle_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("acacia_seed"), group, new ItemStack(Blocks.SAPLING, 1, 4), Ingredient.fromStacks(new ItemStack(ItemRegistry.acacia_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("dark_oak_seed"), group, new ItemStack(Blocks.SAPLING, 1, 5), Ingredient.fromStacks(new ItemStack(ItemRegistry.dark_oak_seed)));

        GameRegistry.addShapelessRecipe(new ResourceLocation("apple_seed"), group, new ItemStack(BlockRegistry.apple_sapling), Ingredient.fromStacks(new ItemStack(ItemRegistry.apple_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("maple_seed"), group, new ItemStack(BlockRegistry.maple_sapling), Ingredient.fromStacks(new ItemStack(ItemRegistry.maple_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("pine_seed"), group, new ItemStack(BlockRegistry.pine_sapling), Ingredient.fromStacks(new ItemStack(ItemRegistry.pine_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("willow_seed"), group, new ItemStack(BlockRegistry.willow_sapling), Ingredient.fromStacks(new ItemStack(ItemRegistry.willow_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("yew_seed"), group, new ItemStack(BlockRegistry.yew_sapling), Ingredient.fromStacks(new ItemStack(ItemRegistry.yew_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("ebony_seed"), group, new ItemStack(BlockRegistry.ebony_sapling), Ingredient.fromStacks(new ItemStack(ItemRegistry.ebony_seed)));
        GameRegistry.addShapelessRecipe(new ResourceLocation("fir_seed"), group, new ItemStack(BlockRegistry.fir_sapling), Ingredient.fromStacks(new ItemStack(ItemRegistry.fir_seed)));
    }
}
项目:ArcaneMagic    文件:ShapelessArcaneTransfigurationRecipe.java   
/**
 * For every ingredient, we need to check each itemstack.
 * Then, if we find a match, mark that itemstack so it cannot be checked again.
 */

@Override
public boolean matches(EntityPlayer player, ItemStack wand, NonNullList<ItemStack> stacks, World world)
{
    List<ItemStack> toCheck = Lists.newArrayList(stacks);
    for (Ingredient i : this.inputs)
    {
        for (int ix = 0; ix < toCheck.size(); ix++)
        {
            if (i.apply(toCheck.get(ix)))
            {
                toCheck.remove(ix);
                break;
            } else if (i == Ingredient.EMPTY && toCheck.get(ix).isEmpty())
                toCheck.remove(ix);
        }
    }

    IArcaneTransfigurationItem crafter = (IArcaneTransfigurationItem) wand.getItem();
    if (!crafter.matches(this, player, wand, stacks, world))
        return false;
    return toCheck.isEmpty() && (anima.isEmpty() || (crafter.containsAnimus()
            && wand.getCapability(IAnimaStorage.CAP, null).take(anima, true) == null));
}
项目:ArcaneMagic    文件:ShapedArcaneTransfigurationRecipe.java   
@Override
public boolean matches(EntityPlayer player, ItemStack wand, NonNullList<ItemStack> stacks, World world)
{
    for (int i = 0; i < 9; i++)
    {
        if (this.inputs.get(i) == Ingredient.EMPTY && stacks.get(i).isEmpty())
            continue;
        if (!this.inputs.get(i).apply(stacks.get(i)))
            return false;
    }

    IArcaneTransfigurationItem crafter = (IArcaneTransfigurationItem) wand.getItem();
    if (!crafter.matches(this, player, wand, stacks, world))
        return false;
    return anima.isEmpty() || (crafter.containsAnimus()
            && wand.getCapability(IAnimaStorage.CAP, null).take(anima, true) == null);
}
项目:ArcaneMagic    文件:RecipeHelper.java   
/**
 * Same thing as genShaped above, but uses a specific group.
 */
private static ShapedRecipes genShaped(String group, ItemStack output, int l, int w, Object[] input)
{
    if (input[0] instanceof List)
        input = ((List<?>) input[0]).toArray();
    if (l * w != input.length)
        throw new UnsupportedOperationException(
                "Attempted to add invalid shaped recipe.  Complain to the author of " + MODNAME);
    NonNullList<Ingredient> inputL = NonNullList.create();
    for (int i = 0; i < input.length; i++)
    {
        Object k = input[i];
        if (k instanceof String)
            inputL.add(i, new OreIngredient((String) k));
        else if (k instanceof ItemStack && !((ItemStack) k).isEmpty())
            inputL.add(i, Ingredient.fromStacks((ItemStack) k));
        else if (k instanceof IForgeRegistryEntry)
            inputL.add(i, Ingredient.fromStacks(makeStack((IForgeRegistryEntry<?>) k)));
        else
            inputL.add(i, Ingredient.EMPTY);
    }

    return new ShapedRecipes(group, l, w, inputL, output);
}
项目:ArcaneMagic    文件:RecipeHelper.java   
/**
 * Creates a list of ingredients based on an Object[].  Valid types are {@link String}, {@link ItemStack}, {@link Item}, and {@link Block}.
 * Used for shapeless recipes.
 */
private static NonNullList<Ingredient> createInput(Object[] input)
{
    if (input[0] instanceof List)
        input = ((List<?>) input[0]).toArray();
    else if (input[0] instanceof Object[])
        input = (Object[]) input[0];
    NonNullList<Ingredient> inputL = NonNullList.create();
    for (int i = 0; i < input.length; i++)
    {
        Object k = input[i];
        if (k instanceof String)
            inputL.add(i, new OreIngredient((String) k));
        else if (k instanceof ItemStack && !((ItemStack) k).isEmpty())
            inputL.add(i, Ingredient.fromStacks((ItemStack) k));
        else if (k instanceof IForgeRegistryEntry)
            inputL.add(i, Ingredient.fromStacks(makeStack((IForgeRegistryEntry<?>) k)));
        else
            throw new UnsupportedOperationException(
                    "Attempted to add invalid shapeless recipe.  Complain to the author of " + MODNAME);
    }
    return inputL;
}
项目:ArcaneMagic    文件:RecipeHelper.java   
/**
 * Creates a list of ingredients based on an Object[].  Valid types are {@link String}, {@link ItemStack}, {@link Item}, and {@link Block}.
 * Used for elemental recipes.
 */
private static NonNullList<Ingredient> createElementalInput(Object[] input)
{
    if (input[0] instanceof List)
        input = ((List<?>) input[0]).toArray();
    else if (input[0] instanceof Object[])
        input = (Object[]) input[0];
    NonNullList<Ingredient> inputL = NonNullList.withSize(9, Ingredient.EMPTY);
    for (int i = 0; i < input.length; i++)
    {
        Object k = input[i];
        if (k instanceof String)
            inputL.set(i, new OreIngredient((String) k));
        else if (k instanceof ItemStack && !((ItemStack) k).isEmpty())
            inputL.set(i, Ingredient.fromStacks((ItemStack) k));
        else if (k instanceof IForgeRegistryEntry)
            inputL.set(i, Ingredient.fromStacks(makeStack((IForgeRegistryEntry<?>) k)));
    }
    return inputL;
}
项目:Randores2    文件:RandoresForgeUpgradeRecipeFactory.java   
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    int clamp = JsonUtils.getInt(json, "clamp");
    boolean combining = JsonUtils.getBoolean(json, "combining");

    JsonArray upgradeList = JsonUtils.getJsonArray(json, "upgrades");
    Map<Ingredient, Double> upgrades = new LinkedHashMap<>();
    int n = 0;
    for (JsonElement element : upgradeList) {
        if (element.isJsonObject()) {
            JsonObject upgrade = element.getAsJsonObject();
            double amount = JsonUtils.getFloat(upgrade, "amount");
            Ingredient ingredient = CraftingHelper.getIngredient(upgrade.get("ingredient"), context);
            upgrades.put(ingredient, amount);
        } else {
            throw new JsonSyntaxException("Expected " + n + " to be a JsonObject, was " + JsonUtils.toString(json));
        }
        n++;
    }

    return new RandoresForgeUpgradeRecipe(clamp, combining, upgrades);
}
项目:PurificatiMagicae    文件:MagibenchShapelessRecipe.java   
public MagibenchShapelessRecipe(@Nonnull ItemStack result, int minTier, String entryId, Object... recipe)
{
    setTier(minTier);
    setEntry(entryId);
    out = result.copy();
    for (Object in : recipe)
    {
        Ingredient ing = CraftingHelper.getIngredient(in);
        if (ing != null)
        {
            ingredients.add(ing);
            this.simple &= ing.isSimple();
        }
        else
        {
            StringBuilder ret = new StringBuilder("Invalid shapeless ore recipe: ");
            for (Object tmp :  recipe)
            {
                ret.append(tmp).append(", ");
            }
            ret.append(out);
            throw new RuntimeException(ret.toString());
        }
    }
}
项目:Adventurers-Toolbox    文件:ModRecipes.java   
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);
}
项目:customstuff4    文件:ItemHelper.java   
@SuppressWarnings("unchecked")
public static boolean isSameRecipeInput(Ingredient target, Object input)
{
    if (input instanceof String)
    {
        NonNullList<ItemStack> ores = OreDictionary.getOres(input.toString());
        return ores.stream().allMatch(target::apply);
    } else if (input instanceof ItemStack)
    {
        return target.apply((ItemStack) input);
    } else if (input instanceof NonNullList)
    {
        NonNullList<ItemStack> items = (NonNullList<ItemStack>) input;
        return items.stream().anyMatch(target::apply);
    } else
    {
        throw new IllegalArgumentException("Invalid input: " + input);
    }
}
项目:customstuff4    文件:ShapelessRecipe.java   
private boolean matchesInput(ShapelessRecipes recipe)
{
    if (isOreRecipe())
        return false;
    if (recipe.recipeItems.size() != getRecipeSize())
        return false;

    Object[] input = getRecipeInput();

    for (int i = 0; i < recipe.recipeItems.size(); i++)
    {
        Ingredient target = recipe.recipeItems.get(i);
        ItemStack source = (ItemStack) input[i];

        if (!target.apply(source))
            return false;
    }

    return true;
}
项目:customstuff4    文件:ShapelessRecipe.java   
private boolean matchesInput(ShapelessOreRecipe recipe)
{
    if (recipe.getIngredients().size() != getRecipeSize())
        return false;

    Object[] input = getRecipeInput();

    for (int i = 0; i < recipe.getIngredients().size(); i++)
    {
        Ingredient target = recipe.getIngredients().get(i);
        Object source = input[i];

        if (!ItemHelper.isSameRecipeInput(target, source))
            return false;
    }
    return true;
}
项目:customstuff4    文件:ItemHelperTests.java   
@Test
public void test_isSameRecipeInput()
{
    assertTrue(ItemHelper.isSameRecipeInput(new OreIngredient("stickWood"), "stickWood"));
    assertFalse(ItemHelper.isSameRecipeInput(new OreIngredient("stickWood"), "oreIron"));

    assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.APPLE), new ItemStack(Items.APPLE)));
    assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.APPLE), new ItemStack(Items.DIAMOND_SWORD)));

    NonNullList<ItemStack> stickWoodList = OreDictionary.getOres("stickWood");
    ItemStack[] stickWood = stickWoodList.toArray(new ItemStack[0]);

    assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), stickWoodList));
    assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), OreDictionary.getOres("ingotIron")));

    assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), new ItemStack(Items.STICK)));
    assertTrue(ItemHelper.isSameRecipeInput(Ingredient.fromItem(Items.STICK), stickWoodList));
    assertFalse(ItemHelper.isSameRecipeInput(Ingredient.fromStacks(stickWood), new ItemStack(Items.DIAMOND_PICKAXE)));
}
项目:CompositeGear    文件:IC2IngredientFactory.java   
@Override
public Ingredient parse(JsonContext context, JsonObject json)
{
    String name = JsonUtils.getString(json, "name");

    ItemStack stack = null;

    // If item with variant.
    if (name.contains("#")) {
        String[] parts = name.split("#");
        stack = IC2Items.getItem(parts[0], parts[1]);
    } else {
        stack = IC2Items.getItem(name);
    }

    if (stack == null)
        throw new JsonSyntaxException("IC2 item with name " + name + " could not be found");

    return Ingredient.fromStacks(stack);
}
项目:PonySocks2    文件:RecipeBase.java   
protected boolean matchesShaped(InventoryCrafting inv) {
    for (int iy = 0; iy <= inv.getHeight() - 2; iy++) {
        for (int ix = 0; ix <= inv.getWidth() - 3; ix++) {
            boolean foundMistake = false;
            innerLoop: for (int y = 0; y < 2; y++) {
                for (int x = 0; x < 3; x++) {
                    Ingredient ingredient = ingredients.get(y*3 + x);
                    if (!ingredient.apply(inv.getStackInRowAndColumn(ix+x, iy+y))) {
                        foundMistake = true;
                        break innerLoop;
                    }
                }
            }

            if (!foundMistake) {
                return true;
            }
        }
    }

    return false;
}
项目:Wizardry    文件:ManaRecipeJEI.java   
@Override
public void getIngredients(@Nonnull IIngredients ingredients) {
    List<List<ItemStack>> stacks = Lists.newArrayList();
    stacks.add(Lists.newArrayList(builder.getMainInput().getMatchingStacks()));
    for (Ingredient ingredient : builder.getInputs())
        stacks.add(Lists.newArrayList(ingredient.getMatchingStacks()));

    if (!isFluidOutput())
        for (List<ItemStack> stackList : stacks)
            stackList.removeIf(Ingredient.fromStacks(builder.getOutput())::apply);

    ingredients.setInputLists(ItemStack.class, stacks);
    ingredients.setInput(FluidStack.class, new FluidStack(FluidMana.instance, 1000));

    if (isFluidOutput())
        ingredients.setOutput(FluidStack.class, builder.getFluidOutput());
    else
        ingredients.setOutput(ItemStack.class, builder.getOutput());
}
项目:Wizardry    文件:RecipeShapelessFluidFactory.java   
@Override
public IRecipe parse(JsonContext context, JsonObject json)
{
    String group = JsonUtils.getString(json, "group", "");
    NonNullList<Ingredient> ingredients = NonNullList.create();
    for (JsonElement element : JsonUtils.getJsonArray(json, "ingredients"))
        ingredients.add(CraftingHelper.getIngredient(element, context));

    if (ingredients.isEmpty())
        throw new JsonParseException("No ingredients in shapeless recipe");

    ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
    RecipeShapelessFluid recipe = new RecipeShapelessFluid(group.isEmpty() ? null : new ResourceLocation(group), result, ingredients);

    return recipe;
}
项目:Gravestone-mod-Extended    文件:GSPotion.java   
@SubscribeEvent
public static void registerPotionTypes(final RegistryEvent.Register<PotionType> event) {
    event.getRegistry().registerAll(PURIFICATION_TYPE, RUST_TYPE, BONE_SKIN_TYPE, RECALL_TYPE, BURNING_TYPE, BLEEDING_TYPE,
            INFERNO_TYPE);
    event.getRegistry().registerAll(HUNGER_TYPE, BLINDNESS_TYPE, NAUSEA_TYPE, RESISTANCE_TYPE, LEVITATION_TYPE);

    PotionHelper.addMix(PotionTypes.AWKWARD, GSItem.TOXIC_SLIME, RUST_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.GOLDEN_KOI.ordinal())), PURIFICATION_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.BONE_FISH.ordinal())), BONE_SKIN_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.SPECULAR_FISH.ordinal())), RECALL_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.MAGMA_JELLYFISH.ordinal())), BURNING_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.PIRANHA.ordinal())), BLEEDING_TYPE);
    PotionHelper.addMix(BURNING_TYPE, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.FLAREFIN_KOI.ordinal())), INFERNO_TYPE);

    // vanilla potions
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(Items.FISH, 1, 2)), PotionType.getPotionTypeForName("luck"));
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(Items.ROTTEN_FLESH, 1)), HUNGER_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.BLUE_JELLYFISH.ordinal())), NAUSEA_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.SPOOKYFIN.ordinal())), BLINDNESS_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.CAVEFISH.ordinal())), RESISTANCE_TYPE);
    PotionHelper.addMix(PotionTypes.AWKWARD, Ingredient.fromStacks(new ItemStack(GSItem.FISH, 1, ItemFish.EnumFishType.CHORUS_KOI.ordinal())), LEVITATION_TYPE);
}
项目:EnderStorage    文件:RecipeBase.java   
@Override
public boolean matches(InventoryCrafting inv, World worldIn) {
    for (int i = 0; i < 3; ++i) {
        for (int j = 0; j < 3; ++j) {
            Ingredient ingredient = Ingredient.EMPTY;

            if (i >= 0 && j >= 0 && i < 3 && j < 3) {
                ingredient = this.input.get(i + j * 3);
            }

            if (!ingredient.apply(inv.getStackInRowAndColumn(i, j))) {
                return false;
            }
        }
    }

    return true;
}
项目:Malgra    文件:ExtractorIngredientFactory.java   
@Nonnull
@Override
public Ingredient parse(JsonContext context, JsonObject json) {
    final ItemStack stack = CraftingHelper.getItemStack(json, context);

    Item tip = JsonUtils.getItem(json, "tip");
    Item container = JsonUtils.getItem(json, "container");

    stack.setTagCompound(new NBTTagCompound());
    if (stack.getTagCompound() != null) {
        stack.getTagCompound().setString("tip", tip.getRegistryName().getResourcePath());
        stack.getTagCompound().setString("uses", container.getRegistryName().getResourcePath());
    }

    return new IngredientNBT(stack);
}
项目:Bonfires    文件:EstusFlaskIngredientFactory.java   
@Nonnull
@Override
public Ingredient parse(JsonContext context, JsonObject json) {

    final ItemStack stack = CraftingHelper.getItemStack(json, context);

    int estus = JsonUtils.getInt(json, "estus", 0);
    int uses = JsonUtils.getInt(json, "uses", 0);

    stack.setTagCompound(new NBTTagCompound());
    if (stack.getTagCompound() != null) {
        stack.getTagCompound().setInteger("estus", estus);
        stack.getTagCompound().setInteger("uses", uses);
    }

    return new IngredientNBT(stack);
}
项目:Cyclic    文件:RecipeRegistry.java   
private static NonNullList<Ingredient> convertToNonNullList(Object[] input) {
  NonNullList<Ingredient> list = NonNullList.create();
  for (Object any : input) {
    if (any instanceof Ingredient) {
      list.add((Ingredient) any);
    }
    else {
      Ingredient ing = CraftingHelper.getIngredient(any);
      if (ing == null) {
        ing = Ingredient.EMPTY;// EMPTY/.. same as new Ingredient(new ItemStack[0])
      }
      list.add(ing);
    }
  }
  return list;
}
项目:Ender-Rift    文件:RecipeRiftDuplication.java   
@Override
public NonNullList<Ingredient> getIngredients()
{
    return NonNullList.from(
            Ingredient.EMPTY,
            Ingredient.fromItem(Items.MAGMA_CREAM),
            Ingredient.fromItem(Items.ENDER_PEARL),
            Ingredient.fromItem(Items.MAGMA_CREAM),
            Ingredient.fromItem(Items.ENDER_PEARL),
            Ingredient.fromItem(EnderRiftMod.riftOrb),
            Ingredient.fromItem(Items.ENDER_PEARL),
            Ingredient.fromItem(Items.MAGMA_CREAM),
            Ingredient.fromItem(Items.ENDER_PEARL),
            Ingredient.fromItem(Items.MAGMA_CREAM)
    );
}
项目:AbyssalCraft    文件:APIUtils.java   
/**
 * Converts an Object to an ItemStack, if possible
 * @param obj Object to convert
 * @return An ItemStack, or a ClassCastException if not possible
 */
public static ItemStack convertToStack(Object obj){
    if(obj == null)
        return ItemStack.EMPTY;
    else if(obj instanceof ItemStack)
        return ((ItemStack)obj).copy();
    else if(obj instanceof Item)
        return new ItemStack((Item)obj);
    else if(obj instanceof Block)
        return new ItemStack((Block)obj);
    else if(obj instanceof Ingredient)
        return ((Ingredient) obj).getMatchingStacks().length > 0 ? ((Ingredient) obj).getMatchingStacks()[0].copy() : ItemStack.EMPTY;
        else if(obj instanceof ItemStack[])
            return ((ItemStack[])obj)[0].copy();
        else if(obj instanceof String)
            return OreDictionary.getOres((String)obj).get(0).copy();
        else if(obj instanceof List)
            return ((ItemStack)((List) obj).get(0)).copy();
        else throw new ClassCastException("Not a Item, Block, ItemStack, Ingredient, Array of ItemStacks, String or List of ItemStacks!");
}
项目:Runes-of-Wizardry    文件:DustRegistry.java   
/**
 * 
 * @param materials the recipe to infuse the dust 
 * @param blockIn the block/item to be infused (usually a block of inert dust)
 * @param blockOut the result (usually a block of your dust)
 */
public static void registerBlockInfusion(ItemStack[] materials, ItemStack blockIn, ItemStack blockOut){
    RunesOfWizardry.log().info("Registering infusion for "+blockOut);
    // FUTURE temporary until we figure out what we want
    Ingredient[] recipe = new Ingredient[materials.length + 1];
    for (int i = 0; i < materials.length; i++) {
        recipe[i] = Ingredient.fromStacks(materials[i]);
    }
    recipe[materials.length] = Ingredient.fromStacks(blockIn);
    // TODO figure out how to add generated recipes/custom recipe types.
    GameRegistry.addShapelessRecipe(
            new ResourceLocation(References.modid,
                    blockOut.getItem().getRegistryName().toString().replace(':', '_') + "_infusion"
                            + blockOut.getMetadata()),
            new ResourceLocation(References.modid, "infusion"), blockOut, recipe);
}
项目:Runes-of-Wizardry    文件:WizardryRegistry.java   
/**Create the (vanilla) recipes**/
public static void initCrafting(){
    GameRegistry.addSmelting(nether_paste, new ItemStack(lavastone,1), 0.2F);

    //Crafting the blocks
    for(IDustStorageBlock dustBlock:DustRegistry.getAllBlocks()){
        IDust dustclass = dustBlock.getIDust();
        String modID = dustclass.getRegistryName().getResourceDomain();
        for(int i:dustclass.getMetaValues()){
            GameRegistry.addShapedRecipe(new ResourceLocation(References.modid,modID+"_"+dustclass.getName()+"_to_block"+i),null,new ItemStack(dustBlock.getInstance(), 1, i), 
                    new Object[]{"XXX","XXX","XXX",'X',new ItemStack(dustclass,1,i)});

            ItemStack block = new ItemStack(dustBlock.getInstance(), 1, i);

            GameRegistry.addShapelessRecipe(new ResourceLocation(References.modid,modID+"_"+dustclass.getName()+"_from_block"+i),null,
                    new ItemStack(dustclass,9,i), Ingredient.fromStacks(block));

        }
    }

}
项目:OpenBlocks    文件:MapResizeRecipe.java   
private static ShapedPrimer createExample() {
    final ShapedPrimer example = new ShapedPrimer();
    example.width = 3;
    example.height = 3;

    Ingredient e = Ingredient.fromStacks(MetasGeneric.mapMemory.newItemStack());
    Ingredient m = Ingredient.fromStacks(ItemEmptyMap.createMap(Items.emptyMap, 0));

    example.input = NonNullList.from(
            Ingredient.EMPTY,
            Ingredient.EMPTY, e, Ingredient.EMPTY,
            e, m, e,
            Ingredient.EMPTY, e, Ingredient.EMPTY);

    return example;
}
项目:ThermionicsWorld    文件:ThermionicsWorld.java   
public static void addMeatCompressionRecipe(IForgeRegistry<IRecipe> registry, EnumEdibleMeat meat, boolean cooked, ItemStack ingredient) {
    ResourceLocation group = new ResourceLocation("thermionics_world", "compress.meat");
    Ingredient input = Ingredient.fromStacks(ingredient);
    ShapedRecipes recipe = 
            new ShapedRecipes(group.toString(), 3, 3,
            NonNullList.withSize(3*3, input),
            new ItemStack(TWBlocks.MEAT_EDIBLE, 1, BlockMeatEdible.getMetaFromValue(meat, cooked)) );
    recipe.setRegistryName(new ResourceLocation("thermionics_world", meat.getName()+((cooked)?".cooked":".raw")+"_CompressToBlock"));
    registry.register(recipe);
}
项目:pnc-repressurized    文件:Helper.java   
/**
 * Returns a string representation of the item which can also be used in scripts
 */
@SuppressWarnings("rawtypes")
public static String getStackDescription(Object object) {
    if(object instanceof IIngredient) {
        return getStackDescription((IIngredient) object);
    } else if(object instanceof ItemStack) {
        return toIItemStack((ItemStack) object).toString();
    } else if(object instanceof FluidStack) {
        return getStackDescription((FluidStack) object);
    } else if(object instanceof Block) {
        return toIItemStack(new ItemStack((Block) object, 1, 0)).toString();
    } else if(object instanceof String) {
        // Check if string specifies an oredict entry
        List<ItemStack> ores = OreDictionary.getOres((String) object);

        if(!ores.isEmpty()) {
            return "<ore:" + (String) object + ">";
        } else {
            return "\"" + (String) object + "\"";
        }
    } else if(object instanceof List) {
        return getListDescription((List) object);
    } else if(object instanceof Object[]) {
        return getListDescription(Arrays.asList((Object[]) object));
    } else if(object != null) {
        return "\"" + object.toString() + "\"";
    } else if(object instanceof Ingredient && !((Ingredient) object).apply(ItemStack.EMPTY) && ((Ingredient) object).getMatchingStacks().length > 0) {
        return getStackDescription(((Ingredient) object).getMatchingStacks()[0]);
    } else {
        return "null";
    }
}
项目:pnc-repressurized    文件:CraftingRegistrator.java   
/**
 * Adds recipes like 9 gold ingot --> 1 gold block, and 1 gold block --> 9 gold ingots.
 */
public static void addPressureChamberStorageBlockRecipes() {
    // search for a 3x3 recipe where all 9 ingredients are the same
    for (IRecipe recipe : CraftingManager.REGISTRY) {
        if (recipe instanceof ShapedRecipes) {
            ShapedRecipes shaped = (ShapedRecipes) recipe;
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            ItemStack ref = ingredients.get(0).getMatchingStacks()[0];
            if (ref.isEmpty() || ingredients.size() < 9) continue;
            boolean valid = true;
            for (int i = 0; i < 9; i++) {
                ItemStack stack = ingredients.get(i).getMatchingStacks()[0];
                if (!stack.isItemEqual(ref)) {
                    valid = false;
                    break;
                }
            }
            if (valid) {
                ItemStack inputStack = ref.copy();
                inputStack.setCount(9);
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[]{inputStack}, 1.0F, new ItemStack[]{shaped.getRecipeOutput()}, false));

                ItemStack inputStack2 = shaped.getRecipeOutput().copy();
                inputStack2.setCount(1);
                PressureChamberRecipe.chamberRecipes.add(new PressureChamberRecipe(new ItemStack[]{inputStack2}, -0.5F, new ItemStack[]{inputStack}, false));

            }
        }
    }
}
项目:pnc-repressurized    文件:CraftingRegistrator.java   
private static void scanForFluids(ShapedOreRecipe recipe) {
    for (int i = 0; i < recipe.getIngredients().size(); i++) {
        Ingredient ingredient = recipe.getIngredients().get(i);
        for (ItemStack stack : ingredient.getMatchingStacks()) {
            FluidStack fluid = FluidUtil.getFluidContained(stack);
            if (fluid != null) {
                ForgeRegistries.RECIPES.register(new RecipeFluid(recipe, i));
            }
        }
    }
}
项目:pnc-repressurized    文件:RecipeFluid.java   
public RecipeFluid(ShapedOreRecipe recipe, int fluidIndex) {
    super("fluid_recipe_" + recipeIndex++);
    this.recipe = recipe;
    Ingredient ingredient = recipe.getIngredients().get(fluidIndex);
    originalStack = ingredient.getMatchingStacks()[0];
    fluidStack = FluidUtil.getFluidContained(originalStack);
    if (fluidStack == null)
        throw new IllegalArgumentException("Recipe doesn't have fluid item at index " + fluidIndex + ". Item: " + originalStack);
    this.fluidIndex = fluidIndex;
}
项目:Soot    文件:JEI.java   
private List<RecipeDawnstoneAnvil> generateDawnstoneAnvilRecipes()
{
    //I'm basicly sorry for all of this. Please forgive me.
    ArrayList<RecipeDawnstoneAnvil> repairRecipes = new ArrayList<>();
    ArrayList<RecipeDawnstoneAnvil> destroyRecipes = new ArrayList<>();

    for (Item item : Item.REGISTRY) {
        ItemStack stack = item.getDefaultInstance();
        ItemStack repairItem = ItemStack.EMPTY;
        try {
            repairItem = Misc.getRepairItem(stack);
        }
        catch (Exception e) { //Gotta catch em all
            e.printStackTrace();
        }
        boolean isRepairable = item.getIsRepairable(stack, repairItem);
        boolean materiaAllowed = item.isRepairable();
        if(isRepairable || materiaAllowed)
        {
            ArrayList<ItemStack> repairMaterials = new ArrayList<>();
            repairMaterials.add(repairItem.copy());
            if(materiaAllowed)
                repairMaterials.add(new ItemStack(RegistryManager.isolated_materia));
            ItemStack[] repairMaterialsArray = repairMaterials.toArray(new ItemStack[repairMaterials.size()]);
            repairRecipes.add(new RecipeDawnstoneAnvil(new ItemStack[]{stack.copy()}, Ingredient.fromStacks(makeDamaged(stack)),Ingredient.fromStacks(repairMaterialsArray)));
            if(Misc.getResourceCount(stack) != -1) {
                ItemStack material = repairItem.copy();
                material.setCount(Misc.getResourceCount(stack));
                destroyRecipes.add(new RecipeDawnstoneAnvil(new ItemStack[]{material}, Ingredient.fromStacks(makeDamaged(stack)), Ingredient.EMPTY));
            }
        }
    }

    return Stream.concat(repairRecipes.stream(),destroyRecipes.stream()).collect(Collectors.toList());
}
项目:Industrial-Foregoing    文件:PageRecipe.java   
@SideOnly(Side.CLIENT)
@Override
public void drawScreenPre(CategoryEntry entry, GUIBookBase base, int mouseX, int mouseY, float partialTicks, FontRenderer renderer) {
    //base.drawCenteredString(renderer, TextFormatting.AQUA+"Recipe"+TextFormatting.RESET, base.getGuiLeft()+base.getGuiXSize()/2,base.getGuiTop()+30,0xFFFFFF);
    base.mc.getTextureManager().bindTexture(GUIBookBase.BOOK_EXTRAS);
    base.drawTexturedModalRect(base.getGuiLeft() + 20, base.getGuiTop() + 64, 45, 1, 124, 62);
    int pos = 0;
    RenderHelper.enableGUIStandardItemLighting();
    for (Ingredient ingredient : recipe.getIngredients()) {
        if (ingredient != null && ingredient.getMatchingStacks().length > 0)
            base.mc.getRenderItem().renderItemIntoGUI(ingredient.getMatchingStacks()[0], base.getGuiLeft() + 25 + (pos % 3) * 18, base.getGuiTop() + 69 + (pos / 3) * 18);
        ++pos;
    }
    base.mc.getRenderItem().renderItemIntoGUI(recipe.getRecipeOutput(), base.getGuiLeft() + 25 + 94, base.getGuiTop() + 69 + 18);
}
项目:Bewitchment    文件:Ritual.java   
public boolean isValidInput(List<ItemStack> ground, boolean circles) {
    ArrayList<ItemStack> checklist = new ArrayList<ItemStack>(ground.size());
    for (ItemStack item : ground)
        for (int j = 0; j < item.getCount(); j++) {
            ItemStack copy = item.copy();
            copy.setCount(1);
            checklist.add(copy);
        }

    if (checklist.size() != input.size()) {
        return false;
    }
    ArrayList<Ingredient> removalList = new ArrayList<Ingredient>(input);

    for (ItemStack stack_on_ground : checklist) {
        Ingredient found = null;
        for (Ingredient ingredient : removalList) {
            if (ingredient.apply(stack_on_ground)) {
                found = ingredient;
                break;
            }
        }
        if (found == null) {
            return false; //The stack on the ground doesn't belong to the rite
        }
        removalList.remove(found);
    }
    if (!removalList.isEmpty()) {
        return false;
    }
    return circles;
}
项目:Bewitchment    文件:SpinnerWrapper.java   
@Override
public void getIngredients(IIngredients ingredients) {
    ArrayList<List<ItemStack>> list = new ArrayList<List<ItemStack>>();
    for (Ingredient i : input) list.add(Arrays.asList(i.getMatchingStacks()));
    ingredients.setInputLists(ItemStack.class, list);
    ingredients.setOutput(ItemStack.class, output);
}
项目:Bewitchment    文件:ModSpinningThreadRecipes.java   
public static void init() {
    Ingredient string = Ingredient.fromItem(Items.STRING);
    web = new SpinningThreadRecipe(LibMod.MOD_ID, "spider_web", new ItemStack(Blocks.WEB), string, string, string);
    // soulstring = new SpinningThreadRecipe(LibMod.MOD_ID, "soulstring", new ItemStack(ModItems.soulstring), string, string, Ingredient.fromStacks(new ItemStack(ModItems.misc, 1, 5)), Ingredient.fromStacks(new ItemStack(ModItems.flowers, 1, 1)));

    registerAll();
}