From 4801313df08dae58ee267a5b3e4f7adbcaddd8c3 Mon Sep 17 00:00:00 2001 From: Lizbeth Rika Date: Fri, 23 Jan 2015 16:57:17 +0000 Subject: [PATCH] Fixed dying Composite Lenses removing the composite component. Took me long enough. Closes #260 --- .../common/crafting/ModCraftingRecipes.java | 17 --- .../crafting/recipe/LensDyingRecipe.java | 102 ++++++++++++++++++ .../vazkii/botania/common/item/ItemLens.java | 3 + .../botania/common/lexicon/LexiconData.java | 2 +- .../resources/assets/botania/lang/en_US.lang | 2 +- 5 files changed, 107 insertions(+), 19 deletions(-) create mode 100644 src/main/java/vazkii/botania/common/crafting/recipe/LensDyingRecipe.java diff --git a/src/main/java/vazkii/botania/common/crafting/ModCraftingRecipes.java b/src/main/java/vazkii/botania/common/crafting/ModCraftingRecipes.java index 4c914612c..3cc8fa006 100644 --- a/src/main/java/vazkii/botania/common/crafting/ModCraftingRecipes.java +++ b/src/main/java/vazkii/botania/common/crafting/ModCraftingRecipes.java @@ -43,8 +43,6 @@ public final class ModCraftingRecipes { public static List recipesApothecary; public static List recipesSpreader; public static IRecipe recipeManaLens; - public static List recipesLensDying; - public static IRecipe recipeRainbowLens; public static IRecipe recipePool; public static List recipesRuneAltar; public static IRecipe recipeLensVelocity; @@ -274,21 +272,6 @@ public final class ModCraftingRecipes { 'G', new ItemStack(Blocks.glass_pane)); recipeManaLens = BotaniaAPI.getLatestAddedRecipe(); - // Mana Lens Dying Recipes - for(int j = 0; j < 16; j++) - addShapelessOreDictRecipe(ItemLens.setLensColor(new ItemStack(ModItems.lens), j), new ItemStack(ModItems.lens), LibOreDict.DYE[j]); - recipesLensDying = BotaniaAPI.getLatestAddedRecipes(16); - - for(int i = 1; i < ItemLens.SUBTYPES; i++) - for(int j = 0; j < 16; j++) - addShapelessOreDictRecipe(ItemLens.setLensColor(new ItemStack(ModItems.lens, 1, i), j), new ItemStack(ModItems.lens, 1, i), LibOreDict.DYE[j]); - - // Rainbow Lens Recipe - addShapelessOreDictRecipe(ItemLens.setLensColor(new ItemStack(ModItems.lens), 16), new ItemStack(ModItems.lens), LibOreDict.MANA_PEARL); - recipeRainbowLens = BotaniaAPI.getLatestAddedRecipe(); - for(int i = 1; i < ItemLens.SUBTYPES; i++) - addShapelessOreDictRecipe(ItemLens.setLensColor(new ItemStack(ModItems.lens, 1, i), 16), new ItemStack(ModItems.lens, 1, i), LibOreDict.MANA_PEARL); - // Mana Pool Recipe addOreDictRecipe(new ItemStack(ModBlocks.pool, 1, 2), "R R", "RRR", diff --git a/src/main/java/vazkii/botania/common/crafting/recipe/LensDyingRecipe.java b/src/main/java/vazkii/botania/common/crafting/recipe/LensDyingRecipe.java new file mode 100644 index 000000000..430d6663a --- /dev/null +++ b/src/main/java/vazkii/botania/common/crafting/recipe/LensDyingRecipe.java @@ -0,0 +1,102 @@ +/** + * This class was created by . It's distributed as + * part of the Botania Mod. Get the Source Code in github: + * https://github.com/Vazkii/Botania + * + * Botania is Open Source and distributed under a + * Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License + * (http://creativecommons.org/licenses/by-nc-sa/3.0/deed.en_GB) + * + * File Created @ [Jan 23, 2015, 4:10:24 PM (GMT)] + */ +package vazkii.botania.common.crafting.recipe; + +import java.util.Arrays; +import java.util.List; + +import net.minecraft.init.Items; +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import net.minecraftforge.oredict.OreDictionary; +import vazkii.botania.api.mana.ILens; +import vazkii.botania.common.item.ItemLens; +import vazkii.botania.common.item.ModItems; +import vazkii.botania.common.lib.LibOreDict; + +public class LensDyingRecipe implements IRecipe { + + private static final List DYES = Arrays.asList(new String[] { + "dyeWhite", "dyeOrange", "dyeMagenta", "dyeLightBlue", "dyeYellow", "dyeLime", "dyePink", "dyeGray", "dyeLightGray", "dyeCyan", "dyePurple", "dyeBlue", "dyeBrown", "dyeGreen", "dyeRed", "dyeBlack", LibOreDict.MANA_PEARL + }); + + @Override + public boolean matches(InventoryCrafting var1, World var2) { + boolean foundLens = false; + boolean foundDye = false; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(stack != null) { + if(stack.getItem() instanceof ILens && !foundLens) + foundLens = true; + else if(!foundDye) { + int color = getStackColor(stack); + if(color > -1) + foundDye = true; + else return false; + } + } + } + + return foundLens && foundDye; + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting var1) { + ItemStack lens = null; + int color = -1; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(stack != null) { + if(stack.getItem() instanceof ILens && lens == null) + lens = stack; + else color = getStackColor(stack); + } + } + + if(lens.getItem() instanceof ILens) { + ILens lensItem = (ILens) lens.getItem(); + ItemStack lensCopy = lens.copy(); + ((ItemLens) ModItems.lens).setLensColor(lensCopy, color); + + return lensCopy; + } + + return null; + } + + @Override + public int getRecipeSize() { + return 10; + } + + @Override + public ItemStack getRecipeOutput() { + return null; + } + + int getStackColor(ItemStack stack) { + int[] ids = OreDictionary.getOreIDs(stack); + for(int i : ids) { + int index = DYES.indexOf(OreDictionary.getOreName(i)); + if(index > 0) + return index; + } + + return -1; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/ItemLens.java b/src/main/java/vazkii/botania/common/item/ItemLens.java index 3e0e36661..dffcc7a67 100644 --- a/src/main/java/vazkii/botania/common/item/ItemLens.java +++ b/src/main/java/vazkii/botania/common/item/ItemLens.java @@ -58,6 +58,7 @@ import vazkii.botania.common.core.helper.ItemNBTHelper; import vazkii.botania.common.core.helper.MathHelper; import vazkii.botania.common.core.helper.Vector3; import vazkii.botania.common.crafting.recipe.CompositeLensRecipe; +import vazkii.botania.common.crafting.recipe.LensDyingRecipe; import vazkii.botania.common.lib.LibItemNames; import cpw.mods.fml.common.registry.GameRegistry; @@ -138,7 +139,9 @@ public class ItemLens extends ItemMod implements ILens { setHasSubtypes(true); GameRegistry.addRecipe(new CompositeLensRecipe()); + GameRegistry.addRecipe(new LensDyingRecipe()); RecipeSorter.register("botania:compositeLens", CompositeLensRecipe.class, Category.SHAPELESS, ""); + RecipeSorter.register("botania:lensDying", CompositeLensRecipe.class, Category.SHAPELESS, ""); } @Override diff --git a/src/main/java/vazkii/botania/common/lexicon/LexiconData.java b/src/main/java/vazkii/botania/common/lexicon/LexiconData.java index f33ee9928..b2a21eb7b 100644 --- a/src/main/java/vazkii/botania/common/lexicon/LexiconData.java +++ b/src/main/java/vazkii/botania/common/lexicon/LexiconData.java @@ -272,7 +272,7 @@ public final class LexiconData { rfGenerator.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModCraftingRecipes.recipeRFGenerator)); lenses = new BLexiconEntry(LibLexicon.MANA_LENSES, categoryMana); - lenses.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModCraftingRecipes.recipeManaLens), new PageCraftingRecipe("2", ModCraftingRecipes.recipesLensDying), new PageCraftingRecipe("3", ModCraftingRecipes.recipeRainbowLens), new PageText("4"), new PageText("5"), + lenses.setLexiconPages(new PageText("0"), new PageCraftingRecipe("1", ModCraftingRecipes.recipeManaLens), new PageText("4"), new PageText("5"), new PageText("6"), new PageCraftingRecipe("7", ModCraftingRecipes.recipeLensVelocity), new PageText("8"), new PageCraftingRecipe("9", ModCraftingRecipes.recipeLensPotency), new PageText("10"), new PageCraftingRecipe("11", ModCraftingRecipes.recipeLensResistance), diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index 7034f4579..8912de31c 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -1001,7 +1001,7 @@ botania.page.rfGenerator1=The bullet guys. I bit it. # -- MANA LENSES botania.entry.lens=Mana Lenses -botania.page.lens0=In order to upgrade the potential a &1Mana Spreader&0, one can apply &1Mana Lenses&0. The very basic mana lens does absolutely nothing.
Lenses can be &4dyed&0 all the 16 colors of the spectrum, or combined with a &1Mana Pearl&0 to create a &1Rainbow Lens&0. These will change the color of the burst. +botania.page.lens0=In order to upgrade the potential a &1Mana Spreader&0, one can apply &1Mana Lenses&0. The very basic mana lens does absolutely nothing.
Lenses can be &4dyed&0, in a workbench, all the 16 colors of the spectrum, or combined with a &1Mana Pearl&0 to create a &1Rainbow Lens&0. These will change the color of the burst. botania.page.lens1=The basic lens, it doesn't do anything. botania.page.lens2=&4Dying&0 lenses! botania.page.lens3=&1Rainbow Lens&0 all the way