1 package pcc.chemicraft.base.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;
15 * @author mozipi,ponkotate
17 public class EntityAtomsGrenade extends EntityThrowable {
19 private float explodeSize;
20 private boolean isExplode;
21 private boolean onFire;
22 private boolean isNuke;
24 public EntityAtomsGrenade(World par1World) {
28 public EntityAtomsGrenade(World par1World, EntityLiving par2EntityLiving, boolean par3, boolean par4, boolean par5) {
29 super(par1World, par2EntityLiving);
30 this.isExplode = par3;
36 public void onUpdate() {
40 @SuppressWarnings("unchecked")
42 protected void onImpact(MovingObjectPosition par1MovingObjectPosition) {
45 this.explodeSize = 3.0F;
49 this.explodeSize = 35.0F;
52 if (par1MovingObjectPosition.entityHit != null) {
53 par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.func_85052_h()), 2);
54 par1MovingObjectPosition.entityHit.setFire(5);
57 if (!this.worldObj.isRemote && !isNuke) {
58 this.worldObj.newExplosion((Entity) null, this.posX, this.posY, this.posZ, explodeSize, onFire, true);
60 } else if(!this.worldObj.isRemote && isNuke) {
61 this.worldObj.newExplosion((Entity) null, this.posX, this.posY, this.posZ, explodeSize, onFire, true);
62 Iterator<EntityLiving> itr = this.worldObj.getEntitiesWithinAABB(EntityLiving.class, this.boundingBox.expand(30, 30, 30)).iterator();
63 while(itr.hasNext()) {
64 EntityLiving entity = itr.next();
65 double dx = Math.abs(entity.posX - this.posX);
66 double dy = Math.abs(entity.posY - this.posY);
67 double dz = Math.abs(entity.posZ - this.posZ);
68 int distance = (int) Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2) + Math.pow(dz, 2) );
69 if(30 - distance >= 0) {
70 entity.addPotionEffect(new PotionEffect(2, (60 + (30 - distance)) * 20, (30 - distance) / 5));
71 entity.addPotionEffect(new PotionEffect(4, (60 + (30 - distance)) * 20, (30 - distance) / 5));
72 entity.addPotionEffect(new PotionEffect(18, (60 + (30 - distance)) * 20, (30 - distance) / 5));
73 entity.addPotionEffect(new PotionEffect(19, (60 + (30 - distance)) * 20, (30 - distance) / 5));