Search in sources :

Example 1 with ShapedPrimer

use of net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer in project BaseMetals by MinecraftModDevelopmentMods.

the class ConfigVariedOutput method parse.

@Override
public IRecipe parse(final JsonContext context, final JsonObject json) {
    String confKey = JsonUtils.getString(json, "config_key");
    int resAmount = 0;
    switch(confKey) {
        case "gear":
            resAmount = Options.gearQuantity();
            break;
        case "plate":
            resAmount = Options.plateQuantity();
            break;
        default:
            BaseMetals.logger.error("Unknown quantity config value {}, setting to 1", confKey);
            resAmount = 1;
    }
    // load the data here, map the ingredients, setup the primer and return the ShapedOreRecipe :)
    final Map<Character, Ingredient> ingMap = Maps.newHashMap();
    JsonUtils.getJsonObject(json, "key").entrySet().stream().filter(ent -> ent.getKey().length() == 1 && !ent.getKey().isEmpty()).forEach(ent -> ingMap.put(ent.getKey().toCharArray()[0], CraftingHelper.getIngredient(ent.getValue(), context)));
    ingMap.put(' ', Ingredient.EMPTY);
    JsonArray patternJ = JsonUtils.getJsonArray(json, "pattern");
    if (patternJ.size() == 0) {
        throw new JsonSyntaxException("Invalid pattern: empty pattern not allows");
    }
    final String[] pattern = new String[patternJ.size()];
    for (int x = 0; x < pattern.length; ++x) {
        final 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 width");
        }
        pattern[x] = line;
    }
    final ShapedPrimer primer = new ShapedPrimer();
    primer.width = pattern[0].length();
    primer.height = pattern.length;
    primer.mirrored = true;
    primer.input = NonNullList.withSize(primer.width * primer.height, Ingredient.EMPTY);
    final Set<Character> keys = Sets.newHashSet(ingMap.keySet());
    keys.remove(' ');
    int x = 0;
    for (final String line : pattern) {
        for (final char chr : line.toCharArray()) {
            final 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);
    }
    final String group = JsonUtils.getString(json, "group", "");
    final ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
    result.setCount(resAmount);
    return new ShapedOreRecipe(group.isEmpty() ? null : new ResourceLocation(group), result, primer);
}
Also used : JsonObject(com.google.gson.JsonObject) IRecipe(net.minecraft.item.crafting.IRecipe) Ingredient(net.minecraft.item.crafting.Ingredient) IRecipeFactory(net.minecraftforge.common.crafting.IRecipeFactory) JsonSyntaxException(com.google.gson.JsonSyntaxException) JsonContext(net.minecraftforge.common.crafting.JsonContext) Set(java.util.Set) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) ItemStack(net.minecraft.item.ItemStack) ShapedPrimer(net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer) JsonArray(com.google.gson.JsonArray) BaseMetals(com.mcmoddev.basemetals.BaseMetals) Map(java.util.Map) JsonUtils(net.minecraft.util.JsonUtils) ResourceLocation(net.minecraft.util.ResourceLocation) NonNullList(net.minecraft.util.NonNullList) Options(com.mcmoddev.lib.util.ConfigBase.Options) CraftingHelper(net.minecraftforge.common.crafting.CraftingHelper) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) JsonArray(com.google.gson.JsonArray) ShapedPrimer(net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer) JsonSyntaxException(com.google.gson.JsonSyntaxException) Ingredient(net.minecraft.item.crafting.Ingredient) ResourceLocation(net.minecraft.util.ResourceLocation) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ShapedPrimer

use of net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer in project SpringFestival by TeamCovertDragon.

the class ShapedFlexibleDurationRecipeFactory method parse.

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    ShapedOreRecipe recipe = ShapedOreRecipe.factory(context, json);
    ShapedPrimer primer = new ShapedPrimer();
    primer.width = recipe.getRecipeWidth();
    primer.height = recipe.getRecipeHeight();
    primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true);
    primer.input = recipe.getIngredients();
    int damage = JsonUtils.getInt(json, "damage", 0);
    return new ShapedFlexibleEnduranceShapedRecipe(new ResourceLocation(SpringFestivalConstants.MOD_ID, "shaped_flexible_duration"), recipe.getRecipeOutput(), primer, damage);
}
Also used : ShapedPrimer(net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 3 with ShapedPrimer

use of net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer in project RFTools by McJty.

the class ContainerAndItemRecipeFactory method parse.

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    ShapedOreRecipe recipe = ShapedOreRecipe.factory(context, json);
    ShapedPrimer primer = new ShapedPrimer();
    primer.width = recipe.getRecipeWidth();
    primer.height = recipe.getRecipeHeight();
    primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true);
    primer.input = recipe.getIngredients();
    return new ContainerAndItemRecipe(new ResourceLocation(RFTools.MODID, "container_and_item"), recipe.getRecipeOutput(), primer);
}
Also used : ShapedPrimer(net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 4 with ShapedPrimer

use of net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer in project RFTools by McJty.

the class ContainerToItemRecipeFactory method parse.

@Override
public IRecipe parse(JsonContext context, JsonObject json) {
    ShapedOreRecipe recipe = ShapedOreRecipe.factory(context, json);
    ShapedPrimer primer = new ShapedPrimer();
    primer.width = recipe.getRecipeWidth();
    primer.height = recipe.getRecipeHeight();
    primer.mirrored = JsonUtils.getBoolean(json, "mirrored", true);
    primer.input = recipe.getIngredients();
    return new ContainerToItemRecipe(new ResourceLocation(RFTools.MODID, "container_to_item"), recipe.getRecipeOutput(), primer);
}
Also used : ShapedPrimer(net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 5 with ShapedPrimer

use of net.minecraftforge.common.crafting.CraftingHelper.ShapedPrimer in project ImmersiveEngineering by BluSunrize.

the class RecipeFactoryShapedIngredient 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 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(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);
    ItemStack result = CraftingHelper.getItemStack(JsonUtils.getJsonObject(json, "result"), context);
    RecipeShapedIngredient recipe = constructRecipe(group.isEmpty() ? null : new ResourceLocation(group), result, primer);
    if (JsonUtils.getBoolean(json, "quarter_turn", false))
        recipe.allowQuarterTurn();
    if (JsonUtils.getBoolean(json, "eighth_turn", false))
        recipe.allowEighthTurn();
    if (JsonUtils.hasField(json, "copy_nbt_multiply_decimals"))
        recipe.setNBTCopyMultiplyDecimals(JsonUtils.getBoolean(json, "copy_nbt_multiply_decimals"));
    if (JsonUtils.hasField(json, "copy_nbt")) {
        if (JsonUtils.isJsonArray(json, "copy_nbt")) {
            JsonArray jArray = JsonUtils.getJsonArray(json, "copy_nbt");
            int[] array = new int[jArray.size()];
            for (int i = 0; i < array.length; i++) array[i] = jArray.get(i).getAsInt();
            recipe.setNBTCopyTargetRecipe(array);
        } else
            recipe.setNBTCopyTargetRecipe(JsonUtils.getInt(json, "copy_nbt"));
        if (JsonUtils.hasField(json, "copy_nbt_predicate"))
            recipe.setNBTCopyPredicate(JsonUtils.getString(json, "copy_nbt_predicate"));
    }
    return recipe;
}
Also used : 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)8 ResourceLocation (net.minecraft.util.ResourceLocation)7 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)5 JsonArray (com.google.gson.JsonArray)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)4 ItemStack (net.minecraft.item.ItemStack)4 Ingredient (net.minecraft.item.crafting.Ingredient)4 JsonElement (com.google.gson.JsonElement)3 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