Search in sources :

Example 6 with ShapedPrimer

use of net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer in project MC-Prefab by Brian-Wuest.

the class ModRegistry method AddShapedRecipe.

/**
 * This should only be used for registering recipes for vanilla objects and not mod-specific objects.
 * @param name The name of the recipe. ModID is pre-pended to it.
 * @param stack The output of the recipe.
 * @param recipeComponents The recipe components.
 */
public static ShapedRecipes AddShapedRecipe(String name, String groupName, ItemStack stack, Object... recipeComponents) {
    name = Prefab.MODID.toLowerCase().replace(' ', '_') + ":" + name;
    ShapedPrimer primer = CraftingHelper.parseShaped(recipeComponents);
    ShapedRecipes shapedrecipes = new ShapedRecipes(groupName, primer.width, primer.height, primer.input, stack);
    shapedrecipes.setRegistryName(name);
    ForgeRegistries.RECIPES.register(shapedrecipes);
    return shapedrecipes;
}
Also used : ShapedPrimer(net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer) ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes)

Example 7 with ShapedPrimer

use of net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer in project Wizardry by TeamWizardry.

the class RecipeShapedFluidFactory method parse.

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    String group = JsonUtils.getString(json, "group", "");
    Map<Character, Ingredient> ingredientMap = new HashMap<>();
    ingredientMap.put(' ', Ingredient.EMPTY);
    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.");
        ingredientMap.put(entry.getKey().toCharArray()[0], CraftingHelper.getIngredient(entry.getValue(), context));
    }
    JsonArray jsonPattern = JsonUtils.getJsonArray(json, "pattern");
    if (jsonPattern.size() == 0)
        throw new JsonSyntaxException("Invalid pattern: empty pattern not allowed");
    String[] pattern = new String[jsonPattern.size()];
    for (int x = 0; x < pattern.length; x++) {
        String line = JsonUtils.getString(jsonPattern.get(x), "pattern[" + x + "]");
        if (x > 0 && pattern[0].length() != line.length())
            throw new JsonSyntaxException("Invalid pattern: each row must be the same width");
        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(ingredientMap.keySet());
    keys.remove(' ');
    int x = 0;
    for (String line : pattern) {
        for (char c : line.toCharArray()) {
            Ingredient ingredient = ingredientMap.get(c);
            if (ingredient == null)
                throw new JsonSyntaxException("Pattern references symbol '" + c + "' but it's not defined in the key");
            primer.input.set(x++, ingredient);
            keys.remove(c);
        }
    }
    if (!keys.isEmpty())
        throw new JsonSyntaxException("Key defineds symbols that aren't used in pattern: " + keys);
    ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
    RecipeShapedFluid recipe = new RecipeShapedFluid(group.isEmpty() ? null : new ResourceLocation(group), result, primer);
    return recipe;
}
Also used : HashMap(java.util.HashMap) 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)

Aggregations

ShapedPrimer (net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer)7 ResourceLocation (net.minecraft.util.ResourceLocation)6 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)5 JsonArray (com.google.gson.JsonArray)3 JsonSyntaxException (com.google.gson.JsonSyntaxException)3 ItemStack (net.minecraft.item.ItemStack)3 Ingredient (net.minecraft.item.crafting.Ingredient)3 JsonElement (com.google.gson.JsonElement)2 JsonObject (com.google.gson.JsonObject)2 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 BaseMetals (com.mcmoddev.basemetals.BaseMetals)1 Options (com.mcmoddev.lib.util.ConfigBase.Options)1 MetaItem (gregtech.api.items.metaitem.MetaItem)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Set (java.util.Set)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)1 JsonUtils (net.minecraft.util.JsonUtils)1