Search in sources :

Example 1 with TCharObjectMap

use of gnu.trove.map.TCharObjectMap in project Charset by CharsetMC.

the class RecipeReplacement method process.

public void process(Collection<IRecipe> registry) {
    for (IRecipe recipe : registry) {
        ResourceLocation recipeName = recipe.getRegistryName();
        boolean dirty = false;
        if (recipe instanceof ShapedRecipes || recipe instanceof ShapelessRecipes || recipe instanceof ShapedOreRecipe || recipe instanceof ShapelessOreRecipe) {
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 0; i < ingredients.size(); i++) {
                Ingredient ing = ingredients.get(i);
                Ingredient ingNew = replaceIngredient(ing);
                if (ingNew != null) {
                    ingredients.set(i, ingNew);
                    dirty = true;
                }
            }
        } else if (recipe instanceof RecipeCharset) {
            TCharObjectMap<Ingredient> charToIngredient = ((RecipeCharset) recipe).charToIngredient;
            NonNullList<Ingredient> ingredients = recipe.getIngredients();
            for (int i = 0; i < ingredients.size(); i++) {
                Ingredient ing = ingredients.get(i);
                Ingredient ingNew = replaceIngredient(ing);
                if (ingNew != null) {
                    ingredients.set(i, ingNew);
                    TCharIterator iterator = charToIngredient.keySet().iterator();
                    while (iterator.hasNext()) {
                        char c = iterator.next();
                        if (charToIngredient.get(c) == ing) {
                            charToIngredient.put(c, ing);
                        }
                    }
                    dirty = true;
                }
            }
        }
        if (dirty) {
            ModCharset.logger.info("Successfully edited " + recipeName + "!");
        }
    }
}
Also used : ShapedRecipes(net.minecraft.item.crafting.ShapedRecipes) IRecipe(net.minecraft.item.crafting.IRecipe) ShapedOreRecipe(net.minecraftforge.oredict.ShapedOreRecipe) TCharIterator(gnu.trove.iterator.TCharIterator) TCharObjectMap(gnu.trove.map.TCharObjectMap) Ingredient(net.minecraft.item.crafting.Ingredient) OreIngredient(net.minecraftforge.oredict.OreIngredient) NonNullList(net.minecraft.util.NonNullList) ResourceLocation(net.minecraft.util.ResourceLocation) ShapelessOreRecipe(net.minecraftforge.oredict.ShapelessOreRecipe) ShapelessRecipes(net.minecraft.item.crafting.ShapelessRecipes)

Aggregations

TCharIterator (gnu.trove.iterator.TCharIterator)1 TCharObjectMap (gnu.trove.map.TCharObjectMap)1 IRecipe (net.minecraft.item.crafting.IRecipe)1 Ingredient (net.minecraft.item.crafting.Ingredient)1 ShapedRecipes (net.minecraft.item.crafting.ShapedRecipes)1 ShapelessRecipes (net.minecraft.item.crafting.ShapelessRecipes)1 NonNullList (net.minecraft.util.NonNullList)1 ResourceLocation (net.minecraft.util.ResourceLocation)1 OreIngredient (net.minecraftforge.oredict.OreIngredient)1 ShapedOreRecipe (net.minecraftforge.oredict.ShapedOreRecipe)1 ShapelessOreRecipe (net.minecraftforge.oredict.ShapelessOreRecipe)1