Make Cosmetic items actually render.

This commit is contained in:
Lizbeth Rika committed 2015-02-22 21:50:40 +00:00
1 parent da02c13a71
commit a3e1dc3c6d
8 files changed
+257 -7

No files matched your search

@@ -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);
@@ -0,0 +1,33 @@
/**
* This class was created by <Vazkii>. 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);
}
@@ -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();
}
}
}
}
@@ -0,0 +1,77 @@
/**
* This class was created by <Vazkii>. 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;
}
}
@@ -0,0 +1,70 @@
/**
* This class was created by <Vazkii>. 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;
}
}
@@ -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<String> 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);
}
@@ -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