OSDN Git Service

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