Added crusher output blacklist

Closes #293
This commit is contained in:
Ellpeck 2016-10-19 15:57:30 +02:00
parent 3a324ee09d
commit f1eebaadf3
4 changed files with 66 additions and 3 deletions

View file

@ -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
*

View file

@ -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;

View file

@ -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."),

View file

@ -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<ItemStack> 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<String> addedRecipes = new ArrayList<String>();
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)){