OSDN Git Service

ファイルパス色々変更。
[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 /**
14  * 手榴弾です
15  * @author mozipi,ponkotate
16  */
17 public class EntityAtomsGrenade extends EntityThrowable {
18
19         private float explodeSize;
20         private boolean isExplode;
21         private boolean onFire;
22         private boolean isNuke;
23
24     public EntityAtomsGrenade(World par1World) {
25         super(par1World);
26     }
27
28         public EntityAtomsGrenade(World par1World, EntityLiving par2EntityLiving, boolean par3, boolean par4, boolean par5) {
29                 super(par1World, par2EntityLiving);
30                 this.isExplode = par3;
31                 this.onFire = par4;
32                 this.isNuke = par5;
33         }
34
35         @Override
36         public void onUpdate() {
37                 super.onUpdate();
38         }
39
40         @SuppressWarnings("unchecked")
41         @Override
42         protected void onImpact(MovingObjectPosition par1MovingObjectPosition) {
43
44                 if(isExplode) {
45                         this.explodeSize = 3.0F;
46                 }
47
48                 if(isNuke) {
49                         this.explodeSize = 35.0F;
50                 }
51
52                 if (par1MovingObjectPosition.entityHit != null) {
53                         par1MovingObjectPosition.entityHit.attackEntityFrom(DamageSource.causeThrownDamage(this, this.getThrower()), 2);
54                         par1MovingObjectPosition.entityHit.setFire(5);
55                 }
56
57                 if (!this.worldObj.isRemote && !isNuke) {
58                         this.worldObj.newExplosion((Entity) null, this.posX, this.posY, this.posZ, explodeSize, onFire, true);
59                         this.isDead = 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));
74                                 }
75                         }
76                         this.isDead = true;
77                 }
78         }
79
80 }