summaryrefslogtreecommitdiff
path: root/src/main/java/jp/plusplus/fbs/particle/EntityTrajectoryFX.java
blob: 2e098f020581d4efe2b1aa6379596b3d4f8adbaa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package jp.plusplus.fbs.particle;

import jp.plusplus.fbs.FBS;
import net.minecraft.block.material.Material;
import net.minecraft.client.particle.EntityFX;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import org.lwjgl.opengl.GL11;

/**
 * Created by nori on 2016/03/11.
 */
public class EntityTrajectoryFX extends EntityFX {
    public double[][] plane=new double[4][3];

    public EntityTrajectoryFX(World world, double x, double y, double z, double mX, double mY, double mZ) {
        super(world, x, y, z, mX, mY, mZ);
        this.motionX = mX;
        this.motionY = mY;
        this.motionZ = mZ;
        this.prevPosX=this.posX = x;
        this.prevPosY=this.posY = y;
        this.prevPosZ=this.posZ = z;
        this.particleScale = 0.2F;
        this.particleRed = this.particleGreen = this.particleBlue =this.particleAlpha= 1.0F;
        this.particleMaxAge = 6;
        this.noClip = true;

        particleTextureIndexX=0;
        particleTextureIndexY=2;

        //FBS.logger.info("spawn");

        double mmsize=Math.sqrt(motionX*motionX+motionY*motionY+motionZ*motionZ);

        float rotYaw=(float)Math.atan2(motionX, motionZ)+(float)Math.PI/2.f;
        float rotPitch=(float)Math.asin(-motionY / mmsize);

        float r=2.25f;
        float minx=-r, maxx=r, miny=-r, maxy=r;
        double[][] t=new double[][]{
                {0,miny,minx},
                {0,maxy,minx},
                {0,maxy,maxx},
                {0,miny,maxx}
        };
        double[][] t2=new double[4][3];

        double cx=MathHelper.cos(rotYaw), sx=MathHelper.sin(rotYaw);
        double cy=MathHelper.cos(rotPitch), sy=MathHelper.sin(rotPitch);

        for(int i=0;i<4;i++){
            t2[i][0]=cy*t[i][0]-sy*t[i][1];
            t2[i][1]=sy*t[i][0]+cy*t[i][1];
            t2[i][2]=t[i][2];
        }
        for(int i=0;i<4;i++){
            plane[i][0]=cx*t2[i][0]+sx*t2[i][2];
            plane[i][1]=t2[i][1];
            plane[i][2]=-sx*t2[i][0]+cx*t2[i][2];
        }


        //this.setParticleTextureIndex(rand.nextInt(26));
    }

    @Override
    public int getBrightnessForRender(float p_70070_1_) {
        return 0xffffff;
    }

    @Override
    public float getBrightness(float p_70013_1_) {

        /*
        float f1 = super.getBrightness(p_70013_1_);
        float f2 = (float) this.particleAge / (float) this.particleMaxAge;
        f2 *= f2;
        f2 *= f2;
        return f1 * (1.0F - f2) + f2;
        */
        return 1.f;
    }

    @Override
    public void onUpdate() {
        this.prevPosX = this.posX;
        this.prevPosY = this.posY;
        this.prevPosZ = this.posZ;

        particleScale=0.2f+1.8f*particleAge/particleMaxAge;

        if (this.particleAge++ >= this.particleMaxAge) {
            this.setDead();
        }
    }

    @Override
    public int getFXLayer() {
        return 2;
    }

    @Override
    public void setParticleTextureIndex(int p_70536_1_) {
        this.particleTextureIndexX = p_70536_1_ % 16;
        this.particleTextureIndexY = p_70536_1_ / 16;
    }

    @Override
    public void renderParticle(Tessellator tessellator, float partialTick, float rotX, float rotXZ, float rotZ, float rotYZ, float rotXY) {
        float f10 = 0.2F * this.particleScale;
        float f6 = particleIcon.getMinU() + (particleTextureIndexX) / 128.f;
        float f7 = f6 + 4f / 128.0f;
        float f8 = particleIcon.getMinV() + (2 * particleTextureIndexY) / 128.f;
        float f9 = f8 + 4f / 128.0f;

        float f11 = (float) (this.prevPosX - interpPosX);
        float f12 = (float) (this.prevPosY - interpPosY);
        float f13 = (float) (this.prevPosZ - interpPosZ);

        tessellator.setColorRGBA_F(this.particleRed, this.particleGreen, this.particleBlue, this.particleAlpha);
        tessellator.addVertexWithUV(f11 + f10 * plane[0][0], f12 + f10 * plane[0][1], f13 + f10 * plane[0][2], f7, f9);
        tessellator.addVertexWithUV(f11 + f10 * plane[1][0], f12 + f10 * plane[1][1], f13 + f10 * plane[1][2], f7, f8);
        tessellator.addVertexWithUV(f11 + f10 * plane[2][0], f12 + f10 * plane[2][1], f13 + f10 * plane[2][2], f6, f8);
        tessellator.addVertexWithUV(f11 + f10 * plane[3][0], f12 + f10 * plane[3][1], f13 + f10 * plane[3][2], f6, f9);
        tessellator.draw();
        tessellator.startDrawingQuads();
        tessellator.addVertexWithUV(f11 + f10 * plane[3][0], f12 + f10 * plane[3][1], f13 + f10 * plane[3][2], f6, f9);
        tessellator.addVertexWithUV(f11 + f10 * plane[2][0], f12 + f10 * plane[2][1], f13 + f10 * plane[2][2], f6, f8);
        tessellator.addVertexWithUV(f11 + f10 * plane[1][0], f12 + f10 * plane[1][1], f13 + f10 * plane[1][2], f7, f8);
        tessellator.addVertexWithUV(f11 + f10 * plane[0][0], f12 + f10 * plane[0][1], f13 + f10 * plane[0][2], f7, f9);
    }

    @Override
    protected void fall(float p_70069_1_) {}

    @Override
    public boolean isWet() {
        return false;
    }

    @Override
    public boolean isInWater()
    {
        return false;
    }

    @Override
    public boolean handleWaterMovement() {
        return false;
    }
}