Java 类net.minecraftforge.oredict.OreIngredient 实例源码

项目: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;
}
项目: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    文件: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)));
}
项目:ArcaneMagic    文件:RecipeHelper.java   
/**
 * Generates a shaped recipe with a specific width and height. The Object[] is the ingredients, in order from left to right, top to bottom.
 */
private static ShapedRecipes genShaped(ItemStack output, int width, int height, Object[] input)
{
    if (input[0] instanceof List)
        input = ((List<?>) input[0]).toArray();
    if (width * height != 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 Item)
        {
            inputL.add(i, Ingredient.fromStacks(new ItemStack((Item) k)));
        } else if (k instanceof Block)
        {
            inputL.add(i, Ingredient.fromStacks(new ItemStack((Block) k)));
        } else
        {
            inputL.add(i, Ingredient.EMPTY);
        }
    }

    return new ShapedRecipes(MODID + ":" + j, width, height, inputL, output);
}
项目:PonySocks2    文件:RecipeSockRainbow.java   
public RecipeSockRainbow(ResourceLocation location, String group) {
    super(location, group, true, 3, 3);

    ingredients.add(new OreIngredient("dyeRed"));
    ingredients.add(Ingredient.EMPTY);
    ingredients.add(new OreIngredient("dyeLime"));

    ingredients.add(new OreIngredient("dyeOrange"));
    ingredients.add(Ingredient.fromStacks(new ItemStack(PonySocks.sock, 1, 0)));
    ingredients.add(new OreIngredient("dyeLightBlue"));

    ingredients.add(new OreIngredient("dyeYellow"));
    ingredients.add(Ingredient.EMPTY);
    ingredients.add(new OreIngredient("dyePurple"));
}
项目:Qbar    文件:QBarRecipeHelper.java   
public static void addIngotToGearRecipe(String metalName)
{
    ItemStack gearStack = new ItemStack(QBarItems.METALGEAR, 1, QBarMaterials.metals.indexOf(metalName));

    QBarRecipeHandler.CRAFTING_RECIPES.add(new ShapedOreRecipe(new ResourceLocation(QBarConstants.MODID, "gear" +
            metalName), gearStack, " X ", "XOX", " X ", 'X',
            new OreIngredient("ingot" + StringUtils.capitalize(metalName)), 'O', new ItemStack(Items.IRON_INGOT))
            .setRegistryName(new ResourceLocation(QBarConstants.MODID, "gear" + metalName)));
}
项目:Qbar    文件:QBarRecipeHelper.java   
public static void addBlockToIngotRecipe(String metalName)
{
    ItemStack ingotStack = new ItemStack(QBarItems.METALINGOT, 9, QBarMaterials.metals.indexOf(metalName));

    QBarRecipeHandler.CRAFTING_RECIPES
            .add(new ShapelessOreRecipe(new ResourceLocation(QBarConstants.MODID, "block" + metalName), ingotStack,
                    new OreIngredient("block" + StringUtils.capitalize(metalName)))
                    .setRegistryName(new ResourceLocation(QBarConstants.MODID, "block" + metalName)));
}
项目:Qbar    文件:QBarRecipeHelper.java   
public static void addIngotToBlockRecipe(String metalName)
{
    ItemStack blockStack = new ItemStack(QBarBlocks.METALBLOCK, 1, QBarMaterials.metals.indexOf(metalName));

    QBarRecipeHandler.CRAFTING_RECIPES
            .add(new ShapedOreRecipe(new ResourceLocation(QBarConstants.MODID, "block_ingot" + metalName),
                    blockStack, "XXX", "XXX", "XXX", 'X',
                    new OreIngredient("ingot" + StringUtils.capitalize(metalName)))
                    .setRegistryName(new ResourceLocation(QBarConstants.MODID, "block_ingot" + metalName)));
}
项目:EnderStorage    文件:Factories.java   
public static Ingredient create() {
    Set<Ingredient> ingredients = new HashSet<>();
    for (EnumColour c : EnumColour.values()) {
        ingredients.add(new OreIngredient(c.getDyeOreName()));
    }
    return new MultiIngredient(ingredients);
}
项目:EnderStorage    文件:Factories.java   
@Nonnull
@Override
public Ingredient parse(JsonContext context, JsonObject json) {
    Set<Ingredient> ingredients = new HashSet<>();
    for (EnumColour c : EnumColour.values()) {
        ingredients.add(new OreIngredient(c.getWoolOreName()));
    }
    return new MultiIngredient(ingredients);
}
项目:Metalworks    文件:Registry.java   
@Override
public void registerRecipes(List<IRecipe> recipes) {
    recipes.add(new ShapelessOreRecipe(null, new ItemStack(steelNugget, 9), new OreIngredient("ingotSteel")));
}
项目:ArcaneMagic    文件:AnalysisStack.java   
protected AnalysisStack(String ore)
{
    this(new OreIngredient(ore));
}
项目:UniversalCoins    文件:UCItemPricer.java   
private void priceCraftedItems() {
    // FMLLog.log.info("in autoPriceCraftedItems");
    Set<ResourceLocation> recipeResourceLocations = CraftingManager.REGISTRY.getKeys();
    boolean priceUpdate = false;

    // we rerun multiple times if needed since recipe components might be
    // priced in previous runs
    int loopCount = 0;
    do {
        loopCount++;
        // FMLLog.log.info("priceUpdate loop: " + loopCount);
        priceUpdate = false;
        for (ResourceLocation rloc : recipeResourceLocations) {
            IRecipe irecipe = CraftingManager.getRecipe(rloc);
            int itemCost = 0;
            boolean validRecipe = true;
            ItemStack output = irecipe.getRecipeOutput();
            // FMLLog.log.info("Recipe output: " + output.getDisplayName());
            if (output == null || output.getItem() == Items.AIR) {
                continue;
            }
            if (UCItemPricer.getInstance().getItemPrice(output) != -1) {
                // FMLLog.log.info("recipe output price already set.");
                continue;
            }
            // FMLLog.log.info("Starting pricing for " +
            // output.getDisplayName());
            NonNullList<Ingredient> recipeItems = irecipe.getIngredients();
            for (int i = 0; i < recipeItems.size(); i++) {
                ItemStack stack = null;
                // FMLLog.log.info("Ingredient: " + recipeItems.get(i));
                if (recipeItems.get(i) instanceof OreIngredient) {
                    OreIngredient test = (OreIngredient) recipeItems.get(i);
                    if (test.getMatchingStacks().length > 0)
                        stack = test.getMatchingStacks()[0];
                    // TODO iterate and check for priced items
                } else {
                    if (recipeItems.get(i).getMatchingStacks().length > 0) {
                        stack = recipeItems.get(i).getMatchingStacks()[0];
                        // TODO do we need to iterate here?
                    }
                }
                if (stack == null)
                    continue;
                // FMLLog.log.info("recipe ingredient " + i + " " +
                // stack.getDisplayName());
                // FMLLog.log.info("price: " +
                // UCItemPricer.getInstance().getItemPrice(stack));
                if (UCItemPricer.getInstance().getItemPrice(stack) != -1) {
                    itemCost += UCItemPricer.getInstance().getItemPrice(stack);
                } else {
                    validRecipe = false;
                    // FMLLog.log.info("can't price " +
                    // output.getDisplayName());
                    break;
                }
            }
            if (validRecipe && itemCost > 0) {
                priceUpdate = true;
                if (output.getCount() > 1) {
                    itemCost = itemCost / output.getCount();
                }
                try {
                    // FMLLog.log.info("Setting price of " +
                    // output.getDisplayName() + " to " + itemCost);
                    UCItemPricer.getInstance().setItemPrice(output, itemCost);
                } catch (Exception e) {
                    FMLLog.log.warn(
                            "Universal Coins Autopricer: Failed to set item price: " + output.getUnlocalizedName());
                }
            }
        }
    } while (priceUpdate == true);
}