OSDN Git Service

パッケージ変更
[chemicraft/ChemiCraftNext.git] / src / asia / tcrs / ccnp / chemicraftnext / base / item / ItemRadiationGun.java
1 package asia.tcrs.ccnp.chemicraftnext.base.item;
2
3 import java.util.ArrayList;
4
5 import asia.tcrs.ccnp.chemicraftnext.ChemiCraft;
6 import asia.tcrs.ccnp.chemicraftnext.base.ChemiCraftBase;
7 import asia.tcrs.ccnp.chemicraftnext.core.ChemiCraftCore;
8
9 import cpw.mods.fml.relauncher.Side;
10 import cpw.mods.fml.relauncher.SideOnly;
11
12 import net.minecraft.client.renderer.texture.IconRegister;
13 import net.minecraft.entity.Entity;
14 import net.minecraft.entity.EntityLiving;
15 import net.minecraft.entity.player.EntityPlayer;
16 import net.minecraft.item.Item;
17 import net.minecraft.item.ItemStack;
18 import net.minecraft.util.DamageSource;
19 import net.minecraft.world.World;
20
21 /**
22  * 放射線銃です
23  * @author mozipi
24  */
25 public class ItemRadiationGun extends Item {
26
27         /**
28          * 次の発射までの遅延
29          */
30         private short delay;
31
32         public ItemRadiationGun(int par1) {
33                 super(par1);
34                 this.setCreativeTab(ChemiCraftCore.creativeTabChemiCraft);
35                 this.maxStackSize = 1;
36         }
37
38         @Override
39         @SideOnly(Side.CLIENT)
40     public void registerIcons(IconRegister par1IconRegister){
41                 this.itemIcon = par1IconRegister.registerIcon(ChemiCraft.TEXTURE + "radiation_gun");
42         }
43
44         @Override
45         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,
46                         EntityPlayer par3EntityPlayer) {
47
48                 boolean isCreative = par3EntityPlayer.capabilities.isCreativeMode;
49
50                 if (this.delay <= 0) {
51                         if (!isCreative) {
52                                 this.field_00001(par1ItemStack, par2World, par3EntityPlayer);
53                                 if (par3EntityPlayer.inventory.hasItem(ChemiCraftBase.instance.itemRadiationBallet.itemID)) {
54                                         par3EntityPlayer.inventory.consumeInventoryItem(ChemiCraftBase.instance.itemRadiationBallet.itemID);
55                                         par2World.playSound(par3EntityPlayer.posX,
56                                                         par3EntityPlayer.posY,
57                                                         par3EntityPlayer.posZ,
58                                                         "mob.endermen.portal",
59                                                         1.0F,
60                                                         1.3F,
61                                                         false);
62
63                                         par2World.playSound(par3EntityPlayer.posX,
64                                                         par3EntityPlayer.posY,
65                                                         par3EntityPlayer.posZ,
66                                                         "ChemiCraft.raditionGun",
67                                                         2.0F,
68                                                         1.3F,
69                                                         false);
70                                         if (!par2World.isRemote) {
71                                                 this.delay = 100;
72                                         }
73                                 }
74                         } else {
75                                 this.field_00001(par1ItemStack, par2World, par3EntityPlayer);
76                                 par2World.playSound(par3EntityPlayer.posX,
77                                                 par3EntityPlayer.posY,
78                                                 par3EntityPlayer.posZ,
79                                                 "mob.endermen.portal",
80                                                 1.0F,
81                                                 1.3F,
82                                                 false);
83
84                                 par2World.playSound(par3EntityPlayer.posX,
85                                                 par3EntityPlayer.posY,
86                                                 par3EntityPlayer.posZ,
87                                                 "ChemiCraft.raditionGun",
88                                                 2.0F,
89                                                 1.3F,
90                                                 false);
91                                 if (!par2World.isRemote) {
92                                         this.delay = 100;
93                                 }
94                         }
95                 }
96
97                 return super.onItemRightClick(par1ItemStack, par2World, par3EntityPlayer);
98         }
99
100         private void field_00001(ItemStack par1ItemStack, World par2World,
101                         EntityPlayer par3EntityPlayer) {
102
103                 ArrayList<Entity> collisions = ChemiCraftCore.instance.mathAuxiliary.getTriangleEntitysByPlayer(par2World,
104                                 par3EntityPlayer.posX,
105                                 par3EntityPlayer.posY,
106                                 par3EntityPlayer.posZ,
107                                 par3EntityPlayer.rotationYaw,
108                                 par3EntityPlayer.rotationPitch,
109                                 30,
110                                 15);
111
112                 for (int i = 0; i < collisions.size(); i++) {
113                         if (collisions.get(i) instanceof EntityLiving && collisions.get(i) != par3EntityPlayer) {
114                                 try {
115                                         EntityLiving entity = (EntityLiving) collisions.get(i);
116                                         entity.attackEntityFrom(DamageSource.causePlayerDamage(par3EntityPlayer), (int) (10 + Math.random() * 11));
117                                 } catch (ClassCastException e) {
118                                         break;
119                                 }
120                         }
121                 }
122
123         }
124
125         @Override
126         public void onUpdate(ItemStack par1ItemStack, World par2World,
127                         Entity par3Entity, int par4, boolean par5) {
128                 if (this.delay > 0 && !par2World.isRemote) {
129                         this.delay--;
130                 }
131         }
132
133
134 }