2012-12-17 21:21:53 +01:00
|
|
|
package com.pahimar.ee3.item;
|
2012-12-01 04:45:54 +01:00
|
|
|
|
2013-03-07 00:46:19 +01:00
|
|
|
import net.minecraft.client.renderer.texture.IconRegister;
|
2013-02-26 22:08:43 +01:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2012-12-19 19:09:56 +01:00
|
|
|
import net.minecraft.item.ItemStack;
|
2013-03-08 03:26:42 +01:00
|
|
|
import net.minecraft.nbt.NBTTagCompound;
|
2013-03-05 04:18:15 +01:00
|
|
|
import net.minecraft.util.Icon;
|
2013-02-26 22:08:43 +01:00
|
|
|
import net.minecraft.world.World;
|
2012-12-19 19:09:56 +01:00
|
|
|
|
2012-12-17 21:21:53 +01:00
|
|
|
import com.pahimar.ee3.EquivalentExchange3;
|
2013-05-22 06:08:53 +02:00
|
|
|
import com.pahimar.ee3.core.util.ItemUtil;
|
2013-05-20 06:19:26 +02:00
|
|
|
import com.pahimar.ee3.core.util.NBTHelper;
|
2013-03-08 04:45:55 +01:00
|
|
|
import com.pahimar.ee3.lib.Colours;
|
2013-02-26 22:08:43 +01:00
|
|
|
import com.pahimar.ee3.lib.GuiIds;
|
2013-03-07 00:46:19 +01:00
|
|
|
import com.pahimar.ee3.lib.Reference;
|
2012-12-17 21:21:53 +01:00
|
|
|
import com.pahimar.ee3.lib.Strings;
|
|
|
|
|
2012-12-18 14:41:49 +01:00
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
2012-12-01 04:45:54 +01:00
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
/**
|
|
|
|
* Equivalent-Exchange-3
|
|
|
|
*
|
|
|
|
* ItemAlchemicalBag
|
|
|
|
*
|
|
|
|
* @author pahimar
|
|
|
|
* @license Lesser GNU Public License v3 (http://www.gnu.org/licenses/lgpl.html)
|
|
|
|
*
|
|
|
|
*/
|
2013-03-07 00:46:19 +01:00
|
|
|
public class ItemAlchemicalBag extends ItemEE {
|
2012-12-01 04:45:54 +01:00
|
|
|
|
2013-03-07 00:46:19 +01:00
|
|
|
private static final String[] ALCHEMICAL_BAG_SUBTYPES = new String[] { "Open", "OpenDrawString", "Closed", "ClosedDrawString" };
|
2013-03-08 04:45:55 +01:00
|
|
|
|
2013-03-07 00:46:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
private Icon[] icons;
|
2013-03-08 04:45:55 +01:00
|
|
|
|
2013-03-07 00:46:19 +01:00
|
|
|
public ItemAlchemicalBag(int id) {
|
2012-12-01 04:45:54 +01:00
|
|
|
|
|
|
|
super(id);
|
2013-03-07 00:46:19 +01:00
|
|
|
this.setUnlocalizedName(Strings.ALCHEMICAL_BAG_NAME);
|
2012-12-01 04:45:54 +01:00
|
|
|
this.setCreativeTab(EquivalentExchange3.tabsEE3);
|
|
|
|
}
|
2013-03-08 04:45:55 +01:00
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
@Override
|
2013-03-07 00:46:19 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-04-11 03:04:31 +02:00
|
|
|
public void registerIcons(IconRegister iconRegister) {
|
2013-03-07 00:46:19 +01:00
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
icons = new Icon[ALCHEMICAL_BAG_SUBTYPES.length];
|
2013-03-08 04:45:55 +01:00
|
|
|
|
2013-03-07 00:46:19 +01:00
|
|
|
for (int i = 0; i < ALCHEMICAL_BAG_SUBTYPES.length; ++i) {
|
2013-03-22 00:44:21 +01:00
|
|
|
icons[i] = iconRegister.registerIcon(Reference.MOD_ID.toLowerCase() + ":" + Strings.ALCHEMICAL_BAG_NAME + ALCHEMICAL_BAG_SUBTYPES[i]);
|
2013-03-07 00:46:19 +01:00
|
|
|
}
|
|
|
|
}
|
2013-03-08 04:45:55 +01:00
|
|
|
|
2013-02-26 22:08:43 +01:00
|
|
|
@Override
|
|
|
|
public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer entityPlayer) {
|
2012-12-01 04:45:54 +01:00
|
|
|
|
2013-02-26 22:08:43 +01:00
|
|
|
if (!world.isRemote) {
|
2013-03-07 00:46:19 +01:00
|
|
|
NBTHelper.setBoolean(itemStack, Strings.NBT_ITEM_ALCHEMICAL_BAG_GUI_OPEN, true);
|
2013-02-26 22:08:43 +01:00
|
|
|
entityPlayer.openGui(EquivalentExchange3.instance, GuiIds.ALCHEMICAL_BAG, entityPlayer.worldObj, (int) entityPlayer.posX, (int) entityPlayer.posY, (int) entityPlayer.posZ);
|
|
|
|
}
|
2012-12-01 04:45:54 +01:00
|
|
|
|
2013-02-26 22:08:43 +01:00
|
|
|
return itemStack;
|
2012-12-01 04:45:54 +01:00
|
|
|
}
|
2013-03-08 04:45:55 +01:00
|
|
|
|
2013-02-26 22:08:43 +01:00
|
|
|
@Override
|
|
|
|
public boolean getShareTag() {
|
2012-12-01 04:45:54 +01:00
|
|
|
|
2013-02-26 22:08:43 +01:00
|
|
|
return true;
|
2012-12-01 04:45:54 +01:00
|
|
|
}
|
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
@Override
|
2012-12-01 04:45:54 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
2013-02-26 22:08:43 +01:00
|
|
|
public boolean requiresMultipleRenderPasses() {
|
2012-12-01 04:45:54 +01:00
|
|
|
|
2013-02-26 22:08:43 +01:00
|
|
|
return true;
|
2012-12-01 04:45:54 +01:00
|
|
|
}
|
|
|
|
|
2013-02-26 22:08:43 +01:00
|
|
|
@Override
|
2013-03-05 04:18:15 +01:00
|
|
|
public Icon getIcon(ItemStack itemStack, int renderPass) {
|
2013-03-08 04:45:55 +01:00
|
|
|
|
|
|
|
// If the bag is open
|
2013-03-07 00:46:19 +01:00
|
|
|
if (NBTHelper.hasTag(itemStack, Strings.NBT_ITEM_ALCHEMICAL_BAG_GUI_OPEN)) {
|
2013-03-08 19:40:59 +01:00
|
|
|
if (renderPass != 1)
|
2013-03-07 00:46:19 +01:00
|
|
|
return icons[0];
|
2013-03-08 19:40:59 +01:00
|
|
|
else
|
2013-03-07 00:46:19 +01:00
|
|
|
return icons[1];
|
2013-02-26 22:08:43 +01:00
|
|
|
}
|
2013-03-05 04:18:15 +01:00
|
|
|
// Else, the bag is closed
|
2013-02-26 22:08:43 +01:00
|
|
|
else {
|
2013-03-08 19:40:59 +01:00
|
|
|
if (renderPass != 1)
|
2013-03-07 00:46:19 +01:00
|
|
|
return icons[2];
|
2013-03-08 19:40:59 +01:00
|
|
|
else
|
2013-03-07 00:46:19 +01:00
|
|
|
return icons[3];
|
2013-02-26 22:08:43 +01:00
|
|
|
}
|
2012-12-01 04:45:54 +01:00
|
|
|
}
|
2013-03-08 04:45:55 +01:00
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
@Override
|
2013-03-08 04:45:55 +01:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
public int getColorFromItemStack(ItemStack itemStack, int renderPass) {
|
|
|
|
|
2013-03-08 19:40:59 +01:00
|
|
|
if (renderPass == 1)
|
2013-03-08 04:45:55 +01:00
|
|
|
return Integer.parseInt(Colours.PURE_WHITE, 16);
|
|
|
|
else {
|
|
|
|
int bagColor = this.getColor(itemStack);
|
|
|
|
|
|
|
|
if (bagColor < 0) {
|
|
|
|
bagColor = Integer.parseInt(Colours.PURE_WHITE, 16);
|
|
|
|
}
|
|
|
|
|
|
|
|
return bagColor;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean hasColor(ItemStack itemStack) {
|
|
|
|
|
2013-05-22 06:08:53 +02:00
|
|
|
return ItemUtil.hasColor(itemStack);
|
2013-03-08 04:45:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getColor(ItemStack itemStack) {
|
|
|
|
|
2013-05-22 06:08:53 +02:00
|
|
|
return ItemUtil.getColor(itemStack);
|
2013-03-08 04:45:55 +01:00
|
|
|
}
|
|
|
|
|
2013-03-08 03:26:42 +01:00
|
|
|
public void setColor(ItemStack itemStack, int color) {
|
2013-03-08 04:45:55 +01:00
|
|
|
|
2013-03-08 03:26:42 +01:00
|
|
|
if (itemStack != null) {
|
2013-03-08 19:40:59 +01:00
|
|
|
if (!(itemStack.getItem() instanceof ItemAlchemicalBag))
|
2013-03-08 03:26:42 +01:00
|
|
|
// TODO Localize
|
|
|
|
throw new UnsupportedOperationException("Can\'t dye non-bags!");
|
|
|
|
else {
|
2013-05-22 06:08:53 +02:00
|
|
|
ItemUtil.setColor(itemStack, color);
|
2013-03-08 03:26:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-08 04:45:55 +01:00
|
|
|
|
|
|
|
public void removeColor(ItemStack itemStack) {
|
|
|
|
|
|
|
|
if (itemStack != null) {
|
|
|
|
|
|
|
|
NBTTagCompound nbtTagCompound = itemStack.getTagCompound();
|
|
|
|
|
|
|
|
if (nbtTagCompound != null) {
|
|
|
|
|
|
|
|
NBTTagCompound displayTagCompound = nbtTagCompound.getCompoundTag(Strings.NBT_ITEM_DISPLAY);
|
|
|
|
|
|
|
|
if (displayTagCompound.hasKey(Strings.NBT_ITEM_COLOR)) {
|
|
|
|
|
|
|
|
displayTagCompound.removeTag(Strings.NBT_ITEM_COLOR);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2013-03-08 03:26:42 +01:00
|
|
|
}
|
2012-12-01 04:45:54 +01:00
|
|
|
}
|