OSDN Git Service

tc
[chemicraft/chemicraft.git] / common / pcc / chemicraft / core / item / ItemCompounds.java
1 package pcc.chemicraft.core.item;
2
3 import java.util.List;
4
5 import net.minecraft.creativetab.CreativeTabs;
6 import net.minecraft.entity.Entity;
7 import net.minecraft.entity.player.EntityPlayer;
8 import net.minecraft.item.Item;
9 import net.minecraft.item.ItemStack;
10 import net.minecraft.world.World;
11 import pcc.chemicraft.ChemiCraft;
12 import pcc.chemicraft.core.ChemiCraftAPI;
13 import pcc.chemicraft.core.ChemiCraftCore;
14 import cpw.mods.fml.relauncher.Side;
15 import cpw.mods.fml.relauncher.SideOnly;
16
17 public class ItemCompounds extends Item {
18
19         public ItemCompounds(int par1){
20                 super(par1);
21                 this.setHasSubtypes(true);
22                 this.setMaxDamage(0);
23                 this.setCreativeTab(ChemiCraftCore.instance.creativeTabChemiCraft);
24         }
25
26         @Override
27         public boolean onItemUse(ItemStack par1ItemStack, EntityPlayer par2EntityPlayer, World par3World, int par4, int par5, int par6, int par7, float par8, float par9, float par10) {
28                 try {
29                         for(int i=0;i < ChemiCraftAPI.instance().getCompoundHandlerItemName().size();i++){
30                                 if(ChemiCraftAPI.instance().getCompoundsName().getKeyList(par1ItemStack.getItemDamage()).equals(ChemiCraftAPI.instance().getCompoundHandlerItemName().get(i))){
31                                         return ChemiCraftAPI.instance().getCompoundHandler().get(i).onItemUseHandler(par1ItemStack, par2EntityPlayer, par3World, par4, par5, par6, par7, par8, par9, par10);
32                                 }
33                         }
34                 } catch (IndexOutOfBoundsException e) {
35                         par1ItemStack.stackSize = 0;
36                 }
37                 return false;
38         }
39
40
41         @Override
42         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World, EntityPlayer par3EntityPlayer)
43         {
44                 try {
45                         for(int i=0;i < ChemiCraftAPI.instance().getCompoundHandlerItemName().size();i++){
46                                 if(ChemiCraftAPI.instance().getCompoundsName().getKeyList(par1ItemStack.getItemDamage()).equals(ChemiCraftAPI.instance().getCompoundHandlerItemName().get(i))){
47                                         ChemiCraftAPI.instance().getCompoundHandler().get(i).onItemRightClickHandler(par1ItemStack, par2World, par3EntityPlayer);
48                                 }
49                         }
50                 } catch (IndexOutOfBoundsException e) {
51                         par1ItemStack.stackSize = 0;
52                 }
53                 return par1ItemStack;
54         }
55
56
57
58         @Override
59         public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5){
60                 try {
61                         for(int i=0;i < ChemiCraftAPI.instance().getCompoundHandlerItemName().size();i++){
62                                 if(ChemiCraftAPI.instance().getCompoundsName().getKeyList(par1ItemStack.getItemDamage()).equals(ChemiCraftAPI.instance().getCompoundHandlerItemName().get(i))){
63                                         ChemiCraftAPI.instance().getCompoundHandler().get(i).onUpdateHandler(par1ItemStack, par2World, par3Entity, par4, par5);
64                                 }
65                         }
66                 } catch (IndexOutOfBoundsException e) {
67                         par1ItemStack.stackSize = 0;
68                         par1ItemStack = null;
69                 }
70         }
71
72
73
74         @SuppressWarnings({ "unchecked", "rawtypes" })
75         @SideOnly(Side.CLIENT)
76         @Override
77         public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List){
78                 for(int type = 0; type < ChemiCraftAPI.instance().getCompoundsName().get("en_US").size(); type++)
79                 {
80                         par3List.add(new ItemStack(par1, 1, type));
81                         this.setIconIndex(type);
82                 }
83         }
84
85
86
87         @Override
88         public String getItemNameIS(ItemStack par1ItemStack){
89                 try {
90                         return super.getItemName() + "." + ChemiCraftAPI.instance().getCompoundsName().get("en_US", par1ItemStack.getItemDamage());
91                 } catch (ArrayIndexOutOfBoundsException e) {
92                         par1ItemStack.stackSize = 0;
93                 }
94                 return null;
95         }
96
97
98
99         @Override
100         public String getTextureFile(){
101                 return ChemiCraft.ITEM_COMPOUNDS_TEXTURE;
102         }
103
104
105
106         @SideOnly(Side.CLIENT)
107         @Override
108         public int getIconFromDamage(int par1){
109                 try {
110                         for(int i=0;i < ChemiCraftAPI.instance().getCompoundHandlerItemName().size();i++){
111                                 if(ChemiCraftAPI.instance().getCompoundsName().getKeyList(par1).equals(ChemiCraftAPI.instance().getCompoundHandlerItemName().get(i))){
112                                         return ChemiCraftAPI.instance().getCompoundHandler().get(i).getIconIndexHandler();
113                                 }
114                         }
115                 } catch (IndexOutOfBoundsException e) {
116                         return 0;
117                 }
118                 return 0;
119         }
120
121 }