OSDN Git Service

80db90b34d3d4e587b4cdc39bdb41da74573590a
[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 public class ItemRadiationGun extends Item {
17
18         private short delay;
19
20         public ItemRadiationGun(int par1) {
21                 super(par1);
22                 this.setCreativeTab(ChemiCraftCore.creativeTabChemiCraft);
23                 this.maxStackSize = 1;
24         }
25
26         @Override
27         public String getTextureFile() {
28                 return ChemiCraft.ITEM_TEXTURE;
29         }
30
31         @Override
32         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,
33                         EntityPlayer par3EntityPlayer) {
34
35                 boolean isCreative = par3EntityPlayer.capabilities.isCreativeMode;
36
37                 if (this.delay <= 0) {
38                         if (!isCreative) {
39                                 this.field_00001(par1ItemStack, par2World, par3EntityPlayer);
40                                 if (par3EntityPlayer.inventory.hasItem(ChemiCraftBase.instance.itemRadiationBallet.shiftedIndex)) {
41                                         par3EntityPlayer.inventory.consumeInventoryItem(ChemiCraftBase.instance.itemRadiationBallet.shiftedIndex);
42                                         par2World.playSound(par3EntityPlayer.posX,
43                                                         par3EntityPlayer.posY,
44                                                         par3EntityPlayer.posZ,
45                                                         "mob.endermen.portal",
46                                                         1.0F,
47                                                         1.3F,
48                                                         false);
49
50                                         par2World.playSound(par3EntityPlayer.posX,
51                                                         par3EntityPlayer.posY,
52                                                         par3EntityPlayer.posZ,
53                                                         "ChemiCraft.raditionGun",
54                                                         2.0F,
55                                                         1.3F,
56                                                         false);
57                                         if (!par2World.isRemote) {
58                                                 this.delay = 100;
59                                         }
60                                 }
61                         } else {
62                                 this.field_00001(par1ItemStack, par2World, par3EntityPlayer);
63                                 par2World.playSound(par3EntityPlayer.posX,
64                                                 par3EntityPlayer.posY,
65                                                 par3EntityPlayer.posZ,
66                                                 "mob.endermen.portal",
67                                                 1.0F,
68                                                 1.3F,
69                                                 false);
70
71                                 par2World.playSound(par3EntityPlayer.posX,
72                                                 par3EntityPlayer.posY,
73                                                 par3EntityPlayer.posZ,
74                                                 "ChemiCraft.raditionGun",
75                                                 2.0F,
76                                                 1.3F,
77                                                 false);
78                                 if (!par2World.isRemote) {
79                                         this.delay = 100;
80                                 }
81                         }
82                 }
83
84                 return super.onItemRightClick(par1ItemStack, par2World, par3EntityPlayer);
85         }
86
87         private void field_00001(ItemStack par1ItemStack, World par2World,
88                         EntityPlayer par3EntityPlayer) {
89
90                 ArrayList<Entity> collisions = ChemiCraftCore.instance.mathAuxiliary.getTriangleEntitysByPlayer(par2World,
91                                 par3EntityPlayer.posX,
92                                 par3EntityPlayer.posY,
93                                 par3EntityPlayer.posZ,
94                                 par3EntityPlayer.rotationYaw,
95                                 par3EntityPlayer.rotationPitch,
96                                 30,
97                                 15);
98
99                 for (int i = 0; i < collisions.size(); i++) {
100                         if (collisions.get(i) instanceof EntityLiving && collisions.get(i) != par3EntityPlayer) {
101                                 try {
102                                         EntityLiving entity = (EntityLiving) collisions.get(i);
103                                         entity.attackEntityFrom(DamageSource.causePlayerDamage(par3EntityPlayer), (int) (10 + Math.random() * 11));
104                                 } catch (ClassCastException e) {
105                                         break;
106                                 }
107                         }
108                 }
109
110         }
111
112         @Override
113         public void onUpdate(ItemStack par1ItemStack, World par2World,
114                         Entity par3Entity, int par4, boolean par5) {
115                 if (this.delay > 0 && !par2World.isRemote) {
116                         this.delay--;
117                 }
118         }
119
120
121 }