equivalent-exchange-3/src/main/java/com/pahimar/ee3/item/ItemAlchemicalBag.java

168 lines
4.2 KiB
Java
Raw Normal View History

2013-08-23 16:59:50 +02:00
package com.pahimar.ee3.item;
import com.pahimar.ee3.EquivalentExchange3;
2013-12-17 21:48:21 +01:00
import com.pahimar.ee3.helper.ItemHelper;
import com.pahimar.ee3.helper.ItemStackNBTHelper;
2013-08-23 16:59:50 +02:00
import com.pahimar.ee3.lib.Colours;
import com.pahimar.ee3.lib.GuiIds;
import com.pahimar.ee3.lib.Strings;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.Icon;
import net.minecraft.world.World;
2013-08-23 16:59:50 +02:00
/**
* Equivalent-Exchange-3
* <p/>
2013-08-23 16:59:50 +02:00
* ItemAlchemicalBag
*
2013-08-23 16:59:50 +02:00
* @author pahimar
*/
2014-01-02 09:55:01 +01:00
public class ItemAlchemicalBag extends ItemEE implements IDyeable
{
2013-12-20 12:58:15 +01:00
private static final String[] ALCHEMICAL_BAG_ICONS = {"Open", "OpenDrawString", "Closed", "ClosedDrawString"};
2013-08-23 16:59:50 +02:00
@SideOnly(Side.CLIENT)
private Icon[] icons;
public ItemAlchemicalBag(int id)
{
2013-08-23 16:59:50 +02:00
super(id);
2014-01-02 09:55:01 +01:00
this.setUnlocalizedName(Strings.ALCHEMICAL_BAG_NAME);
2013-08-23 16:59:50 +02:00
}
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IconRegister iconRegister)
{
2013-12-20 12:58:15 +01:00
icons = new Icon[ALCHEMICAL_BAG_ICONS.length];
2013-08-23 16:59:50 +02:00
2013-12-20 12:58:15 +01:00
for (int i = 0; i < ALCHEMICAL_BAG_ICONS.length; ++i)
{
2013-12-20 12:58:15 +01:00
icons[i] = iconRegister.registerIcon(Strings.RESOURCE_PREFIX + Strings.ALCHEMICAL_BAG_NAME + ALCHEMICAL_BAG_ICONS[i]);
2013-08-23 16:59:50 +02:00
}
}
@Override
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer)
{
if (!world.isRemote)
{
ItemStackNBTHelper.setBoolean(itemStack, Strings.NBT_ITEM_ALCHEMICAL_BAG_GUI_OPEN, true);
2013-08-23 16:59:50 +02:00
entityPlayer.openGui(EquivalentExchange3.instance, GuiIds.ALCHEMICAL_BAG, entityPlayer.worldObj, (int) entityPlayer.posX, (int) entityPlayer.posY, (int) entityPlayer.posZ);
}
return itemStack;
}
@Override
public boolean getShareTag()
{
2013-08-23 16:59:50 +02:00
return true;
}
@Override
@SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses()
{
2013-08-23 16:59:50 +02:00
return true;
}
@Override
public Icon getIcon(ItemStack itemStack, int renderPass)
{
2013-08-23 16:59:50 +02:00
// If the bag is open
if (ItemStackNBTHelper.hasTag(itemStack, Strings.NBT_ITEM_ALCHEMICAL_BAG_GUI_OPEN))
{
2013-08-23 16:59:50 +02:00
if (renderPass != 1)
{
2013-08-23 16:59:50 +02:00
return icons[0];
}
2013-08-23 16:59:50 +02:00
else
{
2013-08-23 16:59:50 +02:00
return icons[1];
}
2013-08-23 16:59:50 +02:00
}
// Else, the bag is closed
else
{
2013-08-23 16:59:50 +02:00
if (renderPass != 1)
{
2013-08-23 16:59:50 +02:00
return icons[2];
}
2013-08-23 16:59:50 +02:00
else
{
2013-08-23 16:59:50 +02:00
return icons[3];
}
2013-08-23 16:59:50 +02:00
}
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack itemStack, int renderPass)
{
2013-08-23 16:59:50 +02:00
if (renderPass == 1)
{
2013-08-23 16:59:50 +02:00
return Integer.parseInt(Colours.PURE_WHITE, 16);
}
else
{
2013-08-23 16:59:50 +02:00
int bagColor = this.getColor(itemStack);
if (bagColor < 0)
{
2013-08-23 16:59:50 +02:00
bagColor = Integer.parseInt(Colours.PURE_WHITE, 16);
}
return bagColor;
}
}
2014-01-02 09:55:01 +01:00
@Override
public boolean hasColor(ItemStack itemStack)
{
return ItemHelper.hasColor(itemStack);
2013-08-23 16:59:50 +02:00
}
2014-01-02 09:55:01 +01:00
@Override
public int getColor(ItemStack itemStack)
{
return ItemHelper.getColor(itemStack);
2013-08-23 16:59:50 +02:00
}
2014-01-02 09:55:01 +01:00
@Override
public void setColor(ItemStack itemStack, int color)
{
if (itemStack != null)
{
2013-12-20 12:58:15 +01:00
if (itemStack.getItem() instanceof ItemAlchemicalBag)
{
ItemHelper.setColor(itemStack, color);
2013-08-23 16:59:50 +02:00
}
}
}
2014-01-02 09:55:01 +01:00
@Override
public void removeColor(ItemStack itemStack)
{
if (itemStack != null)
{
2013-08-23 16:59:50 +02:00
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
if (nbtTagCompound != null)
{
2013-08-23 16:59:50 +02:00
NBTTagCompound displayTagCompound = nbtTagCompound.getCompoundTag(Strings.NBT_ITEM_DISPLAY);
if (displayTagCompound.hasKey(Strings.NBT_ITEM_COLOR))
{
2013-08-23 16:59:50 +02:00
displayTagCompound.removeTag(Strings.NBT_ITEM_COLOR);
}
}
}
}
}