OSDN Git Service

0d202ea93cbde5be9a55d4dddbfcd9b4afcaf43f
[chemicraft/chemicraft.git] / common / pcc / chemicraft / item / ItemRadiationGun.java
1 package pcc.chemicraft.item;
2
3 import java.util.Iterator;
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.potion.Potion;
11 import net.minecraft.potion.PotionEffect;
12 import net.minecraft.util.AxisAlignedBB;
13 import net.minecraft.util.DamageSource;
14 import net.minecraft.world.World;
15 import pcc.chemicraft.ChemiCraft;
16
17 public class ItemRadiationGun extends Item {
18
19         private short delay;
20
21         public ItemRadiationGun(int par1) {
22                 super(par1);
23                 this.setCreativeTab(ChemiCraft.creativeTabChemiCraft);
24                 this.maxStackSize = 1;
25         }
26
27         @Override
28         public String getTextureFile() {
29                 return ChemiCraft.instance.ITEM_TEXTURE;
30         }
31
32         @Override
33         public ItemStack onItemRightClick(ItemStack par1ItemStack, World par2World,
34                         EntityPlayer par3EntityPlayer) {
35
36                 boolean isCreative = par3EntityPlayer.capabilities.isCreativeMode;
37
38                 if (this.delay <= 0) {
39                         if (isCreative) {
40                                 if (par3EntityPlayer.inventory.hasItem(ChemiCraft.instance.itemRadiationBallet.shiftedIndex)) {
41                                         this.field_00001(par1ItemStack, par2World, par3EntityPlayer);
42                                         par3EntityPlayer.inventory.consumeInventoryItem(ChemiCraft.instance.itemRadiationBallet.shiftedIndex);
43                                         par2World.playSound(par3EntityPlayer.posX,
44                                                         par3EntityPlayer.posY,
45                                                         par3EntityPlayer.posZ,
46                                                         "mob.endermen.portal",
47                                                         1.0F,
48                                                         1.3F,
49                                                         false);
50                                         if (!par2World.isRemote) {
51                                                 this.delay = 100;
52                                         }
53                                 } else {
54                                         this.field_00001(par1ItemStack, par2World, par3EntityPlayer);
55                                         par2World.playSound(par3EntityPlayer.posX,
56                                                         par3EntityPlayer.posY,
57                                                         par3EntityPlayer.posZ,
58                                                         "mob.endermen.portal",
59                                                         1.0F,
60                                                         1.3F,
61                                                         false);
62                                         if (!par2World.isRemote) {
63                                                 this.delay = 100;
64                                         }
65                                 }
66                         }
67                 }
68
69                 return super.onItemRightClick(par1ItemStack, par2World, par3EntityPlayer);
70         }
71
72         private void field_00001(ItemStack par1ItemStack, World par2World,
73                         EntityPlayer par3EntityPlayer) {
74                 int distance = 0;
75                 double minX = par3EntityPlayer.posX;
76                 double minZ = par3EntityPlayer.posZ;
77                 double maxX = par3EntityPlayer.posX - Math.sin(Math.toRadians(par3EntityPlayer.rotationYaw)) * 20;
78                 double maxZ = par3EntityPlayer.posZ + Math.cos(Math.toRadians(par3EntityPlayer.rotationYaw)) * 20;
79                 double posY = par3EntityPlayer.posY;
80                 for(distance = 0;distance < Math.abs(((minX-maxX) + (minZ-maxZ))) / 2;distance++){
81                         AxisAlignedBB aabb = AxisAlignedBB.getBoundingBox(
82                                         minX + -Math.sin(Math.toRadians(par3EntityPlayer.rotationYaw)) * distance,
83                                         posY + 1,
84                                         minZ + Math.cos(Math.toRadians(par3EntityPlayer.rotationYaw)) * distance,
85                                         minX + -Math.sin(Math.toRadians(par3EntityPlayer.rotationYaw)) * distance,
86                                         posY + 1,
87                                         minZ + Math.cos(Math.toRadians(par3EntityPlayer.rotationYaw)) * distance
88                                         ).expand(1.5, 3, 1.5);
89
90                         Iterator itr = par2World.getEntitiesWithinAABB(EntityLiving.class, aabb).iterator();
91                         while(itr.hasNext()){
92                                 EntityLiving entity = (EntityLiving) itr.next();
93                                 if(entity != par3EntityPlayer){
94                                         entity.attackEntityFrom(DamageSource.causePlayerDamage(par3EntityPlayer), 10);
95                                         entity.attackEntityFrom(DamageSource.causePlayerDamage(par3EntityPlayer), (int) (10 + Math.random() * 11));
96                                         entity.addPotionEffect(new PotionEffect(Potion.moveSlowdown.getId(), 1, 20*20));
97                                         entity.addPotionEffect(new PotionEffect(Potion.weakness.getId(), 1, 20*20));
98                                 }
99                         }
100                 }
101         }
102
103         @Override
104         public void onUpdate(ItemStack par1ItemStack, World par2World,
105                         Entity par3Entity, int par4, boolean par5) {
106                 if (this.delay > 0 && !par2World.isRemote) {
107                         this.delay--;
108                 }
109         }
110
111
112 }