OSDN Git Service

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