OSDN Git Service

ad7e9fa599b9155ec45497886c60bcf836530042
[chemicraft/chemicraft.git] / common / chemicraft / entity / EntityAtomGrenade.java
1 package chemicraft.entity;
2
3 import java.util.Iterator;
4
5 import net.minecraft.src.DamageSource;
6 import net.minecraft.src.Entity;
7 import net.minecraft.src.EntityLiving;
8 import net.minecraft.src.EntityThrowable;
9 import net.minecraft.src.MovingObjectPosition;
10 import net.minecraft.src.PotionEffect;
11 import net.minecraft.src.World;
12
13 public class EntityAtomGrenade extends EntityThrowable
14 {
15
16         private float explodeSize;
17         private boolean isExplode;
18         private boolean onFire;
19         private boolean isNuke;
20
21         public EntityAtomGrenade(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         @Override
34         protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
35         {
36
37                 if(isExplode){
38                         this.explodeSize = 3.0F;
39                 }
40
41                 if(isNuke){
42                         this.explodeSize = 20.0F;
43                 }
44
45                 if (par1MovingObjectPosition.entityHit != null) {
46                         par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.thrower), 2);
47                         par1MovingObjectPosition.entityHit.setFire(5);
48                 }
49
50                 if (!this.worldObj.isRemote && !isNuke) {
51                         this.worldObj.newExplosion((Entity)null, this.posX, this.posY, this.posZ, explodeSize, onFire);
52                         this.isDead = true;
53                 }else if(!this.worldObj.isRemote && isNuke){
54                         this.worldObj.newExplosion((Entity)null, this.posX, this.posY, this.posZ, explodeSize, onFire);
55                         Iterator itr = this.worldObj.getEntitiesWithinAABB(EntityLiving.class, this.boundingBox.expand(30, 30, 30)).iterator();
56                         while(itr.hasNext()){
57                                 EntityLiving entity = (EntityLiving) itr.next();
58                                 double dx = Math.abs(entity.posX - this.posX);
59                                 double dy = Math.abs(entity.posY - this.posY);
60                                 double dz = Math.abs(entity.posZ - this.posZ);
61                                 int distance = (int)Math.sqrt( Math.pow(dx, 2) + Math.pow(dy, 2) + Math.pow(dz, 2) );
62                                 if(30 - distance >= 0){
63                                         entity.addPotionEffect(new PotionEffect(2, (60 + (30 - distance)) * 20, (30 - distance) / 5));
64                                         entity.addPotionEffect(new PotionEffect(4, (60 + (30 - distance)) * 20, (30 - distance) / 5));
65                                         entity.addPotionEffect(new PotionEffect(18, (60 + (30 - distance)) * 20, (30 - distance) / 5));
66                                         entity.addPotionEffect(new PotionEffect(19, (60 + (30 - distance)) * 20, (30 - distance) / 5));
67                                 }
68                         }
69                         this.isDead = true;
70                 }
71
72         }
73
74 }