OSDN Git Service

e68b8a2714048e74b217c0392e24972c6e5eefb1
[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         @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 = 20.0F;
44                 }
45
46                 if (par1MovingObjectPosition.entityHit != null) {
47                         par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.thrower), 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);
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);
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 }