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