OSDN Git Service

修正・変更
[chemicraft/chemicraft.git] / common / pcc / chemicraft / core / item / ItemAtoms.java
1 package pcc.chemicraft.core.item;
2
3 import java.util.List;
4 import java.util.Random;
5
6 import net.minecraft.creativetab.CreativeTabs;
7 import net.minecraft.entity.Entity;
8 import net.minecraft.entity.EntityLiving;
9 import net.minecraft.entity.player.EntityPlayer;
10 import net.minecraft.item.Item;
11 import net.minecraft.item.ItemStack;
12 import net.minecraft.potion.PotionEffect;
13 import net.minecraft.util.DamageSource;
14 import net.minecraft.util.EntityDamageSource;
15 import net.minecraft.world.World;
16 import net.minecraftforge.common.MinecraftForge;
17 import net.minecraftforge.event.entity.player.PlayerDestroyItemEvent;
18 import pcc.chemicraft.ChemiCraft;
19 import pcc.chemicraft.core.ChemiCraftCore;
20 import pcc.chemicraft.util.AtomInfo;
21 import cpw.mods.fml.relauncher.Side;
22 import cpw.mods.fml.relauncher.SideOnly;
23
24 public class ItemAtoms extends Item {
25
26         public ItemAtoms(int par1){
27                 super(par1);
28                 this.maxStackSize = 64;
29                 this.setHasSubtypes(true);
30                 this.setMaxDamage(0);
31                 this.setCreativeTab(ChemiCraftCore.instance.creativeTabChemiCraft);
32         }
33
34
35
36         @Override
37         public void onUpdate(ItemStack par1ItemStack, World par2World, Entity par3Entity, int par4, boolean par5)
38         {
39                 if (AtomInfo.isRI(par1ItemStack.getItemDamage() + 1)){
40                         Random random = new Random();
41                         if (random.nextInt(100) == 0){
42                                 if (par3Entity instanceof EntityLiving){
43                                         EntityLiving entity = (EntityLiving)par3Entity;
44                                         entity.attackEntityFrom(ChemiCraftCore.getRadiationDamageSource(entity), 1);
45                                 }
46                                 if (par3Entity instanceof EntityPlayer){
47                                         EntityPlayer player = (EntityPlayer)par3Entity;
48                                         ItemStack itemstack = new ItemStack(
49                                                         par1ItemStack.itemID,
50                                                         1,
51                                                         par1ItemStack.getItemDamage());
52                                         itemstack.setItemDamage(AtomInfo.collapseUraniumSeries(itemstack.getItemDamage() + 1) - 1);
53                                         player.inventory.addItemStackToInventory(itemstack);
54                                         player.inventory.consumeInventoryItem(par1ItemStack.itemID);
55                                 }
56                         }
57                 }
58         }
59
60
61
62         @SuppressWarnings({ "unchecked", "rawtypes" })
63         @SideOnly(Side.CLIENT)
64         @Override
65         public void getSubItems(int par1, CreativeTabs par2CreativeTabs, List par3List){
66                 for(int type = 0; type < ChemiCraftCore.instance.ATOMSNAME.length; type++)
67                 {
68                         par3List.add(new ItemStack(par1, 1, type));
69                         this.setIconIndex(type);
70                 }
71         }
72
73
74
75         @Override
76         public String getItemNameIS(ItemStack par1ItemStack){
77                 return super.getItemName() + "." + ChemiCraftCore.instance.ATOMSNAME[par1ItemStack.getItemDamage()];
78         }
79
80
81
82         @Override
83         public String getTextureFile(){
84                 return ChemiCraft.ITEM_ATOMS_TEXTURE;
85         }
86
87
88
89         @SideOnly(Side.CLIENT)
90         @Override
91         public int getIconFromDamage(int par1){
92                 return par1;
93         }
94
95 }