aboutsummaryrefslogtreecommitdiff
path: root/Minecraft.Client/FlameParticle.cpp
blob: a242f714772331102262a778e16a16b03434ec34 (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
#include "stdafx.h"
#include "..\Minecraft.World\JavaMath.h"
#include "..\Minecraft.World\Random.h"
#include "FlameParticle.h"

FlameParticle::FlameParticle(Level *level, double x, double y, double z, double xd, double yd, double zd) : Particle(level, x, y, z, xd, yd, zd)
{
    this->xd=this->xd*0.01f+xd;
    this->yd=this->yd*0.01f+yd;
    this->zd=this->zd*0.01f+zd;
    x+=(random->nextFloat()-random->nextFloat())*0.05f;
    y+=(random->nextFloat()-random->nextFloat())*0.05f;
    z+=(random->nextFloat()-random->nextFloat())*0.05f;
        
    oSize = size;
    rCol = gCol = bCol = 1.0f;
        
    lifetime = static_cast<int>(8 / (Math::random() * 0.8 + 0.2))+4;
    noPhysics = true;
    setMiscTex(48);
}

void FlameParticle::render(Tesselator *t, float a, float xa, float ya, float za, float xa2, float za2)
{
    float s = (age + a) / static_cast<float>(lifetime);
    size = oSize * (1 - s*s*0.5f);
    Particle::render(t, a, xa, ya, za, xa2, za2);
}

// 4J - brought forward from 1.8.2
int FlameParticle::getLightColor(float a)
{
    float l = (age + a) / lifetime;
    if (l < 0) l = 0;
    if (l > 1) l = 1;
    int br = Particle::getLightColor(a);

    int br1 = (br) & 0xff;
    int br2 = (br >> 16) & 0xff;
    br1 += static_cast<int>(l * 15 * 16);
    if (br1 > 15 * 16) br1 = 15 * 16;
    return br1 | br2 << 16;
}

float FlameParticle::getBrightness(float a)
{
	float l = (age+a)/lifetime;
	if (l<0) l = 0;
	if (l>1) l = 1;
	float br = Particle::getBrightness(a);
        
	return br*l+(1-l);
}

void FlameParticle::tick()
{
    xo = x;
    yo = y;
    zo = z;

    if (age++ >= lifetime) remove();

    move(xd, yd, zd);
    xd *= 0.96f;
    yd *= 0.96f;
    zd *= 0.96f;

    if (onGround)
    {
        xd *= 0.7f;
        zd *= 0.7f;
    }
}