generated from MrSphay/codex-agent-repository-kit
This commit is contained in:
@@ -0,0 +1,346 @@
|
||||
/*
|
||||
* Decompiled with CFR 0.152.
|
||||
*/
|
||||
package com.vinlanx.explosionoverhaul.client;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.mojang.blaze3d.vertex.BufferBuilder;
|
||||
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
|
||||
import com.mojang.blaze3d.vertex.Tesselator;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.blaze3d.vertex.VertexFormat;
|
||||
import com.vinlanx.explosionoverhaul.Config;
|
||||
import com.vinlanx.explosionoverhaul.CustomGlowParticleOptions;
|
||||
import com.vinlanx.explosionoverhaul.client.ExplosionTextureManager;
|
||||
import com.vinlanx.explosionoverhaul.client.ExplosionWindController;
|
||||
import net.minecraft.client.Camera;
|
||||
import net.minecraft.client.multiplayer.ClientLevel;
|
||||
import net.minecraft.client.particle.ParticleRenderType;
|
||||
import net.minecraft.client.particle.TextureSheetParticle;
|
||||
import net.minecraft.client.renderer.GameRenderer;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import org.joml.Quaternionf;
|
||||
import org.joml.Quaternionfc;
|
||||
import org.joml.Vector3f;
|
||||
|
||||
public class CustomGlowParticle
|
||||
extends TextureSheetParticle {
|
||||
private final float power;
|
||||
private final float initialQuadSize;
|
||||
private final int animationDuration;
|
||||
private final int animationType;
|
||||
private final float centerY;
|
||||
private final float maxRadius;
|
||||
private float currentHeightPercent;
|
||||
private final int peakFireEndTick;
|
||||
private final int fireTransitionEndTick;
|
||||
private final int smokeStartTick;
|
||||
private static final int GLOW_FRAME_COUNT = 239;
|
||||
private static final int SGLOW_FRAME_COUNT = 224;
|
||||
private static final int FRAMES_PER_SHEET = 64;
|
||||
private static final int FRAMES_PER_ROW = 8;
|
||||
private int baseSheetIndex;
|
||||
private int baseFrameOnSheet;
|
||||
private int emissiveSheetIndex;
|
||||
private int emissiveFrameOnSheet;
|
||||
|
||||
public CustomGlowParticle(ClientLevel pLevel, double pX, double pY, double pZ, double pXSpeed, double pYSpeed, double pZSpeed, CustomGlowParticleOptions options) {
|
||||
super(pLevel, pX, pY, pZ, pXSpeed, pYSpeed, pZSpeed);
|
||||
int fadeOutDurationTicks;
|
||||
this.f_172258_ = 0.98f;
|
||||
this.f_107226_ = 0.0f;
|
||||
this.f_107215_ = pXSpeed;
|
||||
this.f_107216_ = pYSpeed;
|
||||
this.f_107217_ = pZSpeed;
|
||||
this.power = options.getPower();
|
||||
this.initialQuadSize = options.getScale();
|
||||
this.animationType = options.getAnimationType();
|
||||
this.f_107663_ = this.initialQuadSize;
|
||||
this.centerY = options.getCenterY();
|
||||
this.maxRadius = options.getMaxRadius();
|
||||
this.currentHeightPercent = options.getHeightPercent();
|
||||
if (this.power <= 1.0f) {
|
||||
this.animationDuration = 40;
|
||||
fadeOutDurationTicks = 40;
|
||||
} else if (this.power <= 10.0f) {
|
||||
this.animationDuration = this.interpolate(this.power, 1.0f, 40.0f, 10.0f, 100.0f);
|
||||
fadeOutDurationTicks = this.interpolate(this.power, 1.0f, 40.0f, 10.0f, 60.0f);
|
||||
} else if (this.power <= 60.0f) {
|
||||
this.animationDuration = this.interpolate(this.power, 10.0f, 100.0f, 60.0f, 140.0f);
|
||||
fadeOutDurationTicks = this.interpolate(this.power, 10.0f, 60.0f, 60.0f, 80.0f);
|
||||
} else if (this.power <= 100.0f) {
|
||||
this.animationDuration = this.interpolate(this.power, 60.0f, 140.0f, 100.0f, 200.0f);
|
||||
fadeOutDurationTicks = this.interpolate(this.power, 60.0f, 80.0f, 100.0f, 120.0f);
|
||||
} else {
|
||||
this.animationDuration = 200;
|
||||
fadeOutDurationTicks = 120;
|
||||
}
|
||||
this.f_107225_ = this.animationDuration + fadeOutDurationTicks;
|
||||
float powerFraction = Mth.m_14036_((float)(this.power / 100.0f), (float)0.0f, (float)1.0f);
|
||||
float totalFirePercent = Mth.m_14179_((float)powerFraction, (float)0.02f, (float)0.2f);
|
||||
float cooldownToSmokePercent = Mth.m_14179_((float)powerFraction, (float)0.04f, (float)0.08f);
|
||||
int totalFireDuration = (int)((float)this.f_107225_ * totalFirePercent);
|
||||
this.peakFireEndTick = (int)((float)totalFireDuration * 0.9f);
|
||||
this.fireTransitionEndTick = totalFireDuration;
|
||||
int cooldownDuration = (int)((float)this.f_107225_ * cooldownToSmokePercent);
|
||||
this.smokeStartTick = this.fireTransitionEndTick + cooldownDuration;
|
||||
if (Config.CLIENT.particleRenderMode.get() == Config.Client.ParticleRenderMode.VANILA) {
|
||||
this.f_107230_ = 1.0f;
|
||||
this.f_107227_ = 1.0f;
|
||||
this.f_107228_ = 0.85f;
|
||||
this.f_107229_ = 0.5f;
|
||||
}
|
||||
}
|
||||
|
||||
public void m_5989_() {
|
||||
double targetSpeed;
|
||||
this.f_107209_ = this.f_107212_;
|
||||
this.f_107210_ = this.f_107213_;
|
||||
this.f_107211_ = this.f_107214_;
|
||||
if (this.f_107224_++ >= this.f_107225_) {
|
||||
this.m_107274_();
|
||||
return;
|
||||
}
|
||||
if (Config.CLIENT.particleRenderMode.get() == Config.Client.ParticleRenderMode.VANILA) {
|
||||
this.tickVanila();
|
||||
} else if (Config.CLIENT.particleRenderMode.get() == Config.Client.ParticleRenderMode.REALISTIC_2) {
|
||||
this.tickRealistic2();
|
||||
} else {
|
||||
this.tickRealistic();
|
||||
}
|
||||
this.m_6257_(this.f_107215_, this.f_107216_, this.f_107217_);
|
||||
this.f_107215_ *= (double)this.f_172258_;
|
||||
this.f_107216_ *= (double)this.f_172258_;
|
||||
this.f_107217_ *= (double)this.f_172258_;
|
||||
float heightPercent = this.updateHeightPercent();
|
||||
Vec3 direction = ExplosionWindController.getWindDirection();
|
||||
if (direction != Vec3.f_82478_ && (targetSpeed = ExplosionWindController.computeGlowSpeed(heightPercent)) > 0.0) {
|
||||
double targetX = direction.f_82479_ * targetSpeed;
|
||||
double targetZ = direction.f_82481_ * targetSpeed;
|
||||
this.f_107215_ += (targetX - this.f_107215_) * 0.1;
|
||||
this.f_107217_ += (targetZ - this.f_107217_) * 0.1;
|
||||
}
|
||||
}
|
||||
|
||||
private void tickVanila() {
|
||||
this.baseSheetIndex = 0;
|
||||
this.f_107663_ = this.initialQuadSize;
|
||||
if (this.f_107224_ < this.peakFireEndTick) {
|
||||
this.f_107230_ = 1.0f;
|
||||
this.f_107227_ = 1.0f;
|
||||
this.f_107228_ = 0.85f;
|
||||
this.f_107229_ = 0.5f;
|
||||
} else if (this.f_107224_ < this.fireTransitionEndTick) {
|
||||
float progress = (float)(this.f_107224_ - this.peakFireEndTick) / (float)(this.fireTransitionEndTick - this.peakFireEndTick);
|
||||
this.f_107230_ = 1.0f;
|
||||
this.f_107227_ = 1.0f;
|
||||
this.f_107228_ = Mth.m_14179_((float)progress, (float)0.85f, (float)0.5f);
|
||||
this.f_107229_ = Mth.m_14179_((float)progress, (float)0.5f, (float)0.1f);
|
||||
} else if (this.f_107224_ < this.smokeStartTick) {
|
||||
float progress = (float)(this.f_107224_ - this.fireTransitionEndTick) / (float)(this.smokeStartTick - this.fireTransitionEndTick);
|
||||
float smokeCol = 0.15f;
|
||||
this.f_107227_ = Mth.m_14179_((float)progress, (float)1.0f, (float)(smokeCol + 0.1f));
|
||||
this.f_107228_ = Mth.m_14179_((float)progress, (float)0.5f, (float)smokeCol);
|
||||
this.f_107229_ = Mth.m_14179_((float)progress, (float)0.1f, (float)smokeCol);
|
||||
this.f_107230_ = Mth.m_14179_((float)progress, (float)1.0f, (float)0.9f);
|
||||
} else {
|
||||
float progress = (float)(this.f_107224_ - this.smokeStartTick) / (float)(this.f_107225_ - this.smokeStartTick);
|
||||
float finalSmokeCol = 0.05f;
|
||||
this.f_107228_ = this.f_107229_ = Mth.m_14179_((float)progress, (float)0.15f, (float)finalSmokeCol);
|
||||
this.f_107227_ = this.f_107229_;
|
||||
this.f_107230_ = 0.9f * (1.0f - progress * progress * progress);
|
||||
}
|
||||
}
|
||||
|
||||
private void tickRealistic2() {
|
||||
int frameIndex;
|
||||
int emissiveSheetStart;
|
||||
int baseSheetStart;
|
||||
int frameCountForAnim;
|
||||
this.f_107663_ = this.initialQuadSize * 2.0f;
|
||||
if (this.animationType == 2) {
|
||||
frameCountForAnim = 224;
|
||||
baseSheetStart = 18;
|
||||
emissiveSheetStart = 22;
|
||||
} else if (this.animationType == 1) {
|
||||
frameCountForAnim = 239;
|
||||
baseSheetStart = 10;
|
||||
emissiveSheetStart = 14;
|
||||
} else {
|
||||
frameCountForAnim = 239;
|
||||
baseSheetStart = 2;
|
||||
emissiveSheetStart = 6;
|
||||
}
|
||||
if (this.f_107224_ < this.animationDuration) {
|
||||
float animProgress = (float)this.f_107224_ / (float)this.animationDuration;
|
||||
float easedProgress = 1.0f - (float)Math.pow(1.0f - animProgress, 3.0);
|
||||
frameIndex = (int)(easedProgress * (float)(frameCountForAnim - 1));
|
||||
this.f_107230_ = 1.0f;
|
||||
} else {
|
||||
frameIndex = frameCountForAnim - 1;
|
||||
int fadeDuration = this.f_107225_ - this.animationDuration;
|
||||
int ageInFade = this.f_107224_ - this.animationDuration;
|
||||
this.f_107230_ = 1.0f - (float)ageInFade / (float)fadeDuration;
|
||||
}
|
||||
frameIndex = Mth.m_14045_((int)frameIndex, (int)0, (int)(frameCountForAnim - 1));
|
||||
this.baseSheetIndex = baseSheetStart + frameIndex / 64;
|
||||
this.baseFrameOnSheet = frameIndex % 64;
|
||||
this.emissiveSheetIndex = emissiveSheetStart + frameIndex / 64;
|
||||
this.emissiveFrameOnSheet = frameIndex % 64;
|
||||
}
|
||||
|
||||
private void tickRealistic() {
|
||||
int frameIndex;
|
||||
int emissiveSheetStart;
|
||||
int baseSheetStart;
|
||||
int frameCountForAnim;
|
||||
if (this.animationType == 2) {
|
||||
frameCountForAnim = 224;
|
||||
baseSheetStart = 18;
|
||||
emissiveSheetStart = 22;
|
||||
} else if (this.animationType == 1) {
|
||||
frameCountForAnim = 239;
|
||||
baseSheetStart = 10;
|
||||
emissiveSheetStart = 14;
|
||||
} else {
|
||||
frameCountForAnim = 239;
|
||||
baseSheetStart = 2;
|
||||
emissiveSheetStart = 6;
|
||||
}
|
||||
if (this.f_107224_ < this.animationDuration) {
|
||||
float animProgress = (float)this.f_107224_ / (float)this.animationDuration;
|
||||
float easedProgress = 1.0f - (float)Math.pow(1.0f - animProgress, 3.0);
|
||||
frameIndex = (int)(easedProgress * (float)(frameCountForAnim - 1));
|
||||
this.f_107230_ = 1.0f;
|
||||
} else {
|
||||
frameIndex = frameCountForAnim - 1;
|
||||
int fadeDuration = this.f_107225_ - this.animationDuration;
|
||||
int ageInFade = this.f_107224_ - this.animationDuration;
|
||||
this.f_107230_ = 1.0f - (float)ageInFade / (float)fadeDuration;
|
||||
}
|
||||
frameIndex = Mth.m_14045_((int)frameIndex, (int)0, (int)(frameCountForAnim - 1));
|
||||
this.baseSheetIndex = baseSheetStart + frameIndex / 64;
|
||||
this.baseFrameOnSheet = frameIndex % 64;
|
||||
this.emissiveSheetIndex = emissiveSheetStart + frameIndex / 64;
|
||||
this.emissiveFrameOnSheet = frameIndex % 64;
|
||||
}
|
||||
|
||||
public void m_5744_(VertexConsumer pBuffer, Camera pRenderInfo, float pPartialTicks) {
|
||||
Vector3f[] avector3f;
|
||||
Vec3 vec3 = pRenderInfo.m_90583_();
|
||||
float f = (float)(Mth.m_14139_((double)pPartialTicks, (double)this.f_107209_, (double)this.f_107212_) - vec3.m_7096_());
|
||||
float f1 = (float)(Mth.m_14139_((double)pPartialTicks, (double)this.f_107210_, (double)this.f_107213_) - vec3.m_7098_());
|
||||
float f2 = (float)(Mth.m_14139_((double)pPartialTicks, (double)this.f_107211_, (double)this.f_107214_) - vec3.m_7094_());
|
||||
Quaternionf quaternion = new Quaternionf((Quaternionfc)pRenderInfo.m_253121_());
|
||||
if (this.f_107231_ != 0.0f) {
|
||||
float f3 = Mth.m_14179_((float)pPartialTicks, (float)this.f_107204_, (float)this.f_107231_);
|
||||
quaternion.rotateZ(f3);
|
||||
}
|
||||
if (this.animationType == 2) {
|
||||
float aspectRatio = 0.5629139f;
|
||||
avector3f = new Vector3f[]{new Vector3f(-0.5629139f, -1.0f, 0.0f), new Vector3f(-0.5629139f, 1.0f, 0.0f), new Vector3f(0.5629139f, 1.0f, 0.0f), new Vector3f(0.5629139f, -1.0f, 0.0f)};
|
||||
} else {
|
||||
avector3f = new Vector3f[]{new Vector3f(-1.0f, -1.0f, 0.0f), new Vector3f(-1.0f, 1.0f, 0.0f), new Vector3f(1.0f, 1.0f, 0.0f), new Vector3f(1.0f, -1.0f, 0.0f)};
|
||||
}
|
||||
float f4 = this.m_5902_(pPartialTicks);
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
Vector3f vector3f = avector3f[i];
|
||||
vector3f.rotate((Quaternionfc)quaternion);
|
||||
vector3f.mul(f4);
|
||||
vector3f.add(f, f1, f2);
|
||||
}
|
||||
int worldLight = this.m_6355_(pPartialTicks);
|
||||
int frameToRender = Config.CLIENT.particleRenderMode.get() == Config.Client.ParticleRenderMode.VANILA ? 0 : this.baseFrameOnSheet;
|
||||
ResourceLocation baseTexture = ExplosionTextureManager.getInstance().getTexture(this.baseSheetIndex);
|
||||
this.renderFrame(avector3f, baseTexture, frameToRender, this.f_107227_, this.f_107228_, this.f_107229_, this.f_107230_, worldLight);
|
||||
if (Config.CLIENT.particleRenderMode.get() == Config.Client.ParticleRenderMode.REALISTIC || Config.CLIENT.particleRenderMode.get() == Config.Client.ParticleRenderMode.REALISTIC_2) {
|
||||
ResourceLocation emissiveTexture = ExplosionTextureManager.getInstance().getTexture(this.emissiveSheetIndex);
|
||||
int fullBright = 240;
|
||||
this.renderFrame(avector3f, emissiveTexture, this.emissiveFrameOnSheet, this.f_107227_, this.f_107228_, this.f_107229_, this.f_107230_, fullBright);
|
||||
} else if (this.f_107224_ < this.smokeStartTick) {
|
||||
ResourceLocation emissiveTexture = ExplosionTextureManager.getInstance().getTexture(1);
|
||||
int fullBright = 240;
|
||||
this.renderFrame(avector3f, emissiveTexture, 0, this.f_107227_, this.f_107228_, this.f_107229_, this.f_107230_ * 0.8f, fullBright);
|
||||
}
|
||||
}
|
||||
|
||||
private void renderFrame(Vector3f[] vertices, ResourceLocation texture, int frame, float r, float g, float b, float a, int light) {
|
||||
float v1;
|
||||
float u1;
|
||||
float v0;
|
||||
float u0;
|
||||
if (texture == null) {
|
||||
return;
|
||||
}
|
||||
RenderSystem.setShader(GameRenderer::m_172829_);
|
||||
RenderSystem.setShaderTexture((int)0, (ResourceLocation)texture);
|
||||
RenderSystem.enableDepthTest();
|
||||
RenderSystem.enableBlend();
|
||||
RenderSystem.defaultBlendFunc();
|
||||
RenderSystem.depthMask((boolean)true);
|
||||
Tesselator tesselator = Tesselator.m_85913_();
|
||||
BufferBuilder buffer = tesselator.m_85915_();
|
||||
buffer.m_166779_(VertexFormat.Mode.QUADS, DefaultVertexFormat.f_85813_);
|
||||
if (frame == 0 && Config.CLIENT.particleRenderMode.get() == Config.Client.ParticleRenderMode.VANILA) {
|
||||
u0 = 0.0f;
|
||||
v0 = 0.0f;
|
||||
u1 = 1.0f;
|
||||
v1 = 1.0f;
|
||||
} else {
|
||||
float frameUWidth = 0.125f;
|
||||
float frameVHeight = 0.125f;
|
||||
int col = frame % 8;
|
||||
int row = frame / 8;
|
||||
u0 = (float)col * frameUWidth;
|
||||
v0 = (float)row * frameVHeight;
|
||||
u1 = u0 + frameUWidth;
|
||||
v1 = v0 + frameVHeight;
|
||||
}
|
||||
buffer.m_5483_((double)vertices[0].x(), (double)vertices[0].y(), (double)vertices[0].z()).m_7421_(u0, v1).m_85950_(r, g, b, a).m_85969_(light).m_5752_();
|
||||
buffer.m_5483_((double)vertices[1].x(), (double)vertices[1].y(), (double)vertices[1].z()).m_7421_(u0, v0).m_85950_(r, g, b, a).m_85969_(light).m_5752_();
|
||||
buffer.m_5483_((double)vertices[2].x(), (double)vertices[2].y(), (double)vertices[2].z()).m_7421_(u1, v0).m_85950_(r, g, b, a).m_85969_(light).m_5752_();
|
||||
buffer.m_5483_((double)vertices[3].x(), (double)vertices[3].y(), (double)vertices[3].z()).m_7421_(u1, v1).m_85950_(r, g, b, a).m_85969_(light).m_5752_();
|
||||
tesselator.m_85914_();
|
||||
}
|
||||
|
||||
public ParticleRenderType m_7556_() {
|
||||
return ParticleRenderType.f_107433_;
|
||||
}
|
||||
|
||||
private int interpolate(float power, float p1, float v1, float p2, float v2) {
|
||||
if (p2 == p1) {
|
||||
return (int)v1;
|
||||
}
|
||||
float fraction = (power - p1) / (p2 - p1);
|
||||
return (int)(v1 + fraction * (v2 - v1));
|
||||
}
|
||||
|
||||
private float updateHeightPercent() {
|
||||
if (this.maxRadius <= 0.0f) {
|
||||
return 0.5f;
|
||||
}
|
||||
return Math.max(0.25f, this.currentHeightPercent);
|
||||
}
|
||||
|
||||
public int m_6355_(float pPartialTick) {
|
||||
if (Config.CLIENT.particleRenderMode.get() == Config.Client.ParticleRenderMode.VANILA) {
|
||||
float currentAge = (float)this.f_107224_ + pPartialTick;
|
||||
if (currentAge < (float)this.fireTransitionEndTick) {
|
||||
return 240;
|
||||
}
|
||||
if (currentAge > (float)this.smokeStartTick) {
|
||||
return super.m_6355_(pPartialTick);
|
||||
}
|
||||
float progress = (currentAge - (float)this.fireTransitionEndTick) / (float)(this.smokeStartTick - this.fireTransitionEndTick);
|
||||
int packedAmbient = super.m_6355_(pPartialTick);
|
||||
int skyLightAmbient = packedAmbient >> 20 & 0xF;
|
||||
int blockLightAmbient = packedAmbient >> 4 & 0xF;
|
||||
int skyLightCurrent = (int)Mth.m_14179_((float)progress, (float)15.0f, (float)skyLightAmbient);
|
||||
int blockLightCurrent = (int)Mth.m_14179_((float)progress, (float)15.0f, (float)blockLightAmbient);
|
||||
return skyLightCurrent << 20 | blockLightCurrent << 4;
|
||||
}
|
||||
return super.m_6355_(pPartialTick);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user