OSDN Git Service

cf3749df38cdf8f7ca3984aeb5893ce8c2a22d4a
[chemicraft/chemicraft.git] / common / pcc / chemicraft / base / entity / EntityAtomsGrenade.java
1 package pcc.chemicraft.base.entity;
2
3 import java.util.Iterator;
4
5 import net.minecraft.entity.Entity;
6 import net.minecraft.entity.EntityLiving;
7 import net.minecraft.entity.projectile.EntityThrowable;
8 import net.minecraft.potion.PotionEffect;
9 import net.minecraft.util.DamageSource;
10 import net.minecraft.util.MovingObjectPosition;
11 import net.minecraft.world.World;
12
13 public class EntityAtomsGrenade extends EntityThrowable
14 {
15
16         private float explodeSize;
17         private boolean isExplode;
18         private boolean onFire;
19         private boolean isNuke;
20
21         public EntityAtomsGrenade(World par1World, EntityLiving par2EntityLiving, boolean par3, boolean par4, boolean par5) {
22                 super(par1World, par2EntityLiving);
23                 this.isExplode = par3;
24                 this.onFire = par4;
25                 this.isNuke = par5;
26         }
27
28         @Override
29         public void onUpdate(){
30                 super.onUpdate();
31         }
32
33         @SuppressWarnings("unchecked")
34         @Override
35         protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
36         {
37
38                 if(isExplode){
39                         this.explodeSize = 3.0F;
40                 }
41
42                 if(isNuke){
43                         this.explodeSize = 35.0F;
44                 }
45
46                 if (par1MovingObjectPosition.entityHit != null) {
47                         par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.func_85052_h()), 2);
48                         par1MovingObjectPosition.entityHit.setFire(5);
49                 }
50
51                 if (!this.worldObj.isRemote && !isNuke) {
52                         this.worldObj.newExplosion((Entity)null, this.posX, this.posY, this.posZ, explodeSize, onFire, true);
53                         this.isDead = true;
54                 }else if(!this.worldObj.isRemote && isNuke){
55                         this.worldObj.newExplosion((Entity)null, this.posX, this.posY, this.posZ, explodeSize, onFire, true);
56                         Iterator<EntityLiving> itr = this.worldObj.getEntitiesWithinAABB(EntityLiving.class, this.boundingBox.expand(30, 30, 30)).iterator();
57                         while(itr.hasNext()){
58                                 EntityLiving entity = itr.next();
59                                 double dx = Math.abs(entity.posX - this.posX);
60                                 double dy = Math.abs(entity.posY - this.posY);
61                                 double dz = Math.abs(entity.posZ - this.posZ);
62                                 int distance = (int)Math.sqrt( Math.pow(dx, 2) + Math.pow(dy, 2) + Math.pow(dz, 2) );
63                                 if(30 - distance >= 0){
64                                         entity.addPotionEffect(new PotionEffect(2, (60 + (30 - distance)) * 20, (30 - distance) / 5));
65                                         entity.addPotionEffect(new PotionEffect(4, (60 + (30 - distance)) * 20, (30 - distance) / 5));
66                                         entity.addPotionEffect(new PotionEffect(18, (60 + (30 - distance)) * 20, (30 - distance) / 5));
67                                         entity.addPotionEffect(new PotionEffect(19, (60 + (30 - distance)) * 20, (30 - distance) / 5));
68                                 }
69                         }
70                         this.isDead = true;
71                 }
72
73         }
74
75 }