OSDN Git Service

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