net.minecraftforge.common.crafting.CraftingHelper Java Examples

The following examples show how to use net.minecraftforge.common.crafting.CraftingHelper. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MetaItemShapelessRecipeFactory.java    From GregTech with GNU Lesser General Public License v3.0 6 votes vote down vote up
@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);
}
 
Example #2
Source File: DamageableShapelessOreRecipe.java    From customstuff4 with GNU General Public License v3.0 5 votes vote down vote up
@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");

    ItemStack itemstack = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);

    int[] damage = new int[ings.size()];
    if (JsonUtils.hasField(json, "damage"))
    {
        JsonArray array = JsonUtils.getJsonArray(json, "damage");
        if (array.size() > damage.length)
            throw new JsonParseException("Too many values for damage array: got " + array.size() + ", expected " + damage.length);

        for (int i = 0; i < array.size(); i++)
        {
            JsonElement element = array.get(i);
            if (!element.isJsonPrimitive() || !element.getAsJsonPrimitive().isNumber())
                throw new JsonSyntaxException("Entry in damage array is not a number, got " + element);

            damage[i] = element.getAsJsonPrimitive().getAsInt();
        }
    }
    return new DamageableShapelessOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), damage, ings, itemstack);
}
 
Example #3
Source File: RecipeShapelessFluidFactory.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
@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;
}
 
Example #4
Source File: ManaRecipes.java    From Wizardry with GNU Lesser General Public License v3.0 5 votes vote down vote up
public static String[] getResourceListing(String mod, String path) {
	List<String> all = Lists.newArrayList();
	if (CraftingHelper.findFiles(Loader.instance().getIndexedModList().get(mod), "assets/" + mod + "/" + path, null,
			(root, full) -> all.add(root.relativize(full).toString()), false, false))
		return all.toArray(new String[0]);
	return new String[0];
}
 
Example #5
Source File: Module.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
@Deprecated
public static void registerRecipe(RegistryEvent.Register<IRecipe> event, String registryName,
    ItemStack out, Object... in) {
    CraftingHelper.ShapedPrimer primer = CraftingHelper.parseShaped(in);
    event.getRegistry()
        .register(new ShapedRecipes(ValkyrienSkiesMod.MOD_ID, primer.width, primer.height,
            primer.input, out).setRegistryName(ValkyrienSkiesMod.MOD_ID, registryName));
}
 
Example #6
Source File: ValkyrienSkiesMod.java    From Valkyrien-Skies with Apache License 2.0 5 votes vote down vote up
private static void registerRecipe(RegistryEvent.Register<IRecipe> event,
    String registryName, ItemStack out, Object... in) {
    CraftingHelper.ShapedPrimer primer = CraftingHelper.parseShaped(in);
    event.getRegistry()
        .register(new ShapedRecipes(ValkyrienSkiesMod.MOD_ID, primer.width, primer.height,
            primer.input, out)
            .setRegistryName(ValkyrienSkiesMod.MOD_ID, registryName));
}
 
Example #7
Source File: SurvivalistMod.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void registerRecipeSerializers(RegistryEvent.Register<IRecipeSerializer<?>> event)
{
    CraftingHelper.register(ConfigurationCondition.Serializer.INSTANCE);
    CraftingHelper.register(ConfigToggledIngredientSerializer.NAME, ConfigToggledIngredientSerializer.INSTANCE);

    event.getRegistry().registerAll(
            new DryingRecipe.Serializer().setRegistryName("drying"),
            new ChoppingRecipe.Serializer().setRegistryName("chopping")
    );
}
 
Example #8
Source File: ConfigToggledIngredientSerializer.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Ingredient parse(JsonObject json)
{
    String categoryName = JSONUtils.getString(json, "category");
    String keyName = JSONUtils.getString(json, "key");

    return new ConfigToggledIngredient(
            categoryName, keyName,
            CraftingHelper.getIngredient(json.getAsJsonObject("then")),
            CraftingHelper.getIngredient(json.getAsJsonObject("else"))
    );
}
 
Example #9
Source File: CustomWoodShapedRecipe.java    From AgriCraft with MIT License 5 votes vote down vote up
@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    ShapedOreRecipe fake = ShapedOreRecipe.factory(context, json);
    CraftingHelper.ShapedPrimer primer = new CraftingHelper.ShapedPrimer();
    primer.width = fake.getRecipeWidth();
    primer.height = fake.getRecipeHeight();
    primer.input = fake.getIngredients();
    primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true); // Hack
    return new CustomWoodShapedRecipe(fake.getRegistryName(), fake.getRecipeOutput(), primer);
}
 
Example #10
Source File: ShapedOreEnergyTransferRecipe.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
public ShapedOreEnergyTransferRecipe(ResourceLocation group, @Nonnull ItemStack result, Predicate<ItemStack> chargePredicate, boolean transferMaxCharge, Object... recipe) {
    this(group, result, chargePredicate, transferMaxCharge, CraftingHelper.parseShaped(recipe));
}
 
Example #11
Source File: MetaTileEntityLockedSafe.java    From GregTech with GNU Lesser General Public License v3.0 4 votes vote down vote up
private static Ingredient createIngredient(Object ingredient) {
    return CraftingHelper.getIngredient(ModHandler.finalizeIngredient(ingredient));
}
 
Example #12
Source File: DamageableShapedOreRecipe.java    From customstuff4 with GNU General Public License v3.0 4 votes vote down vote up
private DamageableShapedOreRecipe(@Nullable ResourceLocation group, int[] damageAmounts, @Nonnull ItemStack result, CraftingHelper.ShapedPrimer primer)
{
    super(group, result, primer);
    this.damageAmounts = damageAmounts;
    mirroredDamageAmounts = mirror(damageAmounts);
}
 
Example #13
Source File: CustomWoodShapedRecipe.java    From AgriCraft with MIT License 4 votes vote down vote up
public CustomWoodShapedRecipe(ResourceLocation id, ItemStack result, CraftingHelper.ShapedPrimer primer) {
    super(id, result, primer);
}