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);
}
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);
}
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);
}
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);
}
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;
}
Aggregations