diff --git a/MODSRC/vazkii/botania/api/BotaniaAPI.java b/MODSRC/vazkii/botania/api/BotaniaAPI.java index 087e643e4..9b454d164 100644 --- a/MODSRC/vazkii/botania/api/BotaniaAPI.java +++ b/MODSRC/vazkii/botania/api/BotaniaAPI.java @@ -14,15 +14,18 @@ package vazkii.botania.api; import java.util.ArrayList; import java.util.List; +import net.minecraft.item.ItemStack; import net.minecraft.item.crafting.CraftingManager; import net.minecraft.item.crafting.IRecipe; import vazkii.botania.api.internal.DummyMethodHandler; import vazkii.botania.api.internal.IInternalMethodHandler; +import vazkii.botania.api.internal.RecipePetals; public final class BotaniaAPI { private static List categories = new ArrayList(); private static List allEntries = new ArrayList(); + public static List petalRecipes = new ArrayList(); /** * The internal method handler in use. Do not overwrite. @@ -30,6 +33,19 @@ public final class BotaniaAPI { */ public static IInternalMethodHandler internalHandler = new DummyMethodHandler(); + /** + * Registers a Petal Recipe. + * @param output The ItemStack to craft. + * @param colors The required metadata petals for this recipe to be accept. + * Eg: 0, 0, 1 is White, White, Orange + * @return The recipe created. + */ + public static RecipePetals registerPetalRecipe(ItemStack output, int... colors) { + RecipePetals recipe = new RecipePetals(output, colors); + petalRecipes.add(recipe); + return recipe; + } + /** * Adds a category to the list of registered categories to appear in the Lexicon. */ diff --git a/MODSRC/vazkii/botania/api/internal/RecipePetals.java b/MODSRC/vazkii/botania/api/internal/RecipePetals.java new file mode 100644 index 000000000..cbd5324fc --- /dev/null +++ b/MODSRC/vazkii/botania/api/internal/RecipePetals.java @@ -0,0 +1,53 @@ +/** + * 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 22, 2014, 2:02:44 PM (GMT)] + */ +package vazkii.botania.api.internal; + +import java.util.ArrayList; +import java.util.List; + +import net.minecraft.inventory.IInventory; +import net.minecraft.item.ItemStack; + +public class RecipePetals { + + ItemStack output; + List colors = new ArrayList(); + + public RecipePetals(ItemStack output, int... colors) { + this.output = output; + for(int c : colors) + this.colors.add(c); + } + + public boolean matches(IInventory inv) { + List colorsMissing = new ArrayList(colors); + + for(int i = 0; i < inv.getSizeInventory(); i++) { + ItemStack stack = inv.getStackInSlot(i); + if(stack == null) + break; + + int color = stack.getItemDamage(); + + if(!colorsMissing.contains(color)) + return false; + colorsMissing.remove((Integer) color); + } + + return colorsMissing.isEmpty(); + } + + public ItemStack getOutput() { + return output; + } + +} diff --git a/MODSRC/vazkii/botania/common/block/tile/TileAltar.java b/MODSRC/vazkii/botania/common/block/tile/TileAltar.java index 42f0cf525..1369d7e1a 100644 --- a/MODSRC/vazkii/botania/common/block/tile/TileAltar.java +++ b/MODSRC/vazkii/botania/common/block/tile/TileAltar.java @@ -16,9 +16,13 @@ import java.util.List; import cpw.mods.fml.common.network.PacketDispatcher; import net.minecraft.entity.item.EntityItem; import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.AxisAlignedBB; +import net.minecraftforge.oredict.OreDictionary; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.internal.RecipePetals; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.lib.LibBlockNames; @@ -35,13 +39,18 @@ public class TileAltar extends TileSimpleInventory implements ISidedInventory { boolean didChange = false; ItemStack stack = item.getEntityItem(); + if(stack == null) + return false; + if(stack.itemID == ModItems.petal.itemID) { if(getStackInSlot(getSizeInventory() - 1) != null) return false; - stack.stackSize--; - if(stack.stackSize == 0) - item.setDead(); + if(!worldObj.isRemote) { + stack.stackSize--; + if(stack.stackSize == 0) + item.setDead(); + } for(int i = 0; i < getSizeInventory(); i++) if(getStackInSlot(i) == null) { @@ -49,6 +58,25 @@ public class TileAltar extends TileSimpleInventory implements ISidedInventory { didChange = true; break; } + } else if(stack.itemID == Item.seeds.itemID) { + for(RecipePetals recipe : BotaniaAPI.petalRecipes) { + if(recipe.matches(this)) { + ItemStack output = recipe.getOutput().copy(); + EntityItem outputItem = new EntityItem(worldObj, xCoord + 0.5, yCoord + 1.5, zCoord + 0.5, output); + worldObj.spawnEntityInWorld(outputItem); + for(int i = 0; i < getSizeInventory(); i++) + setInventorySlotContents(i, null); + + if(!worldObj.isRemote) { + stack.stackSize--; + if(stack.stackSize == 0) + item.setDead(); + } + + didChange = true; + break; + } + } } return didChange; diff --git a/MODSRC/vazkii/botania/common/core/proxy/CommonProxy.java b/MODSRC/vazkii/botania/common/core/proxy/CommonProxy.java index c58373a83..7ce9cf1b0 100644 --- a/MODSRC/vazkii/botania/common/core/proxy/CommonProxy.java +++ b/MODSRC/vazkii/botania/common/core/proxy/CommonProxy.java @@ -17,10 +17,11 @@ import vazkii.botania.api.BotaniaAPI; import vazkii.botania.api.LexiconEntry; import vazkii.botania.common.Botania; import vazkii.botania.common.block.ModBlocks; +import vazkii.botania.common.core.handler.BiomeDecorationHandler; import vazkii.botania.common.core.handler.ConfigHandler; import vazkii.botania.common.core.handler.InternalMethodHandler; -import vazkii.botania.common.core.handler.BiomeDecorationHandler; import vazkii.botania.common.crafting.ModCrafingRecipes; +import vazkii.botania.common.crafting.ModPetalRecipes; import vazkii.botania.common.item.ModItems; import vazkii.botania.common.lexicon.LexiconData; import vazkii.botania.common.network.GuiHandler; @@ -28,7 +29,6 @@ import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLPostInitializationEvent; import cpw.mods.fml.common.event.FMLPreInitializationEvent; import cpw.mods.fml.common.network.NetworkRegistry; -import cpw.mods.fml.common.registry.GameRegistry; public class CommonProxy { @@ -41,7 +41,8 @@ public class CommonProxy { ModItems.init(); ModCrafingRecipes.init(); - + ModPetalRecipes.init(); + LexiconData.init(); } diff --git a/MODSRC/vazkii/botania/common/crafting/ModPetalRecipes.java b/MODSRC/vazkii/botania/common/crafting/ModPetalRecipes.java new file mode 100644 index 000000000..5543a42ec --- /dev/null +++ b/MODSRC/vazkii/botania/common/crafting/ModPetalRecipes.java @@ -0,0 +1,29 @@ +/** + * 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 22, 2014, 2:22:21 PM (GMT)] + */ +package vazkii.botania.common.crafting; + +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import vazkii.botania.api.BotaniaAPI; +import vazkii.botania.api.internal.RecipePetals; + +public final class ModPetalRecipes { + + public static final int white = 0, orange = 1, magenta = 2, lightBlue = 3, yellow = 4, lime = 5, pink = 6, gray = 7, lightGray = 8, cyan = 9, purple = 10, blue = 11, brown = 12, green = 13, red = 14, black = 15; + + public static RecipePetals testRecipe; + + public static void init() { + testRecipe = BotaniaAPI.registerPetalRecipe(new ItemStack(Item.diamond), orange, orange, white); + } + +}