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