From ef11f111ed54fac3804e56762d700d0dcb0dbc52 Mon Sep 17 00:00:00 2001 From: modmuss50 Date: Thu, 23 Jul 2015 16:57:06 +0100 Subject: [PATCH] Started work on a way to find duplicate items --- src/main/java/techreborn/Core.java | 8 +-- .../techreborn/api/recipe/RecipeHandler.java | 60 +++++++++++++++---- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/src/main/java/techreborn/Core.java b/src/main/java/techreborn/Core.java index 31e2ae6f5..b29ca2428 100644 --- a/src/main/java/techreborn/Core.java +++ b/src/main/java/techreborn/Core.java @@ -105,17 +105,15 @@ public class Core { } @Mod.EventHandler - public void postinit(FMLPostInitializationEvent event){ + public void postinit(FMLPostInitializationEvent event) throws Exception { // Has to be done here as Buildcraft registers there recipes late - StopWatch watch = new StopWatch(); - watch.start(); - LogHelper.all(watch + " : main recipes"); - watch.stop(); for(ICompatModule compatModule : CompatManager.INSTANCE.compatModules){ compatModule.postInit(event); } packetPipeline.postInitialise(); LogHelper.info(RecipeHandler.recipeList.size() + " recipes loaded"); + +// RecipeHandler.scanForDupeRecipes(); } @Mod.EventHandler diff --git a/src/main/java/techreborn/api/recipe/RecipeHandler.java b/src/main/java/techreborn/api/recipe/RecipeHandler.java index 54273867b..cb8471df4 100644 --- a/src/main/java/techreborn/api/recipe/RecipeHandler.java +++ b/src/main/java/techreborn/api/recipe/RecipeHandler.java @@ -1,6 +1,12 @@ package techreborn.api.recipe; +import net.minecraft.item.ItemStack; +import org.apache.commons.lang3.time.StopWatch; +import techreborn.util.ItemUtils; +import techreborn.util.LogHelper; + import java.util.ArrayList; +import java.util.HashMap; import java.util.List; @@ -11,10 +17,12 @@ public class RecipeHandler { */ public static final ArrayList recipeList = new ArrayList(); + + public static HashMap stackMap = new HashMap(); /** - * This is a backedup clone of the master recipeList + * This is a list of all the registered machine names. */ - public static ArrayList recipeListBackup = new ArrayList(); + public static ArrayList machineNames = new ArrayList(); /** * Use this to get all of the recipes form a recipe name @@ -32,14 +40,14 @@ public class RecipeHandler { return baseRecipeList; } - public static String getUserFreindlyName(String name) { - for (IBaseRecipeType baseRecipe : recipeList) { - if (baseRecipe.getRecipeName().equals(name)) { - return baseRecipe.getUserFreindlyName(); - } - } - return ""; - } + public static String getUserFreindlyName(String name) { + for (IBaseRecipeType baseRecipe : recipeList) { + if (baseRecipe.getRecipeName().equals(name)) { + return baseRecipe.getUserFreindlyName(); + } + } + return ""; + } /** * Add a recipe to the system @@ -53,8 +61,40 @@ public class RecipeHandler { if (recipeList.contains(recipe)) { return; } + if (!machineNames.contains(recipe.getRecipeName())) { + machineNames.add(recipe.getRecipeName()); + } recipeList.add(recipe); + StringBuffer buffer = new StringBuffer(); + for (StackTraceElement ste : Thread.currentThread().getStackTrace()) { + buffer.append(ste); + } + stackMap.put(recipe, buffer.toString()); } + public static void scanForDupeRecipes() throws Exception { + StopWatch watch = new StopWatch(); + watch.start(); + for (IBaseRecipeType baseRecipeType : recipeList) { + for (IBaseRecipeType recipe : recipeList) { + if (baseRecipeType != recipe && baseRecipeType.getRecipeName().equals(recipe.getRecipeName())) { + for (int i = 0; i < baseRecipeType.getInputs().size(); i++) { + if (ItemUtils.isItemEqual(baseRecipeType.getInputs().get(i), recipe.getInputs().get(i), true, false, false)) { + StringBuffer itemInfo = new StringBuffer(); + for(ItemStack inputs : baseRecipeType.getInputs()){ + itemInfo.append(":" + inputs.getItem().getUnlocalizedName() + "," + inputs.getDisplayName() + "," + inputs.stackSize); + } + LogHelper.all(stackMap.get(baseRecipeType)); + // throw new Exception("Found a duplicate recipe for " + baseRecipeType.getRecipeName() + " with inputs " + itemInfo.toString()); + } + } + } + } + } + LogHelper.all(watch + " : Scanning dupe recipes"); + watch.stop(); + + } + } \ No newline at end of file