From f1eebaadf3a3061b9abb0fad2c7e0fa8755390a2 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 19 Oct 2016 15:57:30 +0200 Subject: [PATCH] Added crusher output blacklist Closes #293 --- .../api/ActuallyAdditionsAPI.java | 13 +++++ .../api/recipe/CrusherRecipe.java | 5 ++ .../config/values/ConfigStringListValues.java | 1 + .../mod/recipe/CrusherRecipeRegistry.java | 50 +++++++++++++++++-- 4 files changed, 66 insertions(+), 3 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 5a217a8c8..5a0fcd137 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -148,6 +148,19 @@ public final class ActuallyAdditionsAPI{ } } + /** + * Adds a Recipe to the Crusher Recipe Registry + * The second output will be nothing + * + * @param input The input as an ItemStack + * @param outputOne The first output's OreDictionary name + */ + public static void addCrusherRecipe(String input, ItemStack outputOne){ + if(!OreDictionary.getOres(input, false).isEmpty()){ + CRUSHER_RECIPES.add(new CrusherRecipe(input, outputOne)); + } + } + /** * Adds a Recipe to the Oil generator * diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java index f5cedd3dd..9b73e52aa 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java @@ -24,6 +24,11 @@ public class CrusherRecipe{ public ItemStack outputOneStack; public ItemStack outputTwoStack; + public CrusherRecipe(String input, ItemStack outputOne){ + this.input = input; + this.outputOneStack = outputOne; + } + public CrusherRecipe(ItemStack input, String outputOne, int outputOneAmount){ this.inputStack = input; this.outputOne = outputOne; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java index 1f6296361..cf50644aa 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigStringListValues.java @@ -15,6 +15,7 @@ import de.ellpeck.actuallyadditions.mod.config.ConfigCategories; public enum ConfigStringListValues{ CRUSHER_RECIPE_EXCEPTIONS("Crusher Recipe Exceptions", ConfigCategories.OTHER, new String[]{"ingotBrick", "ingotBrickNether"}, "The Ingots, Dusts and Ores blacklisted from being auto-registered to be crushed by the Crusher. This list uses OreDictionary Names of the Inputs only."), + CRUSHER_OUTPUT_BLACKLIST("Crusher Output Blacklist", ConfigCategories.OTHER, new String[0], "The items that aren't allowed as outputs from automatically generated Crusher recipes. Use this in case a mod, for example, adds a dust variant that can't be smelted into an ingot. Use REGISTRY NAMES, and if metadata is needed, add it like so: somemod:some_item@3"), MASHED_FOOD_CRAFTING_EXCEPTIONS("Mashed Food Crafting Exceptions", ConfigCategories.ITEMS_CRAFTING, new String[]{"ActuallyAdditions:itemCoffee"}, "The ItemFood, IGrowable and IPlantable Items that can not be used to craft Mashed Food. These are the actual registered Item Names, the ones you use, for example, when using the /give Command."), PAXEL_EXTRA_MINING_WHITELIST("AIOT Extra Whitelist", ConfigCategories.TOOL_VALUES, new String[]{"TConstruct:GravelOre"}, "By default, the AIOT can mine certain blocks. If there is one that it can't mine, but should be able to, put its REGISTRY NAME here. These are the actual registered Item Names, the ones you use, for example, when using the /give Command."), DRILL_EXTRA_MINING_WHITELIST("Drill Extra Whitelist", ConfigCategories.TOOL_VALUES, new String[]{"TConstruct:GravelOre"}, "By default, the Drill can mine certain blocks. If there is one that it can't mine, but should be able to, put its REGISTRY NAME here. These are the actual registered Item Names, the ones you use, for example, when using the /give Command."), diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java index 3987e6543..d1460e297 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java @@ -16,6 +16,7 @@ import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.util.ItemUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.RecipeUtil; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; @@ -39,8 +40,18 @@ public final class CrusherRecipeRegistry{ String output = theCase.resultPreString+ore.substring(theCase.theCase.length()); if(!hasOreRecipe(ore)){ - if(!OreDictionary.getOres(output, false).isEmpty() && !OreDictionary.getOres(ore, false).isEmpty()){ - ActuallyAdditionsAPI.addCrusherRecipe(ore, output, theCase.resultAmount); + List outputs = OreDictionary.getOres(output, false); + if(!outputs.isEmpty() && !OreDictionary.getOres(ore, false).isEmpty()){ + for(ItemStack stack : outputs){ + if(!hasBlacklistedOutput(stack)){ + ItemStack copy = stack.copy(); + copy.stackSize = theCase.resultAmount; + ActuallyAdditionsAPI.addCrusherRecipe(ore, copy); + } + else if(!oresNoResult.contains(ore)){ + oresNoResult.add(ore); + } + } } else{ oresNoResult.add(ore); @@ -57,12 +68,45 @@ public final class CrusherRecipeRegistry{ ArrayList addedRecipes = new ArrayList(); for(int i = recipeStartedAt; i < ActuallyAdditionsAPI.CRUSHER_RECIPES.size(); i++){ CrusherRecipe recipe = ActuallyAdditionsAPI.CRUSHER_RECIPES.get(i); - addedRecipes.add(recipe.input+" -> "+recipe.outputOneAmount+"x "+recipe.outputOne); + addedRecipes.add(recipe.input+" -> "+recipe.outputOneStack); } ModUtil.LOGGER.info("Added "+addedRecipes.size()+" Crusher Recipes automatically: "+addedRecipes.toString()); ModUtil.LOGGER.warn("Couldn't add "+oresNoResult.size()+" Crusher Recipes automatically because the inputs were missing outputs: "+oresNoResult.toString()); } + private static boolean hasBlacklistedOutput(ItemStack output){ + if(output != null){ + Item item = output.getItem(); + if(item != null){ + String reg = item.getRegistryName().toString(); + + for(String conf : ConfigStringListValues.CRUSHER_OUTPUT_BLACKLIST.getValue()){ + String confReg = conf; + int meta = 0; + + if(conf.contains("@")){ + try{ + String[] split = conf.split("@"); + confReg = split[0]; + meta = Integer.parseInt(split[1]); + } + catch(Exception e){ + ModUtil.LOGGER.warn("A config option appears to be incorrect: The Crusher Output Blacklist entry "+conf+" can't be parsed!"); + } + } + + if(reg.equals(confReg) && output.getItemDamage() == meta){ + System.out.println("Blacklisting "+output); + return true; + } + } + + return false; + } + } + return true; + } + private static boolean hasException(String ore){ for(String conf : ConfigStringListValues.CRUSHER_RECIPE_EXCEPTIONS.getValue()){ if(conf.equals(ore)){