Search in sources :

Example 1 with ParseResult

use of com.codetaylor.mc.athenaeum.parser.recipe.item.ParseResult in project artisan-worktables by codetaylor.

the class CustomMaterialConverter method convert.

public CustomMaterial convert(DataCustomMaterial data) throws MalformedRecipeItemException {
    // Convert tool material
    Item.ToolMaterial toolMaterial = EnumHelper.addToolMaterial("artisanworktables:" + data.getName().toUpperCase(), data.getHarvestLevel(), data.getMaxUses(), data.getEfficiency(), data.getDamage(), data.getEnchantability());
    // Convert color
    Integer colorInt = Integer.decode("0x" + data.getColor());
    int color = new Color(colorInt).getRGB();
    // Convert ingredient
    ParseResult parseResult = this.recipeItemParser.parse(data.getIngredientString());
    if (parseResult == ParseResult.NULL) {
        throw new MalformedRecipeItemException("Unable to parse ingredient [" + data.getIngredientString() + "] for material [" + data.getName() + "]");
    }
    Object ingredient;
    if ("ore".equals(parseResult.getDomain())) {
        ingredient = parseResult.getPath();
    } else {
        Item item = ForgeRegistries.ITEMS.getValue(new ResourceLocation(parseResult.getDomain(), parseResult.getPath()));
        if (item == null) {
            throw new MalformedRecipeItemException("Unable to find registered item: " + parseResult.toString());
        }
        if (parseResult.getMeta() == OreDictionary.WILDCARD_VALUE) {
            throw new MalformedRecipeItemException("Wildcard value not accepted for tool material ingredients: " + parseResult.toString());
        }
        ingredient = new ItemStack(item, 1, parseResult.getMeta());
    }
    return new CustomMaterial(data, toolMaterial, color, ingredient);
}
Also used : Item(net.minecraft.item.Item) ParseResult(com.codetaylor.mc.athenaeum.parser.recipe.item.ParseResult) ResourceLocation(net.minecraft.util.ResourceLocation) MalformedRecipeItemException(com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ParseResult

use of com.codetaylor.mc.athenaeum.parser.recipe.item.ParseResult in project artisan-worktables by codetaylor.

the class ModuleToolsRecipes method register.

/**
 * Iterates through all given items in the tool list and registers a recipe for each.
 *
 * @param registry the recipe registry
 * @param modId    the mod id
 * @param toolList the tool list
 */
public static void register(IForgeRegistry<IRecipe> registry, String modId, List<ItemWorktableToolBase> toolList) {
    RecipeItemParser recipeItemParser = new RecipeItemParser();
    for (ItemWorktableToolBase item : toolList) {
        try {
            // Convert ingredient
            String ingredientString = item.getMaterial().getIngredientString();
            ParseResult parseResult = recipeItemParser.parse(ingredientString);
            if (parseResult == ParseResult.NULL) {
                throw new MalformedRecipeItemException("Unable to parse ingredient [" + item.getMaterial().getIngredientString() + "] for material [" + item.getMaterial() + "]");
            }
            Object ingredient;
            if ("ore".equals(parseResult.getDomain())) {
                ingredient = parseResult.getPath();
            } else {
                Item parsedItem = ForgeRegistries.ITEMS.getValue(new ResourceLocation(parseResult.getDomain(), parseResult.getPath()));
                if (parsedItem == null) {
                    throw new MalformedRecipeItemException("Unable to find registered item: " + parseResult.toString());
                }
                if (parseResult.getMeta() == OreDictionary.WILDCARD_VALUE) {
                    throw new MalformedRecipeItemException("Wildcard value not accepted for tool material ingredients: " + parseResult.toString());
                }
                ingredient = new ItemStack(parsedItem, 1, parseResult.getMeta());
            }
            Object[] recipeDefinition = ModuleToolsRecipes.getRecipeDefinition(item.getType(), ingredient);
            if (recipeDefinition == null) {
                throw new RuntimeException("Missing recipe definition for tool type: " + item.getType().getName());
            }
            ShapedOreRecipe recipe = new ShapedOreRecipe(null, item, recipeDefinition);
            recipe.setRegistryName(new ResourceLocation(modId, "recipe." + item.getName() + "." + item.getMaterial().getDataCustomMaterial().getName()));
            registry.register(recipe);
        } catch (Exception e) {
            throw new RuntimeException("Error registering recipe", e);
        }
    }
}
Also used : ItemWorktableToolBase(com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase) RecipeItemParser(com.codetaylor.mc.athenaeum.parser.recipe.item.RecipeItemParser) ParseResult(com.codetaylor.mc.athenaeum.parser.recipe.item.ParseResult) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) MalformedRecipeItemException(com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException) Item(net.minecraft.item.Item) ResourceLocation(net.minecraft.util.ResourceLocation) MalformedRecipeItemException(com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException) ItemStack(net.minecraft.item.ItemStack)

Aggregations

MalformedRecipeItemException (com.codetaylor.mc.athenaeum.parser.recipe.item.MalformedRecipeItemException)2 ParseResult (com.codetaylor.mc.athenaeum.parser.recipe.item.ParseResult)2 Item (net.minecraft.item.Item)2 ItemStack (net.minecraft.item.ItemStack)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ItemWorktableToolBase (com.codetaylor.mc.artisanworktables.api.tool.ItemWorktableToolBase)1 RecipeItemParser (com.codetaylor.mc.athenaeum.parser.recipe.item.RecipeItemParser)1 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)1