diff --git a/src/main/java/vazkii/botania/api/item/IBaubleRender.java b/src/main/java/vazkii/botania/api/item/IBaubleRender.java index c78621711..7cc492a39 100644 --- a/src/main/java/vazkii/botania/api/item/IBaubleRender.java +++ b/src/main/java/vazkii/botania/api/item/IBaubleRender.java @@ -32,7 +32,8 @@ public interface IBaubleRender { * Called for the rendering of the bauble on the player. The player instance can be * acquired through the event parameter. Transformations are already applied for * the RenderType passed in. Make sure to check against the type parameter for - * rendering. + * rendering. Will not be called if the item is a ICosmeticAttachable and + * has a cosmetic bauble attached to it. */ @SideOnly(Side.CLIENT) public void onPlayerBaubleRender(ItemStack stack, RenderPlayerEvent event, RenderType type); diff --git a/src/main/java/vazkii/botania/api/item/ICosmeticAttachable.java b/src/main/java/vazkii/botania/api/item/ICosmeticAttachable.java new file mode 100644 index 000000000..31cf6cbec --- /dev/null +++ b/src/main/java/vazkii/botania/api/item/ICosmeticAttachable.java @@ -0,0 +1,33 @@ +/** + * 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 the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Feb 22, 2015, 8:31:39 PM (GMT)] + */ +package vazkii.botania.api.item; + +import net.minecraft.item.ItemStack; + +/** + * An Item that implements this interface can have cosmetic items attached to it. + * The item does not have to be a bauble, but it is the render is automatically + * handled by botania internally. Recipes to add and remove the cosmetic items will be + * handled internally, but the cosmetic item has to be set as a container item. + */ +public interface ICosmeticAttachable { + + /** + * Gets the cosmetic item stored in the stack passed in. + */ + public ItemStack getCosmeticItem(ItemStack stack); + + /** + * Sets the stack's cosmetic item to the one passed in. + */ + public void setCosmeticItem(ItemStack stack, ItemStack cosmetic); + +} diff --git a/src/main/java/vazkii/botania/client/core/handler/BaubleRenderHandler.java b/src/main/java/vazkii/botania/client/core/handler/BaubleRenderHandler.java index ed1c97109..bf9c5d353 100644 --- a/src/main/java/vazkii/botania/client/core/handler/BaubleRenderHandler.java +++ b/src/main/java/vazkii/botania/client/core/handler/BaubleRenderHandler.java @@ -28,6 +28,7 @@ import org.lwjgl.opengl.GL11; import vazkii.botania.api.item.IBaubleRender; import vazkii.botania.api.item.IBaubleRender.Helper; import vazkii.botania.api.item.IBaubleRender.RenderType; +import vazkii.botania.api.item.ICosmeticAttachable; import vazkii.botania.common.block.BlockModFlower; import vazkii.botania.common.block.ModBlocks; import vazkii.botania.common.core.handler.ConfigHandler; @@ -73,11 +74,27 @@ public final class BaubleRenderHandler { private void dispatchRenders(InventoryBaubles inv, RenderPlayerEvent event, RenderType type) { for(int i = 0; i < inv.getSizeInventory(); i++) { ItemStack stack = inv.getStackInSlot(i); - if(stack != null && stack.getItem() instanceof IBaubleRender) { - GL11.glPushMatrix(); - GL11.glColor4f(1F, 1F, 1F, 1F); - ((IBaubleRender) stack.getItem()).onPlayerBaubleRender(stack, event, type); - GL11.glPopMatrix(); + if(stack != null) { + Item item = stack.getItem(); + + if(item instanceof ICosmeticAttachable) { + ICosmeticAttachable attachable = (ICosmeticAttachable) item; + ItemStack cosmetic = attachable.getCosmeticItem(stack); + if(cosmetic != null) { + GL11.glPushMatrix(); + GL11.glColor4f(1F, 1F, 1F, 1F); + ((IBaubleRender) cosmetic.getItem()).onPlayerBaubleRender(cosmetic, event, type); + GL11.glPopMatrix(); + continue; + } + } + + if(item instanceof IBaubleRender) { + GL11.glPushMatrix(); + GL11.glColor4f(1F, 1F, 1F, 1F); + ((IBaubleRender) stack.getItem()).onPlayerBaubleRender(stack, event, type); + GL11.glPopMatrix(); + } } } } diff --git a/src/main/java/vazkii/botania/common/crafting/recipe/CosmeticAttachRecipe.java b/src/main/java/vazkii/botania/common/crafting/recipe/CosmeticAttachRecipe.java new file mode 100644 index 000000000..f9431439d --- /dev/null +++ b/src/main/java/vazkii/botania/common/crafting/recipe/CosmeticAttachRecipe.java @@ -0,0 +1,77 @@ +/** + * 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 the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Feb 22, 2015, 8:49:53 PM (GMT)] + */ +package vazkii.botania.common.crafting.recipe; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import vazkii.botania.api.item.IAncientWillContainer; +import vazkii.botania.api.item.ICosmeticAttachable; +import vazkii.botania.api.item.ICosmeticBauble; +import vazkii.botania.common.item.ModItems; + +public class CosmeticAttachRecipe implements IRecipe { + + @Override + public boolean matches(InventoryCrafting var1, World var2) { + boolean foundCosmetic = false; + boolean foundAttachable = false; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(stack != null) { + if(stack.getItem() instanceof ICosmeticBauble && !foundCosmetic) + foundCosmetic = true; + else if(!foundAttachable) { + if(stack.getItem() instanceof ICosmeticAttachable && !(stack.getItem() instanceof ICosmeticBauble) && ((ICosmeticAttachable) stack.getItem()).getCosmeticItem(stack) == null) + foundAttachable = true; + else return false; + } + } + } + + return foundCosmetic && foundAttachable; + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting var1) { + ItemStack cosmeticItem = null; + ItemStack attachableItem = null; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(stack != null) { + if(stack.getItem() instanceof ICosmeticBauble && cosmeticItem == null) + cosmeticItem = stack; + else attachableItem = stack; + } + } + + ICosmeticAttachable attachable = (ICosmeticAttachable) attachableItem.getItem(); + if(attachable.getCosmeticItem(attachableItem) != null) + return null; + + ItemStack copy = attachableItem.copy(); + attachable.setCosmeticItem(copy, cosmeticItem); + return copy; + } + + @Override + public int getRecipeSize() { + return 10; + } + + @Override + public ItemStack getRecipeOutput() { + return null; + } +} diff --git a/src/main/java/vazkii/botania/common/crafting/recipe/CosmeticRemoveRecipe.java b/src/main/java/vazkii/botania/common/crafting/recipe/CosmeticRemoveRecipe.java new file mode 100644 index 000000000..49dfec865 --- /dev/null +++ b/src/main/java/vazkii/botania/common/crafting/recipe/CosmeticRemoveRecipe.java @@ -0,0 +1,70 @@ +/** + * 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 the + * Botania License: http://botaniamod.net/license.php + * + * File Created @ [Feb 22, 2015, 8:55:03 PM (GMT)] + */ +package vazkii.botania.common.crafting.recipe; + +import net.minecraft.inventory.InventoryCrafting; +import net.minecraft.item.ItemStack; +import net.minecraft.item.crafting.IRecipe; +import net.minecraft.world.World; +import vazkii.botania.api.item.ICosmeticAttachable; +import vazkii.botania.api.item.ICosmeticBauble; + +public class CosmeticRemoveRecipe implements IRecipe { + + @Override + public boolean matches(InventoryCrafting var1, World var2) { + boolean foundAttachable = false; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(stack != null) { + if(!foundAttachable) { + if(stack.getItem() instanceof ICosmeticAttachable && !(stack.getItem() instanceof ICosmeticBauble) && ((ICosmeticAttachable) stack.getItem()).getCosmeticItem(stack) != null) { + foundAttachable = true; + break; + } else return false; + } + } + } + + return foundAttachable; + } + + @Override + public ItemStack getCraftingResult(InventoryCrafting var1) { + ItemStack attachableItem = null; + + for(int i = 0; i < var1.getSizeInventory(); i++) { + ItemStack stack = var1.getStackInSlot(i); + if(stack != null) + attachableItem = stack; + } + + ICosmeticAttachable attachable = (ICosmeticAttachable) attachableItem.getItem(); + if(attachable.getCosmeticItem(attachableItem) == null) + return null; + + ItemStack copy = attachableItem.copy(); + attachable.setCosmeticItem(copy, null); + return copy; + } + + @Override + public int getRecipeSize() { + return 10; + } + + @Override + public ItemStack getRecipeOutput() { + return null; + } + +} diff --git a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemBauble.java b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemBauble.java index fa2597541..fa960c221 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemBauble.java +++ b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemBauble.java @@ -16,8 +16,10 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; import net.minecraft.util.StatCollector; import net.minecraft.world.World; +import vazkii.botania.api.item.ICosmeticAttachable; import vazkii.botania.common.achievement.ModAchievements; import vazkii.botania.common.core.helper.ItemNBTHelper; import vazkii.botania.common.entity.EntityDoppleganger; @@ -29,9 +31,10 @@ import baubles.common.lib.PlayerHandler; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -public abstract class ItemBauble extends ItemMod implements IBauble { +public abstract class ItemBauble extends ItemMod implements IBauble, ICosmeticAttachable { private static final String TAG_HASHCODE = "playerHashcode"; + private static final String TAG_COSMETIC_ITEM = "cosmeticItem"; public ItemBauble(String name) { super(); @@ -85,6 +88,10 @@ public abstract class ItemBauble extends ItemMod implements IBauble { if(key != null) addStringToTooltip(StatCollector.translateToLocal("botania.baubletooltip").replaceAll("%key%", key), par3List); + + ItemStack cosmetic = getCosmeticItem(par1ItemStack); + if(cosmetic != null) + addStringToTooltip(String.format(StatCollector.translateToLocal("botaniamisc.hasCosmetic"), cosmetic.getDisplayName()), par3List); } void addStringToTooltip(String s, List tooltip) { @@ -130,6 +137,37 @@ public abstract class ItemBauble extends ItemMod implements IBauble { // NO-OP } + @Override + public ItemStack getCosmeticItem(ItemStack stack) { + NBTTagCompound cmp = ItemNBTHelper.getCompound(stack, TAG_COSMETIC_ITEM, true); + if(cmp == null) + return null; + return ItemStack.loadItemStackFromNBT(cmp); + } + + @Override + public void setCosmeticItem(ItemStack stack, ItemStack cosmetic) { + NBTTagCompound cmp = new NBTTagCompound(); + if(cosmetic != null) + cosmetic.writeToNBT(cmp); + ItemNBTHelper.setCompound(stack, TAG_COSMETIC_ITEM, cmp); + } + + @Override + public boolean hasContainerItem(ItemStack stack) { + return getContainerItem(stack) != null; + } + + @Override + public ItemStack getContainerItem(ItemStack itemStack) { + return getCosmeticItem(itemStack); + } + + @Override + public boolean doesContainerItemLeaveCraftingGrid(ItemStack p_77630_1_) { + return false; + } + public int getLastPlayerHashcode(ItemStack stack) { return ItemNBTHelper.getInt(stack, TAG_HASHCODE, 0); } diff --git a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemBaubleCosmetic.java b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemBaubleCosmetic.java index 452ecd25a..5ab998ea0 100644 --- a/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemBaubleCosmetic.java +++ b/src/main/java/vazkii/botania/common/item/equipment/bauble/ItemBaubleCosmetic.java @@ -14,6 +14,7 @@ import java.util.List; import org.lwjgl.opengl.GL11; +import cpw.mods.fml.common.registry.GameRegistry; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemRenderer; import net.minecraft.client.renderer.Tessellator; @@ -26,10 +27,17 @@ import net.minecraft.item.ItemStack; import net.minecraft.util.IIcon; import net.minecraft.util.StatCollector; import net.minecraftforge.client.event.RenderPlayerEvent; +import net.minecraftforge.oredict.RecipeSorter; +import net.minecraftforge.oredict.RecipeSorter.Category; import vazkii.botania.api.item.ICosmeticBauble; import vazkii.botania.api.item.IBaubleRender.Helper; import vazkii.botania.client.core.handler.ClientTickHandler; import vazkii.botania.client.core.helper.IconHelper; +import vazkii.botania.common.crafting.recipe.CosmeticAttachRecipe; +import vazkii.botania.common.crafting.recipe.CosmeticRemoveRecipe; +import vazkii.botania.common.crafting.recipe.ManaGunClipRecipe; +import vazkii.botania.common.crafting.recipe.ManaGunLensRecipe; +import vazkii.botania.common.crafting.recipe.ManaGunRemoveLensRecipe; import vazkii.botania.common.lib.LibItemNames; import baubles.api.BaubleType; @@ -41,6 +49,11 @@ public class ItemBaubleCosmetic extends ItemBauble implements ICosmeticBauble { public ItemBaubleCosmetic() { super(LibItemNames.COSMETIC); setHasSubtypes(true); + + GameRegistry.addRecipe(new CosmeticAttachRecipe()); + GameRegistry.addRecipe(new CosmeticRemoveRecipe()); + RecipeSorter.register("botania:cosmeticAttach", CosmeticAttachRecipe.class, Category.SHAPELESS, ""); + RecipeSorter.register("botania:cosmeticRemove", CosmeticRemoveRecipe.class, Category.SHAPELESS, ""); } @Override diff --git a/src/main/resources/assets/botania/lang/en_US.lang b/src/main/resources/assets/botania/lang/en_US.lang index 7f13fe99a..62db99905 100644 --- a/src/main/resources/assets/botania/lang/en_US.lang +++ b/src/main/resources/assets/botania/lang/en_US.lang @@ -84,6 +84,7 @@ botaniamisc.startTutorial=Start Tutorial botaniamisc.tutorialStarted=You have started your tutorial, follow the red arrows and read the contents to be guided through the basics of Botania! botaniamisc.tutorialEnded=Your tutorial is over, you should now have a basic idea of how Botania works, make sure to read through the other pages at your leisure to learn more ways of using the mod. botaniamisc.cosmeticBauble=&oCosmetic +botaniamisc.hasCosmetic=&oHas Cosmetic Override: &r%s # NEI INTEGRATION botania.nei.brewery=Botanical Brewery