1 package chemicraft.entity;
3 import java.util.Iterator;
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;
13 public class EntityAtomsGrenade extends EntityThrowable
16 private float explodeSize;
17 private boolean isExplode;
18 private boolean onFire;
19 private boolean isNuke;
21 public EntityAtomsGrenade(World par1World, EntityLiving par2EntityLiving, boolean par3, boolean par4, boolean par5) {
22 super(par1World, par2EntityLiving);
23 this.isExplode = par3;
29 public void onUpdate(){
33 @SuppressWarnings("unchecked")
35 protected void onImpact(MovingObjectPosition par1MovingObjectPosition)
39 this.explodeSize = 3.0F;
43 this.explodeSize = 20.0F;
46 if (par1MovingObjectPosition.entityHit != null) {
47 par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.func_85052_h()), 2);
48 par1MovingObjectPosition.entityHit.setFire(5);
51 if (!this.worldObj.isRemote && !isNuke) {
52 this.worldObj.createExplosion((Entity)null, this.posX, this.posY, this.posZ, explodeSize, onFire);
54 }else if(!this.worldObj.isRemote && isNuke){
55 this.worldObj.createExplosion((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();
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));