Skip to content

Commit

Permalink
Cleanup Part 3 & Moved Particle Creation To New Class "ParticleUtil" …
Browse files Browse the repository at this point in the history
…& Moved Smoke Rendering To "FBPRenderer"
  • Loading branch information
Desoroxxx committed Dec 2, 2022
1 parent 45a9154 commit 2d8f06e
Show file tree
Hide file tree
Showing 11 changed files with 473 additions and 552 deletions.
5 changes: 4 additions & 1 deletion src/main/java/io/redstudioragnarok/FBP/FBP.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import net.minecraft.block.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.particle.ParticleManager;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
import net.minecraft.client.renderer.vertex.VertexFormat;
import net.minecraft.init.Blocks;
Expand Down Expand Up @@ -39,7 +40,6 @@ public class FBP {
public static FBP INSTANCE;

public static final ResourceLocation LOCATION_PARTICLE_TEXTURE = new ResourceLocation("textures/particle/particles.png");

public static final ResourceLocation FBP_BUG = new ResourceLocation(ModReference.MOD_ID + ":textures/gui/bug.png");
public static final ResourceLocation FBP_FBP = new ResourceLocation(ModReference.MOD_ID + ":textures/gui/fbp.png");
public static final ResourceLocation FBP_WIDGETS = new ResourceLocation(ModReference.MOD_ID + ":textures/gui/widgets.png");
Expand Down Expand Up @@ -103,6 +103,8 @@ public class FBP {
public static final FBPEventHandler eventHandler = new FBPEventHandler();
public static final FBPGuiHandler guiHandler = new FBPGuiHandler();

public static TextureAtlasSprite snowTexture;

public FBP() {
INSTANCE = this;

Expand Down Expand Up @@ -137,6 +139,7 @@ public void init(FMLInitializationEvent evt) {
@EventHandler
public void postInit(FMLPostInitializationEvent evt) {
MinecraftForge.EVENT_BUS.register(guiHandler);
snowTexture = Minecraft.getMinecraft().getBlockRendererDispatcher().getBlockModelShapes().getTexture(Blocks.SNOW.getDefaultState());
}

public static boolean isEnabled() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
import javax.annotation.Nullable;
import java.util.List;

import static io.redstudioragnarok.FBP.util.ParticleUtil.texturedParticle;

public class FBPParticleDigging extends ParticleDigging {

private final IBlockState blockState;
Expand All @@ -50,8 +52,6 @@ public class FBPParticleDigging extends ParticleDigging {

FBPVector3d rot, prevRot, rotStep;

Vec2f[] par;

static Entity dummyEntity = new Entity(null) {
@Override
protected void writeEntityToNBT(NBTTagCompound compound) {
Expand Down Expand Up @@ -466,7 +466,7 @@ public void move(double x, double y, double z) {
}

@Override
public void renderParticle(BufferBuilder buf, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
if (!FBPRenderer.render) {
FBPRenderer.queuedParticles.add(this);
return;
Expand All @@ -476,35 +476,20 @@ public void renderParticle(BufferBuilder buf, Entity entityIn, float partialTick
if (FBPKeyBindings.FBPKillParticles.isKeyDown() && !killToggle)
killToggle = true;

float textureX1, textureX2, textureY1, textureY2;

float particleScale = (float) (prevParticleScale + (this.particleScale - prevParticleScale) * partialTicks);

if (particleTexture != null) {
textureX1 = particleTexture.getInterpolatedU(particleTextureJitterX / 4 * 16);
textureY1 = particleTexture.getInterpolatedV(particleTextureJitterY / 4 * 16);

textureX2 = particleTexture.getInterpolatedU((particleTextureJitterX + 1) / 4 * 16);
textureY2 = particleTexture.getInterpolatedV((particleTextureJitterY + 1) / 4 * 16);
} else {
textureX1 = (particleTextureIndexX + particleTextureJitterX / 4) / 16;
textureX2 = textureX1 + 0.015F;
textureY1 = (particleTextureIndexY + particleTextureJitterY / 4) / 16;
textureY2 = textureY1 + 0.015F;
}
Vec2f[] particle = texturedParticle(particleTexture, particleTextureJitterX, particleTextureJitterY, particleTextureIndexX, particleTextureIndexY);

float x = (float) (prevPosX + (posX - prevPosX) * partialTicks - interpPosX);
float y = (float) (prevPosY + (posY - prevPosY) * partialTicks - interpPosY);
float z = (float) (prevPosZ + (posZ - prevPosZ) * partialTicks - interpPosZ);

int brightness = getBrightnessForRender(partialTicks);

par = new Vec2f[] { new Vec2f(textureX2, textureY2), new Vec2f(textureX2, textureY1), new Vec2f(textureX1, textureY1), new Vec2f(textureX1, textureY2) };

float alpha = (float) (prevParticleAlpha + (particleAlpha - prevParticleAlpha) * partialTicks);

float scale = (float) (prevParticleScale + (particleScale - prevParticleScale) * partialTicks);

if (FBP.restOnFloor)
y += particleScale / 10;
y += scale / 10;

FBPVector3d smoothRot = new FBPVector3d(0, 0, 0);

Expand All @@ -528,8 +513,7 @@ public void renderParticle(BufferBuilder buf, Entity entityIn, float partialTick
}
}

// RENDER
FBPRenderer.renderCubeShaded_S(buf, par, x, y, z, particleScale / 10, smoothRot, brightness >> 16 & 65535, brightness & 65535, particleRed, particleGreen, particleBlue, alpha);
FBPRenderer.renderCubeShaded_S(buffer, particle, x, y, z, scale / 10, smoothRot, brightness >> 16 & 65535, brightness & 65535, particleRed, particleGreen, particleBlue, alpha);
}

private void createRotationMatrix() {
Expand All @@ -547,9 +531,9 @@ public int getBrightnessForRender(float partialTicks) {
AxisAlignedBB boundingBox = getBoundingBox();

if (this.world.isBlockLoaded(new BlockPos(posX, 0, posZ))) {
double d0 = (boundingBox.maxY - boundingBox.minY) * 0.66;
double k = this.posY + d0 + 0.01 - (FBP.restOnFloor ? particleScale / 10 : 0);
return this.world.getCombinedLight(new BlockPos(posX, k, posZ), 0);
double boundingBoxHeight = (boundingBox.maxY - boundingBox.minY) * 0.66;
double posY = this.posY + boundingBoxHeight + 0.01 - (FBP.restOnFloor ? particleScale / 10 : 0);
return this.world.getCombinedLight(new BlockPos(posX, posY, posZ), 0);
} else {
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

import java.util.List;

import static io.redstudioragnarok.FBP.FBP.snowTexture;
import static io.redstudioragnarok.FBP.util.ParticleUtil.gasParticle;

public class FBPParticleFlame extends ParticleFlame {

Minecraft mc;
Expand All @@ -30,8 +33,6 @@ public class FBPParticleFlame extends ParticleFlame {

Vec3d[] cube;

Vec2f par;

protected FBPParticleFlame(World worldIn, double xCoordIn, double yCoordIn, double zCoordIn, double mY, boolean spawnAnother) {
super(worldIn, xCoordIn, yCoordIn - 0.06, zCoordIn, 0, mY, 0);
IBlockState blockState = worldIn.getBlockState(new BlockPos(posX, posY, posZ));
Expand All @@ -48,7 +49,7 @@ protected FBPParticleFlame(World worldIn, double xCoordIn, double yCoordIn, doub
this.motionY = -0.00085;
this.particleGravity = -0.05f;

this.particleTexture = mc.getBlockRendererDispatcher().getBlockModelShapes().getTexture(Blocks.SNOW.getDefaultState());
this.particleTexture = snowTexture;

particleScale *= FBP.scaleMult * 2.5;
particleMaxAge = FBP.random.nextInt(3, 5);
Expand Down Expand Up @@ -175,41 +176,37 @@ protected void resetPositionToBB() {
}

@Override
public void renderParticle(BufferBuilder buf, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
public void renderParticle(BufferBuilder buffer, Entity entityIn, float partialTicks, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
if (!FBP.isEnabled() && particleMaxAge != 0)
particleMaxAge = 0;

Vec2f particle = gasParticle(particleTexture);

float x = (float) (prevPosX + (posX - prevPosX) * partialTicks - interpPosX);
float y = (float) (prevPosY + (posY - prevPosY) * partialTicks - interpPosY);
float z = (float) (prevPosZ + (posZ - prevPosZ) * partialTicks - interpPosZ);

float texture1 = particleTexture.getInterpolatedU((0.1 + 1) / 4 * 16);
float texture2 = particleTexture.getInterpolatedV((0.1 + 1) / 4 * 16);
int brightness = getBrightnessForRender(partialTicks);

par = new Vec2f(texture1, texture2);
float alpha = (float) (prevParticleAlpha + (particleAlpha - prevParticleAlpha) * partialTicks);

// Smooth scale transition
float scale = (float) (prevParticleScale + (particleScale - prevParticleScale) * partialTicks);

if (this.particleAge >= this.particleMaxAge)
this.particleGreen = (float) (scale / startScale);

int brightness = getBrightnessForRender(partialTicks);

float alpha = (float) (prevParticleAlpha + (particleAlpha - prevParticleAlpha) * partialTicks);

FBPRenderer.renderCube_F(buf, par, x, y, z, scale, brightness, particleRed, particleGreen, particleBlue, alpha, cube);
FBPRenderer.renderCube_F(buffer, particle, x, y, z, scale, brightness, particleRed, particleGreen, particleBlue, alpha, cube);
}

@Override
public int getBrightnessForRender(float p_189214_1_) {
int brightnessForRender = super.getBrightnessForRender(p_189214_1_);
int ligthing = 0;
public int getBrightnessForRender(float partialTick) {
int brightnessForRender = super.getBrightnessForRender(partialTick);
int lighting = 0;

if (this.world.isBlockLoaded(new BlockPos(posX, posY, posZ))) {
ligthing = this.world.getCombinedLight(new BlockPos(posX, posY, posZ), 0);
lighting = this.world.getCombinedLight(new BlockPos(posX, posY, posZ), 0);
}

return brightnessForRender == 0 ? ligthing : brightnessForRender;
return brightnessForRender == 0 ? lighting : brightnessForRender;
}
}
Loading

1 comment on commit 2d8f06e

@Desoroxxx
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also added more info in the Smart Breaking description

Please sign in to comment.