mirror of
https://github.com/4jcraft/4jcraft.git
synced 2026-04-24 06:03:37 +00:00
76 lines
2.1 KiB
C++
76 lines
2.1 KiB
C++
#include "FootstepParticle.h"
|
|
|
|
|
|
|
|
#include <cmath>
|
|
|
|
#include "platform/renderer/renderer.h"
|
|
#include "minecraft/client/particle/Particle.h"
|
|
#include "minecraft/client/particle/ParticleEngine.h"
|
|
#include "minecraft/client/renderer/Tesselator.h"
|
|
#include "minecraft/client/renderer/Textures.h"
|
|
#include "minecraft/client/resources/ResourceLocation.h"
|
|
#include "minecraft/world/level/Level.h"
|
|
|
|
ResourceLocation FootstepParticle::FOOTPRINT_LOCATION =
|
|
ResourceLocation(TN_MISC_FOOTSTEP);
|
|
|
|
FootstepParticle::FootstepParticle(Textures* textures, Level* level, double x,
|
|
double y, double z)
|
|
: Particle(level, x, y, z, 0, 0, 0) {
|
|
// 4J added initialisers
|
|
life = 0;
|
|
lifeTime = 0;
|
|
|
|
this->textures = textures;
|
|
xd = yd = zd = 0;
|
|
lifeTime = 200;
|
|
}
|
|
|
|
void FootstepParticle::render(Tesselator* t, float a, float xa, float ya,
|
|
float za, float xa2, float za2) {
|
|
float time = (life + a) / lifeTime;
|
|
time = time * time;
|
|
|
|
float alpha = 2 - time * 2;
|
|
if (alpha > 1) alpha = 1;
|
|
alpha = alpha * 0.2f;
|
|
|
|
glDisable(GL_LIGHTING);
|
|
float r = 2 / 16.0f;
|
|
|
|
float xx = (float)(x - xOff);
|
|
float yy = (float)(y - yOff);
|
|
float zz = (float)(z - zOff);
|
|
|
|
float br =
|
|
level->getBrightness(std::floor(x), std::floor(y), std::floor(z));
|
|
|
|
textures->bindTexture(&FOOTPRINT_LOCATION);
|
|
glEnable(GL_BLEND);
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
t->begin();
|
|
t->color(br, br, br, alpha);
|
|
t->vertexUV((float)(xx - r), (float)(yy), (float)(zz + r), (float)(0),
|
|
(float)(1));
|
|
t->vertexUV((float)(xx + r), (float)(yy), (float)(zz + r), (float)(1),
|
|
(float)(1));
|
|
t->vertexUV((float)(xx + r), (float)(yy), (float)(zz - r), (float)(1),
|
|
(float)(0));
|
|
t->vertexUV((float)(xx - r), (float)(yy), (float)(zz - r), (float)(0),
|
|
(float)(0));
|
|
t->end();
|
|
|
|
glDisable(GL_BLEND);
|
|
glEnable(GL_LIGHTING);
|
|
}
|
|
|
|
void FootstepParticle::tick() {
|
|
life++;
|
|
if (life == lifeTime) remove();
|
|
}
|
|
|
|
int FootstepParticle::getParticleTexture() {
|
|
return ParticleEngine::ENTITY_PARTICLE_TEXTURE;
|
|
} |