From acebcb2fbd880b4bd7b0b862b5559f0221d16112 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 30 Oct 2016 17:13:46 +0100 Subject: [PATCH] Changed the way crusher recipes are registered Closes #297 --- build.gradle | 2 +- .../api/ActuallyAdditionsAPI.java | 67 +++++++++------- .../api/internal/IMethodHandler.java | 4 + .../api/recipe/CrusherRecipe.java | 34 ++------ .../api/recipe/LensConversionRecipe.java | 10 --- .../mod/booklet/page/PageCrusherRecipe.java | 78 +++++++------------ .../mod/booklet/page/PageReconstructor.java | 32 ++++---- .../config/values/ConfigStringListValues.java | 2 +- .../mod/crafting/CrusherCrafting.java | 64 +++++++-------- .../actuallyadditions/mod/gen/OreGen.java | 22 ++---- .../mod/items/lens/LensRecipeHandler.java | 2 +- .../jei/crusher/CrusherRecipeCategory.java | 9 +-- .../mod/jei/crusher/CrusherRecipeWrapper.java | 15 ++-- .../ReconstructorRecipeCategory.java | 4 +- .../ReconstructorRecipeWrapper.java | 5 +- .../mod/misc/MethodHandler.java | 74 ++++++++++++------ .../mod/recipe/CrusherRecipeRegistry.java | 46 +++-------- .../mod/tile/TileEntityGrinder.java | 76 ++++++++---------- .../mod/util/RecipeUtil.java | 49 ------------ 19 files changed, 240 insertions(+), 355 deletions(-) diff --git a/build.gradle b/build.gradle index c16898ffe..f4ab3fbe1 100644 --- a/build.gradle +++ b/build.gradle @@ -44,7 +44,7 @@ repositories { } dependencies { - compile "net.darkhax.tesla:Tesla:1.10.2-1.2.1.42" + compile "net.darkhax.tesla:Tesla:1.10.2-1.2.1.49" deobfCompile "mezz.jei:jei_1.10.2:3.13.0.335" } diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java index 5a0fcd137..02472d697 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/ActuallyAdditionsAPI.java @@ -20,7 +20,6 @@ import de.ellpeck.actuallyadditions.api.recipe.*; import net.minecraft.block.Block; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; import java.util.HashMap; @@ -31,7 +30,7 @@ public final class ActuallyAdditionsAPI{ public static final String MOD_ID = "actuallyadditions"; public static final String API_ID = MOD_ID+"api"; - public static final String API_VERSION = "23"; + public static final String API_VERSION = "24"; public static final List CRUSHER_RECIPES = new ArrayList(); public static final List BALL_OF_FUR_RETURN_ITEMS = new ArrayList(); @@ -90,8 +89,8 @@ public final class ActuallyAdditionsAPI{ * @param outputOne The first output's OreDictionary name * @param outputOneAmount The amount of the first output */ + @Deprecated //Use new version below public static void addCrusherRecipe(String input, String outputOne, int outputOneAmount){ - addCrusherRecipe(input, outputOne, outputOneAmount, "", 0, 0); } /** @@ -104,10 +103,8 @@ public final class ActuallyAdditionsAPI{ * @param outputTwoAmount The amount of the second output * @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time) */ + @Deprecated //Use new version below public static void addCrusherRecipe(String input, String outputOne, int outputOneAmount, String outputTwo, int outputTwoAmount, int outputTwoChance){ - if(!OreDictionary.getOres(input, false).isEmpty() && !OreDictionary.getOres(outputOne, false).isEmpty() && (outputTwo == null || outputTwo.isEmpty() || !OreDictionary.getOres(outputTwo, false).isEmpty())){ - CRUSHER_RECIPES.add(new CrusherRecipe(input, outputOne, outputOneAmount, outputTwo, outputTwoAmount, outputTwoChance)); - } } /** @@ -117,21 +114,8 @@ public final class ActuallyAdditionsAPI{ * @param input The input as an ItemStack * @param outputOne The first output as an ItemStack */ + @Deprecated //Use new version below public static void addCrusherRecipe(ItemStack input, ItemStack outputOne){ - addCrusherRecipe(input, outputOne, null, 0); - } - - /** - * 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 as an ItemStack - * @param outputTwo The second output as an ItemStack - * @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time) - */ - public static void addCrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance){ - CRUSHER_RECIPES.add(new CrusherRecipe(input, outputOne, outputTwo, outputTwoChance)); } /** @@ -142,23 +126,46 @@ public final class ActuallyAdditionsAPI{ * @param outputOne The first output's OreDictionary name * @param outputOneAmount The amount of the first output */ + @Deprecated //Use new version below public static void addCrusherRecipe(ItemStack input, String outputOne, int outputOneAmount){ - if(!OreDictionary.getOres(outputOne, false).isEmpty()){ - CRUSHER_RECIPES.add(new CrusherRecipe(input, outputOne, outputOneAmount)); - } } /** * 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 + * @param input The input as an ItemStack + * @param outputOne The first output's OreDictionary name */ + @Deprecated //Use new version below 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 Crusher Recipe Registry + * + * @param input The input as an ItemStack + * @param outputOne The first output as an ItemStack + * @param outputTwo The second output as an ItemStack (can be null if there should be none) + * @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time) + */ + public static void addCrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance){ + CRUSHER_RECIPES.add(new CrusherRecipe(input, outputOne, outputTwo, outputTwoChance)); + } + + /** + * Adds multiple Recipes to the Crusher Recipe Registry + * Use this if you want to add OreDictionary recipes easier + * + * @param inputs The inputs as an ItemStack List, stacksizes are ignored + * @param outputOnes The first outputs as an ItemStack List, stacksizes are ignored + * @param outputOneAmounts The amount of the first output, will be equal for all entries in the list + * @param outputTwos The second outputs as an ItemStack List (can be null or empty if there should be none) + * @param outputTwoAmounts The amount of the second output, will be equal for all entries in the list + * @param outputTwoChance The chance of the second output (0 won't occur at all, 100 will all the time) + */ + public static boolean addCrusherRecipes(List inputs, List outputOnes, int outputOneAmounts, List outputTwos, int outputTwoAmounts, int outputTwoChance){ + return methodHandler.addCrusherRecipes(inputs, outputOnes, outputOneAmounts, outputTwos, outputTwoAmounts, outputTwoChance); } /** @@ -237,12 +244,12 @@ public final class ActuallyAdditionsAPI{ * @param type The type of lens used for the conversion. To use the default type, use method below * Note how this always has to be the same instance of the lens type that the item also has for it to work! */ + @Deprecated //Use ItemStack recipes public static void addReconstructorLensConversionRecipe(String input, String output, int energyUse, LensConversion type){ - RECONSTRUCTOR_LENS_CONVERSION_RECIPES.add(new LensConversionRecipe(input, output, energyUse, type)); } + @Deprecated //Use ItemStack recipes public static void addReconstructorLensConversionRecipe(String input, String output, int energyUse){ - addReconstructorLensConversionRecipe(input, output, energyUse, lensDefaultConversion); } /** diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java index ab9133984..ac3640131 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IMethodHandler.java @@ -21,6 +21,8 @@ import net.minecraft.potion.PotionEffect; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.BlockPos; +import java.util.List; + /** * This is the internal method handler. * Use ActuallyAdditionsAPI.methodHandler for calling @@ -49,4 +51,6 @@ public interface IMethodHandler{ BookletPage generateFurnacePage(int id, ItemStack input, ItemStack result); IBookletChapter generateBookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, BookletPage... pages); + + boolean addCrusherRecipes(List inputs, List outputOnes, int outputOneAmounts, List outputTwos, int outputTwoAmounts, int outputTwoChance); } 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 9b73e52aa..38e621868 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/CrusherRecipe.java @@ -14,41 +14,17 @@ import net.minecraft.item.ItemStack; public class CrusherRecipe{ - public int outputTwoChance; - public String input; - public String outputOne; - public int outputOneAmount; - public String outputTwo; - public int outputTwoAmount; public ItemStack inputStack; public ItemStack outputOneStack; public ItemStack outputTwoStack; + public int outputTwoChance; - 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; - this.outputOneAmount = outputOneAmount; - } - - public CrusherRecipe(ItemStack input, ItemStack outputOne, ItemStack outputTwo, int outputTwoChance){ - this.inputStack = input; - this.outputOneStack = outputOne; - this.outputTwoStack = outputTwo; + public CrusherRecipe(ItemStack inputStack, ItemStack outputOneStack, ItemStack outputTwoStack, int outputTwoChance){ + this.inputStack = inputStack; + this.outputOneStack = outputOneStack; + this.outputTwoStack = outputTwoStack; this.outputTwoChance = outputTwoChance; } - public CrusherRecipe(String input, String outputOne, int outputOneAmount, String outputTwo, int outputTwoAmount, int outputTwoChance){ - this.input = input; - this.outputOne = outputOne; - this.outputOneAmount = outputOneAmount; - this.outputTwo = outputTwo; - this.outputTwoAmount = outputTwoAmount; - this.outputTwoChance = outputTwoChance; - } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/LensConversionRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/LensConversionRecipe.java index fbcdbab74..b3bb02e11 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/recipe/LensConversionRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/recipe/LensConversionRecipe.java @@ -17,8 +17,6 @@ public class LensConversionRecipe{ public final int energyUse; public final LensConversion type; - public String input; - public String output; public ItemStack inputStack; public ItemStack outputStack; @@ -28,12 +26,4 @@ public class LensConversionRecipe{ this.energyUse = energyUse; this.type = type; } - - public LensConversionRecipe(String input, String output, int energyUse, LensConversion type){ - this.input = input; - this.output = output; - this.energyUse = energyUse; - this.type = type; - } - } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrusherRecipe.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrusherRecipe.java index 5c85e7ae8..0e153f6ba 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrusherRecipe.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageCrusherRecipe.java @@ -27,8 +27,6 @@ public class PageCrusherRecipe extends BookletPageAA{ public final CrusherRecipe recipe; - private int recipePos; - public PageCrusherRecipe(int id, CrusherRecipe recipe){ super(id); this.recipe = recipe; @@ -65,41 +63,36 @@ public class PageCrusherRecipe extends BookletPageAA{ Minecraft.getMinecraft().fontRendererObj.drawString(this.recipe.outputTwoChance+"%", gui.getGuiLeft()+37+62, gui.getGuiTop()+20+33, 0); } - List outputOnes = RecipeUtil.getCrusherRecipeOutputOnes(this.recipe); - if(outputOnes != null){ - for(int i = 0; i < 2; i++){ - for(int j = 0; j < 3; j++){ - ItemStack stack; - switch(j){ - case 0: - List inputs = RecipeUtil.getCrusherRecipeInputs(this.recipe); - stack = inputs.get(Math.min(inputs.size()-1, this.recipePos)); - break; - case 1: - stack = outputOnes.get(Math.min(outputOnes.size()-1, this.recipePos)); - break; - default: - List outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(this.recipe); - stack = outputTwos == null ? null : outputTwos.get(Math.min(outputTwos.size()-1, this.recipePos)); - break; + for(int i = 0; i < 2; i++){ + for(int j = 0; j < 3; j++){ + ItemStack stack; + switch(j){ + case 0: + stack = this.recipe.inputStack; + break; + case 1: + stack = this.recipe.outputOneStack; + break; + default: + stack = this.recipe.outputTwoStack; + break; + } + + if(stack != null){ + if(stack.getItemDamage() == Util.WILDCARD){ + stack.setItemDamage(0); } - if(stack != null){ - if(stack.getItemDamage() == Util.WILDCARD){ - stack.setItemDamage(0); - } + boolean tooltip = i == 1; - boolean tooltip = i == 1; - - int xShow = gui.getGuiLeft()+37+(j == 0 ? 1 : (j == 1 ? 43 : (j == 2 ? 43 : 0))); - int yShow = gui.getGuiTop()+20+(j == 0 ? 21 : (j == 1 ? 11 : (j == 2 ? 29 : 0))); - if(!tooltip){ - AssetUtil.renderStackToGui(stack, xShow, yShow, 1.0F); - } - else{ - if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ - gui.renderTooltipAndTransferButton(this, stack, mouseX, mouseY, j == 0, mousePressed); - } + int xShow = gui.getGuiLeft()+37+(j == 0 ? 1 : (j == 1 ? 43 : (j == 2 ? 43 : 0))); + int yShow = gui.getGuiTop()+20+(j == 0 ? 21 : (j == 1 ? 11 : (j == 2 ? 29 : 0))); + if(!tooltip){ + AssetUtil.renderStackToGui(stack, xShow, yShow, 1.0F); + } + else{ + if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ + gui.renderTooltipAndTransferButton(this, stack, mouseX, mouseY, j == 0, mousePressed); } } } @@ -108,23 +101,8 @@ public class PageCrusherRecipe extends BookletPageAA{ } } - @Override - @SideOnly(Side.CLIENT) - public void updateScreen(int ticksElapsed){ - if(ticksElapsed%10 == 0){ - List outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(this.recipe); - if(this.recipePos+1 >= Math.max(RecipeUtil.getCrusherRecipeInputs(this.recipe).size(), Math.max(RecipeUtil.getCrusherRecipeOutputOnes(this.recipe).size(), outputTwos == null ? 0 : outputTwos.size()))){ - this.recipePos = 0; - } - else{ - this.recipePos++; - } - } - } - @Override public ItemStack[] getItemStacksForPage(){ - List outputOnes = RecipeUtil.getCrusherRecipeOutputOnes(this.recipe); - return this.recipe == null ? new ItemStack[0] : outputOnes.toArray(new ItemStack[outputOnes.size()]); + return this.recipe == null ? new ItemStack[0] : new ItemStack[]{this.recipe.outputOneStack, this.recipe.outputTwoStack}; } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageReconstructor.java index 85b3f437c..790cb8d99 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/page/PageReconstructor.java @@ -22,7 +22,6 @@ import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; import java.util.ArrayList; -import java.util.List; public class PageReconstructor extends BookletPageAA{ @@ -69,24 +68,21 @@ public class PageReconstructor extends BookletPageAA{ AssetUtil.renderStackToGui(new ItemStack(InitBlocks.blockAtomicReconstructor), gui.getGuiLeft()+37+22, gui.getGuiTop()+20+21, 1.0F); for(int i = 0; i < 2; i++){ for(int x = 0; x < 2; x++){ - List stacks = x == 0 ? RecipeUtil.getConversionLensInputs(recipe) : RecipeUtil.getConversionLensOutputs(recipe); - if(stacks != null && !stacks.isEmpty()){ - ItemStack stack = stacks.get(0); + ItemStack stack = x == 0 ? recipe.inputStack : recipe.outputStack; - if(stack.getItemDamage() == Util.WILDCARD){ - stack.setItemDamage(0); - } - boolean tooltip = i == 1; + if(stack.getItemDamage() == Util.WILDCARD){ + stack.setItemDamage(0); + } + boolean tooltip = i == 1; - int xShow = gui.getGuiLeft()+37+1+x*42; - int yShow = gui.getGuiTop()+20+21; - if(!tooltip){ - AssetUtil.renderStackToGui(stack, xShow, yShow, 1.0F); - } - else{ - if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ - gui.renderTooltipAndTransferButton(this, stack, mouseX, mouseY, x == 0, mousePressed); - } + int xShow = gui.getGuiLeft()+37+1+x*42; + int yShow = gui.getGuiTop()+20+21; + if(!tooltip){ + AssetUtil.renderStackToGui(stack, xShow, yShow, 1.0F); + } + else{ + if(mouseX >= xShow && mouseX <= xShow+16 && mouseY >= yShow && mouseY <= yShow+16){ + gui.renderTooltipAndTransferButton(this, stack, mouseX, mouseY, x == 0, mousePressed); } } } @@ -113,7 +109,7 @@ public class PageReconstructor extends BookletPageAA{ ArrayList stacks = new ArrayList(); for(LensConversionRecipe recipe : this.recipes){ if(recipe != null){ - stacks.addAll(RecipeUtil.getConversionLensOutputs(recipe)); + stacks.add(recipe.outputStack); } } return stacks.toArray(new ItemStack[stacks.size()]); 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 cf50644aa..1c323e88b 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,7 +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"), + CRUSHER_OUTPUT_BLACKLIST("Crusher Output Blacklist", ConfigCategories.OTHER, new String[0], "The items that aren't allowed as outputs from OreDict 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/crafting/CrusherCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrusherCrafting.java index 2ed31929c..0d67e0b03 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrusherCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/CrusherCrafting.java @@ -21,8 +21,10 @@ import de.ellpeck.actuallyadditions.mod.util.RecipeUtil; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.ItemStack; +import net.minecraftforge.oredict.OreDictionary; import java.util.ArrayList; +import java.util.Collections; public final class CrusherCrafting{ @@ -34,67 +36,67 @@ public final class CrusherCrafting{ public static void init(){ ModUtil.LOGGER.info("Initializing Crusher Recipes..."); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.BONE), new ItemStack(Items.DYE, 6, 15)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.BONE), new ItemStack(Items.DYE, 6, 15), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.REEDS), new ItemStack(Items.SUGAR, 3)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.REEDS), new ItemStack(Items.SUGAR, 3), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.YELLOW_FLOWER), new ItemStack(Items.DYE, 3, 11)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.YELLOW_FLOWER), new ItemStack(Items.DYE, 3, 11), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 0), new ItemStack(Items.DYE, 3, 1)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 0), new ItemStack(Items.DYE, 3, 1), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 1), new ItemStack(Items.DYE, 3, 12)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 1), new ItemStack(Items.DYE, 3, 12), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 2), new ItemStack(Items.DYE, 3, 13)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 2), new ItemStack(Items.DYE, 3, 13), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 3), new ItemStack(Items.DYE, 3, 7)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 3), new ItemStack(Items.DYE, 3, 7), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 4), new ItemStack(Items.DYE, 3, 1)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 4), new ItemStack(Items.DYE, 3, 1), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 5), new ItemStack(Items.DYE, 3, 14)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 5), new ItemStack(Items.DYE, 3, 14), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 6), new ItemStack(Items.DYE, 3, 7)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 6), new ItemStack(Items.DYE, 3, 7), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 7), new ItemStack(Items.DYE, 3, 9)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 7), new ItemStack(Items.DYE, 3, 9), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 8), new ItemStack(Items.DYE, 3, 7)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.RED_FLOWER, 1, 8), new ItemStack(Items.DYE, 3, 7), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.DOUBLE_PLANT, 1, 0), new ItemStack(Items.DYE, 4, 11)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.DOUBLE_PLANT, 1, 0), new ItemStack(Items.DYE, 4, 11), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.DOUBLE_PLANT, 1, 1), new ItemStack(Items.DYE, 4, 13)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.DOUBLE_PLANT, 1, 1), new ItemStack(Items.DYE, 4, 13), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.DOUBLE_PLANT, 1, 4), new ItemStack(Items.DYE, 4, 1)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.DOUBLE_PLANT, 1, 4), new ItemStack(Items.DYE, 4, 1), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.DOUBLE_PLANT, 1, 5), new ItemStack(Items.DYE, 4, 9)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.DOUBLE_PLANT, 1, 5), new ItemStack(Items.DYE, 4, 9), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe("oreRedstone", "dustRedstone", 10); - ActuallyAdditionsAPI.addCrusherRecipe("oreLapis", "gemLapis", 12); - ActuallyAdditionsAPI.addCrusherRecipe("coal", "dustCoal", 1); - ActuallyAdditionsAPI.addCrusherRecipe("oreCoal", "coal", 3); - ActuallyAdditionsAPI.addCrusherRecipe("blockCoal", "coal", 9); - ActuallyAdditionsAPI.addCrusherRecipe("oreQuartz", "gemQuartz", 3); - ActuallyAdditionsAPI.addCrusherRecipe("cobblestone", "sand", 1); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("oreRedstone", false), OreDictionary.getOres("dustRedstone", false), 10, null, 0, 0); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("oreLapis", false), OreDictionary.getOres("gemLapis", false), 12, null, 0, 0); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("coal", false), OreDictionary.getOres("dustCoal", false), 1, null, 0, 0); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("oreCoal", false), OreDictionary.getOres("coal", false), 3, null, 0, 0); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("blockCoal", false), OreDictionary.getOres("coal", false), 9, null, 0, 0); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("oreQuartz", false), OreDictionary.getOres("gemQuartz", false), 3, null, 0, 0); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("cobblestone", false), OreDictionary.getOres("sand", false), 1, null, 0, 0); ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.GRAVEL), new ItemStack(Items.FLINT), new ItemStack(Items.FLINT), 50); - ActuallyAdditionsAPI.addCrusherRecipe("stone", "cobblestone", 1); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("stone", false), OreDictionary.getOres("cobblestone", false), 1, null, 0, 0); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(InitItems.itemFoods, 1, TheFoods.RICE.ordinal()), new ItemStack(Items.SUGAR, 2)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(InitItems.itemFoods, 1, TheFoods.RICE.ordinal()), new ItemStack(Items.SUGAR, 2), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.GLOWSTONE), new ItemStack(Items.GLOWSTONE_DUST, 4)); + ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Blocks.GLOWSTONE), new ItemStack(Items.GLOWSTONE_DUST, 4), null, 0); MISC_RECIPES.add(RecipeUtil.lastCrusherRecipe()); - ActuallyAdditionsAPI.addCrusherRecipe("oreNickel", "dustNickel", 2, "dustPlatinum", 1, 15); - ActuallyAdditionsAPI.addCrusherRecipe("oreIron", "dustIron", 2, "dustGold", 1, 20); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("oreNickel", false), OreDictionary.getOres("dustNickel", false), 2, OreDictionary.getOres("dustPlatinum", false), 1, 15); + ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres("oreIron", false), OreDictionary.getOres("dustIron", false), 2, OreDictionary.getOres("dustGold", false), 1, 20); if(ConfigCrafting.HORSE_ARMORS.isEnabled()){ - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.IRON_HORSE_ARMOR), "dustIron", 8); + ActuallyAdditionsAPI.addCrusherRecipes(Collections.singletonList(new ItemStack(Items.IRON_HORSE_ARMOR)), OreDictionary.getOres("dustIron", false), 8, null, 0, 0); recipeIronHorseArmor = RecipeUtil.lastCrusherRecipe(); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.GOLDEN_HORSE_ARMOR), "dustGold", 8); + ActuallyAdditionsAPI.addCrusherRecipes(Collections.singletonList(new ItemStack(Items.GOLDEN_HORSE_ARMOR)), OreDictionary.getOres("dustGold"), 8, null, 0, 0); recipeGoldHorseArmor = RecipeUtil.lastCrusherRecipe(); - ActuallyAdditionsAPI.addCrusherRecipe(new ItemStack(Items.DIAMOND_HORSE_ARMOR), "dustDiamond", 8); + ActuallyAdditionsAPI.addCrusherRecipes(Collections.singletonList(new ItemStack(Items.DIAMOND_HORSE_ARMOR)), OreDictionary.getOres("dustDiamond"), 8, null, 0, 0); recipeDiamondHorseArmor = RecipeUtil.lastCrusherRecipe(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/OreGen.java b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/OreGen.java index ac29f1440..c0dc980b6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/gen/OreGen.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/gen/OreGen.java @@ -73,13 +73,13 @@ public class OreGen implements IWorldGenerator{ if(ConfigBoolValues.GEN_LUSH_CAVES.isEnabled()){ StructureBoundingBox box = new StructureBoundingBox(x*16+8, 0, z*16+8, x*16+8+15, 255, z*16+8+15); int chunkRadius = 1; - for(int dx = -chunkRadius; dx <= chunkRadius; dx++) { - for(int dz = -chunkRadius; dz <= chunkRadius; dz++) { + for(int dx = -chunkRadius; dx <= chunkRadius; dx++){ + for(int dz = -chunkRadius; dz <= chunkRadius; dz++){ int chunkX = x+dx; int chunkZ = z+dz; int randConst = 0x969ce69d;//so that it won't generate the same numbers as other mod that does the same thing Random chunkRand = new Random(randConst ^ world.getSeed() ^ (chunkX*29+chunkZ*31)); - if(chunkRand.nextInt(ConfigIntValues.LUSH_CAVE_CHANCE.getValue()) <= 0) { + if(chunkRand.nextInt(ConfigIntValues.LUSH_CAVE_CHANCE.getValue()) <= 0){ BlockPos randPos = new BlockPos(chunkX*16+chunkRand.nextInt(16)+8, 64, chunkZ*16+chunkRand.nextInt(16)+8); BlockPos pos = randPos.down(MathHelper.getRandomIntegerInRange(chunkRand, 15, randPos.getY()-15)); this.caveGen.generate(world, chunkRand, pos, box); @@ -90,17 +90,11 @@ public class OreGen implements IWorldGenerator{ } public void addOreSpawn(Block block, int meta, Block blockIn, World world, Random random, int blockXPos, int blockZPos, int maxVeinSize, int chancesToSpawn, int minY, int maxY){ - if(maxY > minY){ - int yDiff = maxY-minY; - for(int i = 0; i < chancesToSpawn; i++){ - int posX = blockXPos+random.nextInt(16); - int posY = minY+random.nextInt(yDiff); - int posZ = blockZPos+random.nextInt(16); - new WorldGenMinable(block.getStateFromMeta(meta), maxVeinSize, BlockMatcher.forBlock(blockIn)).generate(world, random, new BlockPos(posX, posY, posZ)); - } - } - else{ - ModUtil.LOGGER.fatal("Couldn't generate '"+block.getUnlocalizedName()+"' into the world because the Min Y coordinate is bigger than the Max! This is definitely a Config Error! Check the Files!"); + for(int i = 0; i < chancesToSpawn; i++){ + int posX = blockXPos+random.nextInt(16); + int posY = minY+random.nextInt(maxY-minY); + int posZ = blockZPos+random.nextInt(16); + new WorldGenMinable(block.getStateFromMeta(meta), maxVeinSize, BlockMatcher.forBlock(blockIn)).generate(world, random, new BlockPos(posX, posY, posZ)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java index fe734af9b..75b4406a5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensRecipeHandler.java @@ -122,7 +122,7 @@ public final class LensRecipeHandler{ public static ArrayList getRecipesFor(ItemStack input){ ArrayList possibleRecipes = new ArrayList(); for(LensConversionRecipe recipe : ActuallyAdditionsAPI.RECONSTRUCTOR_LENS_CONVERSION_RECIPES){ - if(ItemUtil.contains(RecipeUtil.getConversionLensInputs(recipe), input, true)){ + if(ItemUtil.areItemsEqual(recipe.inputStack, input, true)){ possibleRecipes.add(recipe); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeCategory.java index 48669f70c..086b06560 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeCategory.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeCategory.java @@ -72,15 +72,14 @@ public class CrusherRecipeCategory implements IRecipeCategory{ CrusherRecipeWrapper wrapper = (CrusherRecipeWrapper)recipeWrapper; recipeLayout.getItemStacks().init(0, true, 19, 7); - recipeLayout.getItemStacks().set(0, RecipeUtil.getCrusherRecipeInputs(wrapper.theRecipe)); + recipeLayout.getItemStacks().set(0, wrapper.theRecipe.inputStack); recipeLayout.getItemStacks().init(1, false, 7, 55); - recipeLayout.getItemStacks().set(1, RecipeUtil.getCrusherRecipeOutputOnes(wrapper.theRecipe)); + recipeLayout.getItemStacks().set(1, wrapper.theRecipe.outputOneStack); - List outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(wrapper.theRecipe); - if(outputTwos != null && !outputTwos.isEmpty()){ + if(wrapper.theRecipe.outputTwoStack != null){ recipeLayout.getItemStacks().init(2, false, 31, 55); - recipeLayout.getItemStacks().set(2, outputTwos); + recipeLayout.getItemStacks().set(2, wrapper.theRecipe.outputTwoStack); } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeWrapper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeWrapper.java index 1f822eb9a..41e4e2456 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeWrapper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/crusher/CrusherRecipeWrapper.java @@ -24,6 +24,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class CrusherRecipeWrapper extends RecipeWrapperWithButton implements IRecipeWrapper{ @@ -41,19 +42,16 @@ public class CrusherRecipeWrapper extends RecipeWrapperWithButton implements IRe @Override public List getInputs(){ - return RecipeUtil.getCrusherRecipeInputs(this.theRecipe); + return Collections.singletonList(this.theRecipe.inputStack); } @Override public List getOutputs(){ List list = new ArrayList(); - list.addAll(RecipeUtil.getCrusherRecipeOutputOnes(this.theRecipe)); - - List outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(this.theRecipe); - if(outputTwos != null && !outputTwos.isEmpty()){ - list.addAll(outputTwos); + list.add(this.theRecipe.outputOneStack); + if(this.theRecipe.outputTwoStack != null){ + list.add(this.theRecipe.outputTwoStack); } - return list; } @@ -71,8 +69,7 @@ public class CrusherRecipeWrapper extends RecipeWrapperWithButton implements IRe public void drawInfo(Minecraft minecraft, int recipeWidth, int recipeHeight, int mouseX, int mouseY){ this.updateButton(minecraft, mouseX, mouseY); - List outputTwos = RecipeUtil.getCrusherRecipeOutputTwos(this.theRecipe); - if(outputTwos != null && !outputTwos.isEmpty()){ + if(this.theRecipe.outputTwoStack != null){ minecraft.fontRendererObj.drawString(this.theRecipe.outputTwoChance+"%", 60, 60, StringUtil.DECIMAL_COLOR_GRAY_TEXT, false); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeCategory.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeCategory.java index 1f9816fc0..2fe334785 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeCategory.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeCategory.java @@ -72,10 +72,10 @@ public class ReconstructorRecipeCategory implements IRecipeCategory{ ReconstructorRecipeWrapper wrapper = (ReconstructorRecipeWrapper)recipeWrapper; recipeLayout.getItemStacks().init(0, true, 4, 18); - recipeLayout.getItemStacks().set(0, RecipeUtil.getConversionLensInputs(wrapper.theRecipe)); + recipeLayout.getItemStacks().set(0, wrapper.theRecipe.inputStack); recipeLayout.getItemStacks().init(1, false, 66, 18); - recipeLayout.getItemStacks().set(1, RecipeUtil.getConversionLensOutputs(wrapper.theRecipe)); + recipeLayout.getItemStacks().set(1, wrapper.theRecipe.outputStack); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeWrapper.java b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeWrapper.java index 73509e0ee..b1aeaa75b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeWrapper.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/jei/reconstructor/ReconstructorRecipeWrapper.java @@ -23,6 +23,7 @@ import net.minecraft.item.ItemStack; import net.minecraftforge.fluids.FluidStack; import java.util.ArrayList; +import java.util.Collections; import java.util.List; public class ReconstructorRecipeWrapper extends RecipeWrapperWithButton implements IRecipeWrapper{ @@ -40,12 +41,12 @@ public class ReconstructorRecipeWrapper extends RecipeWrapperWithButton implemen @Override public List getInputs(){ - return RecipeUtil.getConversionLensInputs(this.theRecipe); + return Collections.singletonList(this.theRecipe.inputStack); } @Override public List getOutputs(){ - return RecipeUtil.getConversionLensOutputs(this.theRecipe); + return Collections.singletonList(this.theRecipe.outputStack); } @Override diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java index bb3a19af8..d73d75adb 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java @@ -10,6 +10,7 @@ package de.ellpeck.actuallyadditions.mod.misc; +import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.booklet.BookletPage; import de.ellpeck.actuallyadditions.api.booklet.IBookletChapter; import de.ellpeck.actuallyadditions.api.booklet.IBookletEntry; @@ -24,6 +25,7 @@ import de.ellpeck.actuallyadditions.mod.booklet.page.PagePicture; import de.ellpeck.actuallyadditions.mod.booklet.page.PageTextOnly; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.items.lens.LensRecipeHandler; +import de.ellpeck.actuallyadditions.mod.recipe.CrusherRecipeRegistry; import de.ellpeck.actuallyadditions.mod.util.RecipeUtil; import net.minecraft.block.Block; import net.minecraft.block.state.IBlockState; @@ -145,26 +147,23 @@ public class MethodHandler implements IMethodHandler{ List recipes = LensRecipeHandler.getRecipesFor(new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state))); for(LensConversionRecipe recipe : recipes){ if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse){ - List outputs = RecipeUtil.getConversionLensOutputs(recipe); - if(outputs != null && !outputs.isEmpty()){ - ItemStack output = outputs.get(0); - if(output != null){ - if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){ - tile.getWorldObject().playEvent(2001, pos, Block.getStateId(tile.getWorldObject().getBlockState(pos))); - } - - if(output.getItem() instanceof ItemBlock){ - tile.getWorldObject().setBlockState(pos, Block.getBlockFromItem(output.getItem()).getStateFromMeta(output.getItemDamage()), 2); - } - else{ - EntityItem item = new EntityItem(tile.getWorldObject(), pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, output.copy()); - tile.getWorldObject().spawnEntityInWorld(item); - tile.getWorldObject().setBlockToAir(pos); - } - - tile.extractEnergy(recipe.energyUse); - break; + ItemStack output = recipe.outputStack; + if(output != null){ + if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){ + tile.getWorldObject().playEvent(2001, pos, Block.getStateId(tile.getWorldObject().getBlockState(pos))); } + + if(output.getItem() instanceof ItemBlock){ + tile.getWorldObject().setBlockState(pos, Block.getBlockFromItem(output.getItem()).getStateFromMeta(output.getItemDamage()), 2); + } + else{ + EntityItem item = new EntityItem(tile.getWorldObject(), pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, output.copy()); + tile.getWorldObject().spawnEntityInWorld(item); + tile.getWorldObject().setBlockToAir(pos); + } + + tile.extractEnergy(recipe.energyUse); + break; } } } @@ -186,9 +185,7 @@ public class MethodHandler implements IMethodHandler{ List recipes = LensRecipeHandler.getRecipesFor(stack); for(LensConversionRecipe recipe : recipes){ if(recipe != null && recipe.type == tile.getLens() && tile.getEnergy() >= recipe.energyUse*stack.stackSize){ - List outputs = RecipeUtil.getConversionLensOutputs(recipe); - if(outputs != null && !outputs.isEmpty()){ - ItemStack outputCopy = outputs.get(0).copy(); + ItemStack outputCopy = recipe.outputStack.copy(); outputCopy.stackSize = stack.stackSize; item.setDead(); @@ -198,7 +195,6 @@ public class MethodHandler implements IMethodHandler{ tile.extractEnergy(recipe.energyUse*stack.stackSize); break; - } } } } @@ -232,4 +228,36 @@ public class MethodHandler implements IMethodHandler{ public IBookletChapter generateBookletChapter(String identifier, IBookletEntry entry, ItemStack displayStack, BookletPage... pages){ return new BookletChapter(identifier, entry, displayStack, pages); } + + @Override + public boolean addCrusherRecipes(List inputs, List outputOnes, int outputOneAmounts, List outputTwos, int outputTwoAmounts, int outputTwoChance){ + boolean hasWorkedOnce = false; + for(ItemStack input : inputs){ + if(input != null && CrusherRecipeRegistry.getRecipeFromInput(input) == null){ + for(ItemStack outputOne : outputOnes){ + if(outputOne != null && !CrusherRecipeRegistry.hasBlacklistedOutput(outputOne)){ + ItemStack outputOneCopy = outputOne.copy(); + outputOneCopy.stackSize = outputOneAmounts; + + if(outputTwos == null || outputTwos.isEmpty()){ + ActuallyAdditionsAPI.addCrusherRecipe(input, outputOneCopy, null, 0); + hasWorkedOnce = true; + } + else{ + for(ItemStack outputTwo : outputTwos){ + if(outputTwo != null && !CrusherRecipeRegistry.hasBlacklistedOutput(outputTwo)){ + ItemStack outputTwoCopy = outputTwo.copy(); + outputTwoCopy.stackSize = outputTwoAmounts; + + ActuallyAdditionsAPI.addCrusherRecipe(input, outputOneCopy, outputTwoCopy, outputTwoChance); + hasWorkedOnce = true; + } + } + } + } + } + } + } + return hasWorkedOnce; + } } 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 443aed7af..be5186f98 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/recipe/CrusherRecipeRegistry.java @@ -15,13 +15,11 @@ import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; 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; import java.util.ArrayList; -import java.util.List; public final class CrusherRecipeRegistry{ @@ -39,23 +37,8 @@ public final class CrusherRecipeRegistry{ if(ore.substring(0, theCase.theCase.length()).equals(theCase.theCase)){ String output = theCase.resultPreString+ore.substring(theCase.theCase.length()); - if(!hasOreRecipe(ore)){ - 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); - } + if(!ActuallyAdditionsAPI.addCrusherRecipes(OreDictionary.getOres(ore, false), OreDictionary.getOres(output, false), theCase.resultAmount, null, 0, 0)){ + oresNoResult.add(ore); } break; @@ -68,13 +51,13 @@ 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.outputOneStack); + addedRecipes.add(recipe.inputStack+" -> "+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()); + ModUtil.LOGGER.warn("Couldn't add "+oresNoResult.size()+" Crusher Recipes automatically, either because the inputs were missing outputs, or because they exist already: "+oresNoResult.toString()); } - private static boolean hasBlacklistedOutput(ItemStack output){ + public static boolean hasBlacklistedOutput(ItemStack output){ if(output != null){ Item item = output.getItem(); if(item != null){ @@ -115,32 +98,23 @@ public final class CrusherRecipeRegistry{ return false; } - public static boolean hasOreRecipe(String input){ - for(CrusherRecipe recipe : ActuallyAdditionsAPI.CRUSHER_RECIPES){ - if(recipe.input != null && recipe.input.equals(input)){ - return true; - } - } - return false; - } - - public static List getOutputOnes(ItemStack input){ + public static ItemStack getOutputOnes(ItemStack input){ CrusherRecipe recipe = getRecipeFromInput(input); - return recipe == null ? null : RecipeUtil.getCrusherRecipeOutputOnes(recipe); + return recipe == null ? null : recipe.outputOneStack; } public static CrusherRecipe getRecipeFromInput(ItemStack input){ for(CrusherRecipe recipe : ActuallyAdditionsAPI.CRUSHER_RECIPES){ - if(ItemUtil.contains(RecipeUtil.getCrusherRecipeInputs(recipe), input, true)){ + if(ItemUtil.areItemsEqual(recipe.inputStack, input, true)){ return recipe; } } return null; } - public static List getOutputTwos(ItemStack input){ + public static ItemStack getOutputTwos(ItemStack input){ CrusherRecipe recipe = getRecipeFromInput(input); - return recipe == null ? null : RecipeUtil.getCrusherRecipeOutputTwos(recipe); + return recipe == null ? null : recipe.outputTwoStack; } public static int getOutputTwoChance(ItemStack input){ diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java index 6e3541f52..0e009b097 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityGrinder.java @@ -27,8 +27,6 @@ import net.minecraft.util.SoundCategory; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; -import java.util.List; - public class TileEntityGrinder extends TileEntityInventoryBase implements ICustomEnergyReceiver, IButtonReactor{ public static final int SLOT_INPUT_1 = 0; @@ -188,21 +186,17 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto public boolean canCrushOn(int theInput, int theFirstOutput, int theSecondOutput){ if(this.slots[theInput] != null){ - List outputOnes = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]); - if(outputOnes != null && !outputOnes.isEmpty()){ - ItemStack outputOne = outputOnes.get(0); - List outputTwos = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]); - ItemStack outputTwo = outputTwos == null ? null : outputTwos.get(0); - if(outputOne != null){ - if(outputOne.getItemDamage() == Util.WILDCARD){ - outputOne.setItemDamage(0); - } - if(outputTwo != null && outputTwo.getItemDamage() == Util.WILDCARD){ - outputTwo.setItemDamage(0); - } - 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)))){ - return true; - } + ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]); + ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]); + if(outputOne != null){ + if(outputOne.getItemDamage() == Util.WILDCARD){ + outputOne.setItemDamage(0); + } + if(outputTwo != null && outputTwo.getItemDamage() == Util.WILDCARD){ + outputTwo.setItemDamage(0); + } + 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)))){ + return true; } } } @@ -214,37 +208,31 @@ public class TileEntityGrinder extends TileEntityInventoryBase implements ICusto } public void finishCrushing(int theInput, int theFirstOutput, int theSecondOutput){ - List outputOnes = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]); - if(outputOnes != null){ - ItemStack outputOne = outputOnes.get(0); - if(outputOne != null){ - if(outputOne.getItemDamage() == Util.WILDCARD){ - outputOne.setItemDamage(0); - } - if(this.slots[theFirstOutput] == null){ - this.slots[theFirstOutput] = outputOne.copy(); - } - else if(this.slots[theFirstOutput].getItem() == outputOne.getItem()){ - this.slots[theFirstOutput].stackSize += outputOne.stackSize; - } + ItemStack outputOne = CrusherRecipeRegistry.getOutputOnes(this.slots[theInput]); + if(outputOne != null){ + if(outputOne.getItemDamage() == Util.WILDCARD){ + outputOne.setItemDamage(0); + } + if(this.slots[theFirstOutput] == null){ + this.slots[theFirstOutput] = outputOne.copy(); + } + else if(this.slots[theFirstOutput].getItem() == outputOne.getItem()){ + this.slots[theFirstOutput].stackSize += outputOne.stackSize; } } - List outputTwos = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]); - if(outputTwos != null){ - ItemStack outputTwo = outputTwos.get(0); - if(outputTwo != null){ - if(outputTwo.getItemDamage() == Util.WILDCARD){ - outputTwo.setItemDamage(0); + ItemStack outputTwo = CrusherRecipeRegistry.getOutputTwos(this.slots[theInput]); + if(outputTwo != null){ + if(outputTwo.getItemDamage() == Util.WILDCARD){ + outputTwo.setItemDamage(0); + } + int rand = Util.RANDOM.nextInt(100)+1; + if(rand <= CrusherRecipeRegistry.getOutputTwoChance(this.slots[theInput])){ + if(this.slots[theSecondOutput] == null){ + this.slots[theSecondOutput] = outputTwo.copy(); } - int rand = Util.RANDOM.nextInt(100)+1; - if(rand <= CrusherRecipeRegistry.getOutputTwoChance(this.slots[theInput])){ - if(this.slots[theSecondOutput] == null){ - this.slots[theSecondOutput] = outputTwo.copy(); - } - else if(this.slots[theSecondOutput].getItem() == outputTwo.getItem()){ - this.slots[theSecondOutput].stackSize += outputTwo.stackSize; - } + else if(this.slots[theSecondOutput].getItem() == outputTwo.getItem()){ + this.slots[theSecondOutput].stackSize += outputTwo.stackSize; } } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/util/RecipeUtil.java b/src/main/java/de/ellpeck/actuallyadditions/mod/util/RecipeUtil.java index 4089ccf40..09f8005c2 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/util/RecipeUtil.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/util/RecipeUtil.java @@ -14,13 +14,8 @@ import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.recipe.CrusherRecipe; import de.ellpeck.actuallyadditions.api.recipe.EmpowererRecipe; import de.ellpeck.actuallyadditions.api.recipe.LensConversionRecipe; -import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; -import net.minecraftforge.oredict.OreDictionary; - -import java.util.ArrayList; -import java.util.Collections; import java.util.List; public final class RecipeUtil{ @@ -44,48 +39,4 @@ public final class RecipeUtil{ List list = ActuallyAdditionsAPI.EMPOWERER_RECIPES; return list.get(list.size()-1); } - - public static List getCrusherRecipeOutputOnes(CrusherRecipe recipe){ - return doRecipeOrWhatever(recipe.outputOneStack, recipe.outputOne, recipe.outputOneAmount); - } - - public static List getCrusherRecipeOutputTwos(CrusherRecipe recipe){ - return doRecipeOrWhatever(recipe.outputTwoStack, recipe.outputTwo, recipe.outputTwoAmount); - } - - public static List getCrusherRecipeInputs(CrusherRecipe recipe){ - return doRecipeOrWhatever(recipe.inputStack, recipe.input, 1); - } - - public static List getConversionLensInputs(LensConversionRecipe recipe){ - return doRecipeOrWhatever(recipe.inputStack, recipe.input, 1); - } - - public static List getConversionLensOutputs(LensConversionRecipe recipe){ - return doRecipeOrWhatever(recipe.outputStack, recipe.output, 1); - } - - private static List doRecipeOrWhatever(ItemStack stack, String oredict, int amount){ - if(stack != null){ - return Collections.singletonList(stack.copy()); - } - - if(oredict == null || oredict.isEmpty()){ - return null; - } - - List stacks = OreDictionary.getOres(oredict, false); - if(stacks != null && !stacks.isEmpty()){ - List stacksCopy = new ArrayList(); - for(ItemStack aStack : stacks){ - if(aStack != null){ - ItemStack stackCopy = aStack.copy(); - stackCopy.stackSize = amount; - stacksCopy.add(stackCopy); - } - } - return stacksCopy; - } - return null; - } }