From 56bb502ab7ca1bf90b68f1b507155885f579b670 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Wed, 1 Jul 2015 16:06:40 +0200 Subject: [PATCH] -Changed Crusher Recipe Registering a bit --- .../actuallyadditions/ActuallyAdditions.java | 4 +- .../communication/InterModCommunications.java | 4 +- .../crafting/CrusherCrafting.java | 46 ++++++++++++ .../crafting/GrinderCrafting.java | 44 ----------- .../inventory/ContainerGrinder.java | 4 +- .../nei/CrusherRecipeHandler.java | 14 ++-- .../recipe/CrusherRecipeAutoRegistry.java | 47 ++++++++++++ ....java => CrusherRecipeManualRegistry.java} | 49 +++++++----- .../recipe/GrinderRecipeAutoRegistry.java | 75 ------------------- .../tile/TileEntityGrinder.java | 14 ++-- 10 files changed, 145 insertions(+), 156 deletions(-) create mode 100644 src/main/java/ellpeck/actuallyadditions/crafting/CrusherCrafting.java delete mode 100644 src/main/java/ellpeck/actuallyadditions/crafting/GrinderCrafting.java create mode 100644 src/main/java/ellpeck/actuallyadditions/recipe/CrusherRecipeAutoRegistry.java rename src/main/java/ellpeck/actuallyadditions/recipe/{GrinderRecipeManualRegistry.java => CrusherRecipeManualRegistry.java} (55%) delete mode 100644 src/main/java/ellpeck/actuallyadditions/recipe/GrinderRecipeAutoRegistry.java diff --git a/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java b/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java index ce04e4379..b4afdc733 100644 --- a/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java +++ b/src/main/java/ellpeck/actuallyadditions/ActuallyAdditions.java @@ -9,7 +9,7 @@ import ellpeck.actuallyadditions.achievement.InitAchievements; import ellpeck.actuallyadditions.blocks.InitBlocks; import ellpeck.actuallyadditions.communication.InterModCommunications; import ellpeck.actuallyadditions.config.ConfigurationHandler; -import ellpeck.actuallyadditions.crafting.GrinderCrafting; +import ellpeck.actuallyadditions.crafting.CrusherCrafting; import ellpeck.actuallyadditions.crafting.InitCrafting; import ellpeck.actuallyadditions.crafting.ItemCrafting; import ellpeck.actuallyadditions.event.InitEvents; @@ -76,7 +76,7 @@ public class ActuallyAdditions{ Util.logInfo("Starting PostInitialization Phase..."); ItemCoffee.initIngredients(); - GrinderCrafting.init(); + CrusherCrafting.init(); ItemCrafting.initMashedFoodRecipes(); HairyBallHandler.init(); proxy.postInit(); diff --git a/src/main/java/ellpeck/actuallyadditions/communication/InterModCommunications.java b/src/main/java/ellpeck/actuallyadditions/communication/InterModCommunications.java index 3fa551e59..d8fa8d0de 100644 --- a/src/main/java/ellpeck/actuallyadditions/communication/InterModCommunications.java +++ b/src/main/java/ellpeck/actuallyadditions/communication/InterModCommunications.java @@ -2,7 +2,7 @@ package ellpeck.actuallyadditions.communication; import cpw.mods.fml.common.event.FMLInterModComms; import ellpeck.actuallyadditions.items.ItemCoffee; -import ellpeck.actuallyadditions.recipe.GrinderRecipeManualRegistry; +import ellpeck.actuallyadditions.recipe.CrusherRecipeManualRegistry; import ellpeck.actuallyadditions.recipe.HairyBallHandler; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.Util; @@ -26,7 +26,7 @@ public class InterModCommunications{ int secondChance = compound.getInteger("secondChance"); if(input != null && outputOne != null){ - GrinderRecipeManualRegistry.registerRecipe(input, outputOne, outputTwo, secondChance); + CrusherRecipeManualRegistry.registerRecipe(input, outputOne, outputTwo, secondChance); Util.logInfo("Crusher Recipe that was sent from Mod " + message.getSender() + " has been registered successfully: " + input.toString() + " -> " + outputOne.toString() + (outputTwo != null ? " + " + outputTwo.toString() + ", Second Chance: " + secondChance : "")); } else ModUtil.LOGGER.log(Level.ERROR, "Crusher Recipe that was sent from Mod " + message.getSender() + " could not be registered: It's missing an Input or an Output!"); diff --git a/src/main/java/ellpeck/actuallyadditions/crafting/CrusherCrafting.java b/src/main/java/ellpeck/actuallyadditions/crafting/CrusherCrafting.java new file mode 100644 index 000000000..db0e4d820 --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/crafting/CrusherCrafting.java @@ -0,0 +1,46 @@ +package ellpeck.actuallyadditions.crafting; + +import ellpeck.actuallyadditions.items.InitItems; +import ellpeck.actuallyadditions.items.metalists.TheDusts; +import ellpeck.actuallyadditions.items.metalists.TheFoods; +import ellpeck.actuallyadditions.recipe.CrusherRecipeAutoRegistry; +import ellpeck.actuallyadditions.recipe.CrusherRecipeAutoRegistry.SearchCase; +import ellpeck.actuallyadditions.recipe.CrusherRecipeManualRegistry; +import ellpeck.actuallyadditions.util.Util; +import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; + +public class CrusherCrafting{ + + public static void init(){ + Util.logInfo("Initializing Crusher Recipes..."); + + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Items.bed), new ItemStack(Blocks.planks, 3), new ItemStack(Blocks.wool, 3), 100); + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.wool, 1, Util.WILDCARD), new ItemStack(Items.string, 4)); + + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.redstone_ore), new ItemStack(Items.redstone, 10)); + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.lapis_ore), new ItemStack(InitItems.itemDust, 12, TheDusts.LAPIS.ordinal())); + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Items.coal), new ItemStack(InitItems.itemDust, 1, TheDusts.COAL.ordinal())); + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.coal_block), new ItemStack(InitItems.itemDust, 9, TheDusts.COAL.ordinal())); + + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.cobblestone), new ItemStack(Blocks.sand)); + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.gravel), new ItemStack(Items.flint)); + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.stone), new ItemStack(Blocks.cobblestone)); + CrusherRecipeManualRegistry.registerRecipe(new ItemStack(InitItems.itemFoods, 1, TheFoods.RICE.ordinal()), new ItemStack(Items.sugar, 2)); + + CrusherRecipeManualRegistry.registerRecipe("oreNickel", "dustNickel", "dustPlatinum", 15, 2, 1); + CrusherRecipeManualRegistry.registerRecipe("oreIron", "dustIron", "dustGold", 20, 2, 1); + + CrusherRecipeAutoRegistry.searchCases.add(new SearchCase("oreNether", 6)); + CrusherRecipeAutoRegistry.searchCases.add(new SearchCase("denseore", 8)); + CrusherRecipeAutoRegistry.searchCases.add(new SearchCase("gem", 1)); + CrusherRecipeAutoRegistry.searchCases.add(new SearchCase("ingot", 1)); + CrusherRecipeAutoRegistry.searchCases.add(new SearchCase("ore", 2)); + + CrusherRecipeAutoRegistry.exceptions.add("ingotBrick"); + CrusherRecipeAutoRegistry.exceptions.add("ingotBrickNether"); + + CrusherRecipeAutoRegistry.registerFinally(); + } +} diff --git a/src/main/java/ellpeck/actuallyadditions/crafting/GrinderCrafting.java b/src/main/java/ellpeck/actuallyadditions/crafting/GrinderCrafting.java deleted file mode 100644 index ca6c1721d..000000000 --- a/src/main/java/ellpeck/actuallyadditions/crafting/GrinderCrafting.java +++ /dev/null @@ -1,44 +0,0 @@ -package ellpeck.actuallyadditions.crafting; - -import ellpeck.actuallyadditions.items.InitItems; -import ellpeck.actuallyadditions.items.metalists.TheDusts; -import ellpeck.actuallyadditions.items.metalists.TheFoods; -import ellpeck.actuallyadditions.recipe.GrinderRecipeAutoRegistry; -import ellpeck.actuallyadditions.recipe.GrinderRecipeAutoRegistry.SearchCase; -import ellpeck.actuallyadditions.recipe.GrinderRecipeManualRegistry; -import ellpeck.actuallyadditions.util.Util; -import net.minecraft.init.Blocks; -import net.minecraft.init.Items; -import net.minecraft.item.ItemStack; - -public class GrinderCrafting{ - - public static void init(){ - Util.logInfo("Initializing Crusher Recipes..."); - GrinderRecipeManualRegistry.clearRecipeList(); - - GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.redstone_ore), new ItemStack(Items.redstone, 10)); - GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.lapis_ore), new ItemStack(InitItems.itemDust, 12, TheDusts.LAPIS.ordinal())); - GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Items.coal), new ItemStack(InitItems.itemDust, 1, TheDusts.COAL.ordinal())); - GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.coal_block), new ItemStack(InitItems.itemDust, 9, TheDusts.COAL.ordinal())); - - GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.cobblestone), new ItemStack(Blocks.sand)); - GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.gravel), new ItemStack(Items.flint)); - GrinderRecipeManualRegistry.registerRecipe(new ItemStack(Blocks.stone), new ItemStack(Blocks.cobblestone)); - GrinderRecipeManualRegistry.registerRecipe(new ItemStack(InitItems.itemFoods, 1, TheFoods.RICE.ordinal()), new ItemStack(Items.sugar, 2)); - - GrinderRecipeManualRegistry.registerRecipe("oreNickel", "dustNickel", "dustPlatinum", 15, 2); - GrinderRecipeManualRegistry.registerRecipe("oreIron", "dustIron", "dustGold", 20, 2); - - GrinderRecipeAutoRegistry.searchCases.add(new SearchCase("oreNether", 6)); - GrinderRecipeAutoRegistry.searchCases.add(new SearchCase("denseore", 8)); - GrinderRecipeAutoRegistry.searchCases.add(new SearchCase("gem", 1)); - GrinderRecipeAutoRegistry.searchCases.add(new SearchCase("ingot", 1)); - GrinderRecipeAutoRegistry.searchCases.add(new SearchCase("ore", 2)); - - GrinderRecipeAutoRegistry.exceptions.add("ingotBrick"); - GrinderRecipeAutoRegistry.exceptions.add("ingotBrickNether"); - - GrinderRecipeAutoRegistry.registerFinally(); - } -} diff --git a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGrinder.java b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGrinder.java index 1eb7a3952..ce1892003 100644 --- a/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGrinder.java +++ b/src/main/java/ellpeck/actuallyadditions/inventory/ContainerGrinder.java @@ -3,7 +3,7 @@ package ellpeck.actuallyadditions.inventory; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ellpeck.actuallyadditions.inventory.slot.SlotOutput; -import ellpeck.actuallyadditions.recipe.GrinderRecipeManualRegistry; +import ellpeck.actuallyadditions.recipe.CrusherRecipeManualRegistry; import ellpeck.actuallyadditions.tile.TileEntityBase; import ellpeck.actuallyadditions.tile.TileEntityGrinder; import invtweaks.api.container.InventoryContainer; @@ -104,7 +104,7 @@ public class ContainerGrinder extends Container{ if(currentStack.getItem() != null){ if(slot <= hotbarEnd && slot >= inventoryStart){ - if(GrinderRecipeManualRegistry.getOutput(currentStack, false) != null){ + if(CrusherRecipeManualRegistry.getOutput(currentStack, false) != null){ this.mergeItemStack(newStack, TileEntityGrinder.SLOT_INPUT_1, TileEntityGrinder.SLOT_INPUT_1+1, false); if(this.isDouble) this.mergeItemStack(newStack, TileEntityGrinder.SLOT_INPUT_2, TileEntityGrinder.SLOT_INPUT_2+1, false); } diff --git a/src/main/java/ellpeck/actuallyadditions/nei/CrusherRecipeHandler.java b/src/main/java/ellpeck/actuallyadditions/nei/CrusherRecipeHandler.java index 1d3acfaf8..4ff756f4a 100644 --- a/src/main/java/ellpeck/actuallyadditions/nei/CrusherRecipeHandler.java +++ b/src/main/java/ellpeck/actuallyadditions/nei/CrusherRecipeHandler.java @@ -6,7 +6,7 @@ import codechicken.nei.PositionedStack; import codechicken.nei.recipe.RecipeInfo; import codechicken.nei.recipe.TemplateRecipeHandler; import ellpeck.actuallyadditions.inventory.gui.GuiGrinder; -import ellpeck.actuallyadditions.recipe.GrinderRecipeManualRegistry; +import ellpeck.actuallyadditions.recipe.CrusherRecipeManualRegistry; import ellpeck.actuallyadditions.util.ModUtil; import ellpeck.actuallyadditions.util.StringUtil; import net.minecraft.client.gui.inventory.GuiContainer; @@ -84,8 +84,8 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{ @Override public void loadCraftingRecipes(String outputId, Object... results){ if(outputId.equals(NAME) && getClass() == CrusherRecipeHandler.class){ - ArrayList recipes = GrinderRecipeManualRegistry.recipes; - for(GrinderRecipeManualRegistry.GrinderRecipe recipe : recipes){ + ArrayList recipes = CrusherRecipeManualRegistry.recipes; + for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){ arecipes.add(new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance)); } } @@ -94,16 +94,16 @@ public class CrusherRecipeHandler extends TemplateRecipeHandler{ @Override public void loadCraftingRecipes(ItemStack result){ - ArrayList recipes = GrinderRecipeManualRegistry.recipes; - for(GrinderRecipeManualRegistry.GrinderRecipe recipe : recipes){ + ArrayList recipes = CrusherRecipeManualRegistry.recipes; + for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){ if(NEIServerUtils.areStacksSameType(recipe.firstOutput, result) || NEIServerUtils.areStacksSameType(recipe.secondOutput, result)) arecipes.add(new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance)); } } @Override public void loadUsageRecipes(ItemStack ingredient){ - ArrayList recipes = GrinderRecipeManualRegistry.recipes; - for(GrinderRecipeManualRegistry.GrinderRecipe recipe : recipes){ + ArrayList recipes = CrusherRecipeManualRegistry.recipes; + for(CrusherRecipeManualRegistry.CrusherRecipe recipe : recipes){ if(NEIServerUtils.areStacksSameTypeCrafting(recipe.input, ingredient)){ CachedCrush theRecipe = new CachedCrush(recipe.input, recipe.firstOutput, recipe.secondOutput, recipe.secondChance); theRecipe.setIngredientPermutation(Collections.singletonList(theRecipe.ingredient), ingredient); diff --git a/src/main/java/ellpeck/actuallyadditions/recipe/CrusherRecipeAutoRegistry.java b/src/main/java/ellpeck/actuallyadditions/recipe/CrusherRecipeAutoRegistry.java new file mode 100644 index 000000000..26000865e --- /dev/null +++ b/src/main/java/ellpeck/actuallyadditions/recipe/CrusherRecipeAutoRegistry.java @@ -0,0 +1,47 @@ +package ellpeck.actuallyadditions.recipe; + +import net.minecraftforge.oredict.OreDictionary; + +import java.util.ArrayList; + +public class CrusherRecipeAutoRegistry{ + + public static ArrayList searchCases = new ArrayList(); + public static ArrayList exceptions = new ArrayList(); + + public static class SearchCase{ + + public final String name; + public final int resultAmount; + + public SearchCase(String name, int resultAmount){ + this.name = name; + this.resultAmount = resultAmount; + } + } + + public static void registerFinally(){ + String[] names = OreDictionary.getOreNames(); + for(String inputName : names){ + + if(!exceptions.contains(inputName)){ + int resultAmount = 1; + String inputNameWithoutPrefix = null; + + for(SearchCase searchCase : searchCases){ + String toSearch = searchCase.name; + if(inputName.length() > toSearch.length() && inputName.substring(0, toSearch.length()).equals(toSearch)){ + inputNameWithoutPrefix = inputName.substring(toSearch.length()); + resultAmount = searchCase.resultAmount; + break; + } + } + + if(inputNameWithoutPrefix != null){ + String inputWithDustPrefix = "dust" + inputNameWithoutPrefix; + CrusherRecipeManualRegistry.registerRecipe(inputName, inputWithDustPrefix, resultAmount); + } + } + } + } +} \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/recipe/GrinderRecipeManualRegistry.java b/src/main/java/ellpeck/actuallyadditions/recipe/CrusherRecipeManualRegistry.java similarity index 55% rename from src/main/java/ellpeck/actuallyadditions/recipe/GrinderRecipeManualRegistry.java rename to src/main/java/ellpeck/actuallyadditions/recipe/CrusherRecipeManualRegistry.java index 96077ecfa..a4c41d7eb 100644 --- a/src/main/java/ellpeck/actuallyadditions/recipe/GrinderRecipeManualRegistry.java +++ b/src/main/java/ellpeck/actuallyadditions/recipe/CrusherRecipeManualRegistry.java @@ -1,23 +1,29 @@ package ellpeck.actuallyadditions.recipe; +import ellpeck.actuallyadditions.config.values.ConfigBoolValues; +import ellpeck.actuallyadditions.util.ModUtil; +import ellpeck.actuallyadditions.util.Util; import net.minecraft.item.ItemStack; import net.minecraftforge.oredict.OreDictionary; +import org.apache.logging.log4j.Level; import java.util.ArrayList; -public class GrinderRecipeManualRegistry{ +public class CrusherRecipeManualRegistry{ - public static ArrayList recipes = new ArrayList(); - - public static void clearRecipeList(){ - recipes.clear(); - } + public static ArrayList recipes = new ArrayList(); public static void registerRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int secondChance){ - recipes.add(new GrinderRecipe(input, outputOne, outputTwo, secondChance)); + if(!hasRecipe(input, outputOne)){ + recipes.add(new CrusherRecipe(input, outputOne, outputTwo, secondChance)); + } } - public static void registerRecipe(String input, String outputOne, String outputTwo, int secondChance, int outputAmount){ + public static void registerRecipe(String input, String outputOne, int outputOneAmount){ + registerRecipe(input, outputOne, "", 0, outputOneAmount, 0); + } + + public static void registerRecipe(String input, String outputOne, String outputTwo, int secondChance, int outputOneAmount, int outputTwoAmount){ ArrayList inputStacks = (ArrayList)OreDictionary.getOres(input, false); ArrayList outputOneStacks = (ArrayList)OreDictionary.getOres(outputOne, false); ArrayList outputTwoStacks = (ArrayList)OreDictionary.getOres(outputTwo, false); @@ -28,18 +34,27 @@ public class GrinderRecipeManualRegistry{ if(outputOneStacks != null && !outputOneStacks.isEmpty()){ for(ItemStack anOutputOne : outputOneStacks){ ItemStack theOutputOne = anOutputOne.copy(); - theOutputOne.stackSize = outputAmount; + theOutputOne.stackSize = outputOneAmount; if(outputTwoStacks != null && !outputTwoStacks.isEmpty()){ for(ItemStack anOutputTwo : outputTwoStacks){ ItemStack theOutputTwo = anOutputTwo.copy(); + theOutputTwo.stackSize = outputTwoAmount; registerRecipe(theInput, theOutputOne, theOutputTwo, secondChance); } } else registerRecipe(theInput, theOutputOne, null, 0); } } + else{ + if(ConfigBoolValues.DO_CRUSHER_SPAM.isEnabled()) + ModUtil.LOGGER.log(Level.WARN, "Couldn't register Crusher Recipe! An Item with OreDictionary Registry '" + outputOne + "' doesn't exist! It should be the output of '" + input + "'!"); + } } } + else{ + if(ConfigBoolValues.DO_CRUSHER_SPAM.isEnabled()) + ModUtil.LOGGER.log(Level.WARN, "Couldn't register Crusher Recipe! Didn't find Items registered as '" + input + "'!"); + } } public static void registerRecipe(ItemStack input, ItemStack outputOne){ @@ -47,8 +62,8 @@ public class GrinderRecipeManualRegistry{ } public static ItemStack getOutput(ItemStack input, boolean wantSecond){ - for(GrinderRecipe recipe : recipes){ - if(recipe.input.isItemEqual(input)){ + for(CrusherRecipe recipe : recipes){ + if(recipe.input.isItemEqual(input) || (recipe.input.getItem() == input.getItem() && recipe.input.getItemDamage() == Util.WILDCARD)){ return wantSecond ? recipe.secondOutput : recipe.firstOutput; } } @@ -56,29 +71,29 @@ public class GrinderRecipeManualRegistry{ } public static boolean hasRecipe(ItemStack input, ItemStack outputOne){ - for(GrinderRecipe recipe : recipes){ - if(recipe.input.isItemEqual(input) && recipe.firstOutput.isItemEqual(outputOne)) return true; + for(CrusherRecipe recipe : recipes){ + if(recipe.input.isItemEqual(input) && recipe.firstOutput.isItemEqual(outputOne) || (recipe.input.getItem() == input.getItem() && recipe.firstOutput.getItem() == outputOne.getItem() && recipe.input.getItemDamage() == Util.WILDCARD)) return true; } return false; } public static int getSecondChance(ItemStack input){ - for(GrinderRecipe recipe : recipes){ - if(recipe.input.isItemEqual(input)){ + for(CrusherRecipe recipe : recipes){ + if(recipe.input.isItemEqual(input) || (recipe.input.getItem() == input.getItem() && recipe.input.getItemDamage() == Util.WILDCARD)){ return recipe.secondChance; } } return 0; } - public static class GrinderRecipe{ + public static class CrusherRecipe{ public final ItemStack input; public final ItemStack firstOutput; public final ItemStack secondOutput; public final int secondChance; - public GrinderRecipe(ItemStack input, ItemStack firstOutput, ItemStack secondOutput, int secondChance){ + public CrusherRecipe(ItemStack input, ItemStack firstOutput, ItemStack secondOutput, int secondChance){ this.input = input; this.firstOutput = firstOutput; this.secondOutput = secondOutput; diff --git a/src/main/java/ellpeck/actuallyadditions/recipe/GrinderRecipeAutoRegistry.java b/src/main/java/ellpeck/actuallyadditions/recipe/GrinderRecipeAutoRegistry.java deleted file mode 100644 index 0736f6a23..000000000 --- a/src/main/java/ellpeck/actuallyadditions/recipe/GrinderRecipeAutoRegistry.java +++ /dev/null @@ -1,75 +0,0 @@ -package ellpeck.actuallyadditions.recipe; - -import ellpeck.actuallyadditions.config.values.ConfigBoolValues; -import ellpeck.actuallyadditions.util.ModUtil; -import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; -import org.apache.logging.log4j.Level; - -import java.util.ArrayList; - -public class GrinderRecipeAutoRegistry{ - - public static ArrayList searchCases = new ArrayList(); - public static ArrayList exceptions = new ArrayList(); - - public static class SearchCase{ - - public final String name; - public final int resultAmount; - - public SearchCase(String name, int resultAmount){ - this.name = name; - this.resultAmount = resultAmount; - } - } - - public static void registerFinally(){ - String[] names = OreDictionary.getOreNames(); - for(String inputName : names){ - - if(!exceptions.contains(inputName)){ - int resultAmount = 1; - String inputNameWithoutPrefix = null; - - for(SearchCase searchCase : searchCases){ - String toSearch = searchCase.name; - if(inputName.length() > toSearch.length() && inputName.substring(0, toSearch.length()).equals(toSearch)){ - inputNameWithoutPrefix = inputName.substring(toSearch.length()); - resultAmount = searchCase.resultAmount; - break; - } - } - - if(inputNameWithoutPrefix != null){ - String inputWithDustPrefix = "dust" + inputNameWithoutPrefix; - ArrayList allOresOfInitialInputName = (ArrayList)OreDictionary.getOres(inputName, false); - ArrayList allOresWithDustPrefix = (ArrayList)OreDictionary.getOres(inputWithDustPrefix, false); - if(allOresOfInitialInputName != null && allOresOfInitialInputName.size() > 0){ - if(allOresWithDustPrefix != null && allOresWithDustPrefix.size() > 0){ - for(ItemStack theInput : allOresOfInitialInputName){ - for(ItemStack theDust : allOresWithDustPrefix){ - ItemStack input = theInput.copy(); - ItemStack output = theDust.copy(); - output.stackSize = resultAmount; - if(!GrinderRecipeManualRegistry.hasRecipe(input, output)){ - GrinderRecipeManualRegistry.registerRecipe(input, output, null, 0); - } - } - } - } - else{ - if(ConfigBoolValues.DO_CRUSHER_SPAM.isEnabled()) - ModUtil.LOGGER.log(Level.INFO, "Couldn't register Crusher Recipe! An Item with OreDictionary Registry '" + inputWithDustPrefix + "' doesn't exist! It should correspond to '" + inputName + "'! This is not an Error, just a bit sad :("); - } - - } - else{ - if(ConfigBoolValues.DO_CRUSHER_SPAM.isEnabled()) - ModUtil.LOGGER.log(Level.WARN, "Couldn't register Crusher Recipe! Didn't find Items registered as '" + inputName + "'! This shouldn't happen as there is something registered as '" + inputName + "' that doesn't exist!"); - } - } - } - } - } -} \ No newline at end of file diff --git a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityGrinder.java b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityGrinder.java index 21dbf34cf..ec0f96379 100644 --- a/src/main/java/ellpeck/actuallyadditions/tile/TileEntityGrinder.java +++ b/src/main/java/ellpeck/actuallyadditions/tile/TileEntityGrinder.java @@ -5,7 +5,7 @@ import cofh.api.energy.IEnergyReceiver; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import ellpeck.actuallyadditions.config.values.ConfigIntValues; -import ellpeck.actuallyadditions.recipe.GrinderRecipeManualRegistry; +import ellpeck.actuallyadditions.recipe.CrusherRecipeManualRegistry; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraftforge.common.util.ForgeDirection; @@ -122,8 +122,8 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IEnerg public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput){ if(this.slots[theInput] != null){ - ItemStack outputOne = GrinderRecipeManualRegistry.getOutput(this.slots[theInput], false); - ItemStack outputTwo = GrinderRecipeManualRegistry.getOutput(this.slots[theInput], true); + ItemStack outputOne = CrusherRecipeManualRegistry.getOutput(this.slots[theInput], false); + ItemStack outputTwo = CrusherRecipeManualRegistry.getOutput(this.slots[theInput], true); if(this.slots[theInput] != null){ if(outputOne != null){ if((this.slots[theFirstOutput] == null || (this.slots[theFirstOutput].isItemEqual(outputOne) && this.slots[theFirstOutput].stackSize <= this.slots[theFirstOutput].getMaxStackSize()-outputOne.stackSize)) && (outputTwo == null || (this.slots[theSecondOutput] == null || (this.slots[theSecondOutput].isItemEqual(outputTwo) && this.slots[theSecondOutput].stackSize <= this.slots[theSecondOutput].getMaxStackSize()-outputTwo.stackSize)))){ @@ -136,14 +136,14 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IEnerg } public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput){ - ItemStack outputOnFirst = GrinderRecipeManualRegistry.getOutput(this.slots[theInput], false); + ItemStack outputOnFirst = CrusherRecipeManualRegistry.getOutput(this.slots[theInput], false); if(outputOnFirst != null){ if(this.slots[theFirstOutput] == null) this.slots[theFirstOutput] = outputOnFirst.copy(); else if(this.slots[theFirstOutput].getItem() == outputOnFirst.getItem()) this.slots[theFirstOutput].stackSize += outputOnFirst.stackSize; } - int chance = GrinderRecipeManualRegistry.getSecondChance(this.slots[theInput]); - ItemStack outputOnSecond = GrinderRecipeManualRegistry.getOutput(this.slots[theInput], true); + int chance = CrusherRecipeManualRegistry.getSecondChance(this.slots[theInput]); + ItemStack outputOnSecond = CrusherRecipeManualRegistry.getOutput(this.slots[theInput], true); if(outputOnSecond != null){ int rand = new Random().nextInt(100) + 1; if(rand <= chance){ @@ -189,7 +189,7 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements IEnerg @Override public boolean isItemValidForSlot(int i, ItemStack stack){ - return (i == SLOT_INPUT_1 || i == SLOT_INPUT_2) && GrinderRecipeManualRegistry.getOutput(stack, false) != null; + return (i == SLOT_INPUT_1 || i == SLOT_INPUT_2) && CrusherRecipeManualRegistry.getOutput(stack, false) != null; } @Override