ActuallyAdditions/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java

126 lines
4.7 KiB
Java
Raw Normal View History

2016-01-05 04:47:35 +01:00
/*
2016-05-16 22:52:27 +02:00
* This file ("CrusherRecipeRegistry.java") is part of the Actually Additions mod for Minecraft.
2016-01-05 04:47:35 +01:00
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
2016-05-16 22:52:27 +02:00
* http://ellpeck.de/actaddlicense
2016-01-05 04:47:35 +01:00
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
2016-05-16 22:54:42 +02:00
* © 2015-2016 Ellpeck
2016-01-05 04:47:35 +01:00
*/
package de.ellpeck.actuallyadditions.mod.recipe;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
2016-01-05 04:47:35 +01:00
import de.ellpeck.actuallyadditions.mod.util.ItemUtil;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
2016-08-03 01:09:11 +02:00
import de.ellpeck.actuallyadditions.mod.util.RecipeUtil;
2016-01-05 04:47:35 +01:00
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import java.util.ArrayList;
import java.util.List;
2016-06-17 23:50:38 +02:00
public final class CrusherRecipeRegistry{
2016-01-05 04:47:35 +01:00
public static final ArrayList<SearchCase> SEARCH_CASES = new ArrayList<SearchCase>();
2016-01-05 04:47:35 +01:00
public static void registerFinally(){
ArrayList<String> oresNoResult = new ArrayList<String>();
2016-05-19 20:05:12 +02:00
int recipeStartedAt = ActuallyAdditionsAPI.CRUSHER_RECIPES.size();
2016-01-05 04:47:35 +01:00
for(String ore : OreDictionary.getOreNames()){
if(!hasException(ore)){
for(SearchCase theCase : SEARCH_CASES){
2016-01-05 04:47:35 +01:00
if(ore.length() > theCase.theCase.length()){
if(ore.substring(0, theCase.theCase.length()).equals(theCase.theCase)){
String output = theCase.resultPreString+ore.substring(theCase.theCase.length());
if(!hasOreRecipe(ore)){
if(!OreDictionary.getOres(output, false).isEmpty() && !OreDictionary.getOres(ore, false).isEmpty()){
2016-01-05 04:47:35 +01:00
ActuallyAdditionsAPI.addCrusherRecipe(ore, output, theCase.resultAmount);
}
else{
oresNoResult.add(ore);
}
}
break;
}
}
}
}
}
ArrayList<String> addedRecipes = new ArrayList<String>();
2016-05-19 20:05:12 +02:00
for(int i = recipeStartedAt; i < ActuallyAdditionsAPI.CRUSHER_RECIPES.size(); i++){
CrusherRecipe recipe = ActuallyAdditionsAPI.CRUSHER_RECIPES.get(i);
2016-01-05 04:47:35 +01:00
addedRecipes.add(recipe.input+" -> "+recipe.outputOneAmount+"x "+recipe.outputOne);
}
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 hasException(String ore){
for(String conf : ConfigStringListValues.CRUSHER_RECIPE_EXCEPTIONS.getValue()){
2016-01-05 04:47:35 +01:00
if(conf.equals(ore)){
return true;
}
}
return false;
}
public static boolean hasOreRecipe(String input){
2016-05-19 20:05:12 +02:00
for(CrusherRecipe recipe : ActuallyAdditionsAPI.CRUSHER_RECIPES){
2016-01-05 04:47:35 +01:00
if(recipe.input != null && recipe.input.equals(input)){
return true;
}
}
return false;
}
public static List<ItemStack> getOutputOnes(ItemStack input){
CrusherRecipe recipe = getRecipeFromInput(input);
2016-08-03 01:09:11 +02:00
return recipe == null ? null : RecipeUtil.getCrusherRecipeOutputOnes(recipe);
2016-01-05 04:47:35 +01:00
}
public static CrusherRecipe getRecipeFromInput(ItemStack input){
2016-05-19 20:05:12 +02:00
for(CrusherRecipe recipe : ActuallyAdditionsAPI.CRUSHER_RECIPES){
2016-08-03 01:09:11 +02:00
if(ItemUtil.contains(RecipeUtil.getCrusherRecipeInputs(recipe), input, true)){
2016-01-05 04:47:35 +01:00
return recipe;
}
}
return null;
}
public static List<ItemStack> getOutputTwos(ItemStack input){
CrusherRecipe recipe = getRecipeFromInput(input);
2016-08-03 01:09:11 +02:00
return recipe == null ? null : RecipeUtil.getCrusherRecipeOutputTwos(recipe);
2016-01-05 04:47:35 +01:00
}
public static int getOutputTwoChance(ItemStack input){
CrusherRecipe recipe = getRecipeFromInput(input);
return recipe == null ? -1 : recipe.outputTwoChance;
}
public static class SearchCase{
2016-05-19 20:05:12 +02:00
final String theCase;
final int resultAmount;
final String resultPreString;
2016-01-05 04:47:35 +01:00
public SearchCase(String theCase, int resultAmount){
this(theCase, resultAmount, "dust");
}
public SearchCase(String theCase, int resultAmount, String resultPreString){
this.theCase = theCase;
this.resultAmount = resultAmount;
this.resultPreString = resultPreString;
}
}
}