OSDN Git Service

3880c23fd18ae624478f2bd2152ba9b266cdc9e9
[chemicraft/chemicraft.git] / common / pcc / chemicraft / base / entity / EntityDust.java
1 package pcc.chemicraft.base.entity;
2
3 import net.minecraft.entity.Entity;
4 import net.minecraft.nbt.NBTTagCompound;
5 import net.minecraft.util.MathHelper;
6 import net.minecraft.world.World;
7
8 public class EntityDust extends Entity {
9
10         private final float explodeSize = 2.0F;
11         private final short explodeRad = 5;
12         private int delay = 0;
13         private int deadDelay = 20;
14         private float rad = 0;
15
16         public EntityDust(World par1World) {
17                 super(par1World);
18         }
19
20         public EntityDust(World par1World, double par2, double par3, double par4) {
21                 super(par1World);
22                 this.posX = par2;
23                 this.posY = par3;
24                 this.posZ = par4;
25         }
26
27         @Override
28         public void onUpdate() {
29                 super.onUpdate();
30                 this.delay++;
31                 if (this.delay > 100) {
32                         if (this.deadDelay > 0) {
33                                 this.deadDelay--;
34                                 this.rad += 0.5;
35                                 if (this.deadDelay % 4 == 0) {
36                                         this.explode(this.rad, false);
37                                 } else if (this.deadDelay % 6 == 0){
38                                         this.explode(this.rad, true);
39                                 }
40                         } else {
41                                 this.setDead();
42                         }
43                 }
44
45         float var17 = MathHelper.sqrt_double(this.motionX * this.motionX + this.motionZ * this.motionZ);
46         this.rotationYaw = (float)(Math.atan2(this.motionX, this.motionZ) * 180.0D / Math.PI);
47
48         for (this.rotationPitch = (float)(Math.atan2(this.motionY, (double)var17) * 180.0D / Math.PI); this.rotationPitch - this.prevRotationPitch < -180.0F; this.prevRotationPitch -= 360.0F)
49         {
50             ;
51         }
52
53         while (this.rotationPitch - this.prevRotationPitch >= 180.0F)
54         {
55             this.prevRotationPitch += 360.0F;
56         }
57
58         while (this.rotationYaw - this.prevRotationYaw < -180.0F)
59         {
60             this.prevRotationYaw -= 360.0F;
61         }
62
63         while (this.rotationYaw - this.prevRotationYaw >= 180.0F)
64         {
65             this.prevRotationYaw += 360.0F;
66         }
67
68         this.rotationPitch = this.prevRotationPitch + (this.rotationPitch - this.prevRotationPitch) * 0.2F;
69         this.rotationYaw = this.prevRotationYaw + (this.rotationYaw - this.prevRotationYaw) * 0.2F;
70
71         }
72
73         @Override
74         protected void entityInit() {
75
76         }
77
78         @Override
79         public void readEntityFromNBT(NBTTagCompound var1) {
80
81         }
82
83         @Override
84         public void writeEntityToNBT(NBTTagCompound var1) {
85
86         }
87
88         private void explode(double r, boolean b) {
89                 double angle = 0;
90                 double angleY = 0;
91                 for (int i = 0; i < r; i++) {
92                         double y = this.posY - (r/2) + (i * 1F);
93                         double ry = 0;
94                         for (int j = 1; j < r; j++) {
95                                 ry = Math.sin((double) i / r * Math.PI) * 8;
96                                 angle += 360/j;
97                                 double x = this.posX - Math.sin(Math.toRadians(angle)) * ry;
98                                 double z = this.posZ + Math.cos(Math.toRadians(angle)) * ry;
99                                 if (!this.worldObj.isRemote){
100                                         this.worldObj.createExplosion(this, x - 6 + Math.random() * 12, y + 3, z - 6 + Math.random() * 12, this.explodeSize, b);
101                                 }
102                         }
103                 }
104         }
105
106         public int getDelay() {
107                 return this.delay;
108         }
109
110 }