OSDN Git Service

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