OSDN Git Service

ソース参照
[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.client.renderer.texture.IconRegister;
6 import net.minecraft.creativetab.CreativeTabs;
7 import net.minecraft.entity.Entity;
8 import net.minecraft.entity.player.EntityPlayer;
9 import net.minecraft.item.Item;
10 import net.minecraft.item.ItemStack;
11 import net.minecraft.util.Icon;
12 import net.minecraft.world.World;
13 import pcc.chemicraft.ChemiCraft;
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         public 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         {
48                 try {
49                         for(int i=0;i < ChemiCraftAPI.instance().getCompoundHandlerItemName().size();i++){
50                                 if(ChemiCraftAPI.instance().getCompoundsName().getKeyList(par1ItemStack.getItemDamage()).equals(ChemiCraftAPI.instance().getCompoundHandlerItemName().get(i))){
51                                         ChemiCraftAPI.instance().getCompoundHandler().get(i).onItemRightClickHandler(par1ItemStack, par2World, par3EntityPlayer);
52                                 }
53                         }
54                 } catch (IndexOutOfBoundsException e) {
55                         par1ItemStack.stackSize = 0;
56                 }
57                 return par1ItemStack;
58         }
59
60
61
62         @Override
63         public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5){
64                 try {
65                         for(int i=0;i < ChemiCraftAPI.instance().getCompoundHandlerItemName().size();i++){
66                                 if(ChemiCraftAPI.instance().getCompoundsName().getKeyList(par1ItemStack.getItemDamage()).equals(ChemiCraftAPI.instance().getCompoundHandlerItemName().get(i))){
67                                         ChemiCraftAPI.instance().getCompoundHandler().get(i).onUpdateHandler(par1ItemStack, par2World, par3Entity, par4, par5);
68                                 }
69                         }
70                 } catch (IndexOutOfBoundsException e) {
71                         par1ItemStack.stackSize = 0;
72                         par1ItemStack = null;
73                 }
74         }
75
76
77
78         @SuppressWarnings({ "unchecked", "rawtypes" })
79         @SideOnly(Side.CLIENT)
80         @Override
81         public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List){
82                 for(int type = 0; type < ChemiCraftAPI.instance().getCompoundsName().get("en_US").size(); type++) {
83                         par3List.add(new ItemStack(par1, 1, type));
84                 }
85         }
86
87
88
89         @Override
90         @SideOnly(Side.CLIENT)
91         public Icon getIconFromDamage(int par1) {
92                 return this.icons[par1];
93         }
94
95
96
97         @Override
98         public String getUnlocalizedName(ItemStack par1ItemStack){
99                 return super.getUnlocalizedName() + "." + ChemiCraftCore.instance.api.getCompoundsName().get("en_US", par1ItemStack.getItemDamage());
100         }
101
102
103
104         @Override
105         @SideOnly(Side.CLIENT)
106         public void updateIcons(IconRegister par1IconRegister) {
107                 this.icons = new Icon[ChemiCraftCore.instance.api.getCompoundsName().sizeElementsList("en_US")];
108
109                 for (int i = 0; i < ChemiCraftCore.instance.api.getCompoundsName().sizeElementsList("en_US"); i++) {
110                         this.icons[i] = par1IconRegister.registerIcon(ChemiCraft.TEXTURE + "compounds_" + ChemiCraftCore.instance.api.getCompoundsName().get("en_US", i));
111                 }
112         }
113
114 }