Skip to content

Commit

Permalink
Restore blur particles in 1.21.4
Browse files Browse the repository at this point in the history
  • Loading branch information
rubensworks committed Dec 31, 2024
1 parent 45c839f commit 536ba22
Show file tree
Hide file tree
Showing 7 changed files with 63 additions and 86 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,22 +1,18 @@
package org.cyclops.cyclopscore.client.particle;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import net.minecraft.client.Camera;
import com.mojang.blaze3d.vertex.DefaultVertexFormat;
import com.mojang.blaze3d.vertex.VertexFormat;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.ParticleRenderType;
import net.minecraft.client.particle.TextureSheetParticle;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.world.entity.LivingEntity;
import org.cyclops.cyclopscore.helper.IModHelpers;
import org.cyclops.cyclopscore.helper.IRenderHelpers;
import org.lwjgl.opengl.GL11;

import java.util.Objects;
import org.cyclops.cyclopscore.Reference;

/**
* A blurred static fading particle with any possible color.
Expand All @@ -25,6 +21,32 @@
*/
public class ParticleBlur extends TextureSheetParticle {

public static final RenderType RENDER_TYPE = new RenderType(
Reference.MOD_ID + ":blur",
DefaultVertexFormat.PARTICLE,
VertexFormat.Mode.QUADS,
1536,
false,
false,
() -> {
RenderType.translucentParticle(TextureAtlas.LOCATION_PARTICLES).setupRenderState();

RenderSystem.depthMask(false);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE);

AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_PARTICLES);
texture.setFilter(true, false);
}, () -> {
RenderSystem.disableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.depthMask(true);

RenderType.translucentParticle(TextureAtlas.LOCATION_PARTICLES).clearRenderState();
}
) {};
public static final ParticleRenderType PARTICLE_RENDER_TYPE = new ParticleRenderType(Reference.MOD_ID + ":blur", RENDER_TYPE);

private static final int MAX_VIEW_DISTANCE = 30;

protected float originalScale;
Expand Down Expand Up @@ -72,7 +94,7 @@ private void validateDistance() {

@Override
public ParticleRenderType getRenderType() {
return ParticleRenderType.CUSTOM;
return PARTICLE_RENDER_TYPE;
}

@Override
Expand Down Expand Up @@ -116,32 +138,4 @@ public float getQuadSize(float p_217561_1_) {
quadSize = originalScale * agescale * 0.5F;
return quadSize;
}

@Override
public void renderCustom(PoseStack poseStack, MultiBufferSource bufferSource, Camera camera, float partialTick) {
RenderSystem.depthMask(false);
RenderSystem.enableBlend();
RenderSystem.blendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE);
//RenderSystem.alphaFunc(GL11.GL_GREATER, 0.003921569F);
//RenderSystem.disableLighting();

IRenderHelpers renderHelpers = IModHelpers.get().getRenderHelpers();
renderHelpers.bindTexture(TextureAtlas.LOCATION_PARTICLES);
AbstractTexture texture = Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_PARTICLES);
// lastBlur = texture.blur;
// lastMipmap = texture.mipmap;
texture.setFilter(true, false);

// BufferBuilder buffer = tesselator.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
VertexConsumer buffer = bufferSource.getBuffer(Objects.requireNonNull(getRenderType().renderType()));

// ((BufferBuilderWrapper) builder).cc$setRunnableOnBuild(this::end); // TODO: rm mixin?

this.render(buffer, camera, partialTick);

// Minecraft.getInstance().getTextureManager().getTexture(TextureAtlas.LOCATION_PARTICLES).setFilter(lastBlur, lastMipmap);
//RenderSystem.alphaFunc(GL11.GL_GREATER, 0.1F);
RenderSystem.disableBlend();
RenderSystem.depthMask(true);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package org.cyclops.cyclopscore.proxy;

import com.mojang.blaze3d.vertex.VertexConsumer;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.fabricmc.fabric.api.client.screen.v1.ScreenEvents;
import net.minecraft.CrashReport;
import net.minecraft.CrashReportCategory;
import net.minecraft.ReportedException;
import net.minecraft.client.particle.Particle;
import org.cyclops.cyclopscore.CyclopsCoreFabric;
import org.cyclops.cyclopscore.client.gui.GuiMainMenuExtensionDevWorldFabricRegistrar;
import org.cyclops.cyclopscore.client.particle.ParticleBlur;
import org.cyclops.cyclopscore.events.IParticleEngineRenderEvent;
import org.cyclops.cyclopscore.init.ModBaseFabric;
import org.cyclops.cyclopscore.item.ItemInformationProviderFabric;

import java.util.Queue;

/**
* Proxy for the client side.
*
Expand All @@ -30,5 +39,25 @@ public void registerEventHooks() {

ItemTooltipCallback.EVENT.register(ItemInformationProviderFabric::onTooltip);
ScreenEvents.AFTER_INIT.register(GuiMainMenuExtensionDevWorldFabricRegistrar::afterInit);
IParticleEngineRenderEvent.EVENT.register((particleEngine, camera, partialTick, bufferSource) -> {
Queue<Particle> queue = particleEngine.particles.get(ParticleBlur.PARTICLE_RENDER_TYPE);
if (queue != null && !queue.isEmpty()) {
/* Below is copied and adapted from ParticleEngine */
VertexConsumer vertexConsumer = bufferSource.getBuffer(ParticleBlur.PARTICLE_RENDER_TYPE.renderType());
for (Particle particle : queue) {
try {
particle.render(vertexConsumer, camera, partialTick);
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.forThrowable(throwable, "Rendering Cyclops Core Particle");
CrashReportCategory crashreportcategory = crashreport.addCategory("Particle being rendered");
crashreportcategory.setDetail("Particle", particle::toString);
crashreportcategory.setDetail("Particle Type", ParticleBlur.PARTICLE_RENDER_TYPE.renderType()::toString);
throw new ReportedException(crashreport);
}
}

bufferSource.endBatch();
}
});
}
}
1 change: 0 additions & 1 deletion loader-fabric/src/main/resources/mixins.cyclopscore.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
"MixinServerPlayer"
],
"client": [
"MixinBufferBuilder",
"MixinClientLevel",
"MixinLivingEntityRenderer",
"MixinParticleEngine"
Expand Down
4 changes: 1 addition & 3 deletions loader-forge/src/main/resources/mixins.cyclopscore.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"required": true,
"compatibilityLevel": "JAVA_17",
"package": "org.cyclops.cyclopscore.mixin",
"client": [
"MixinBufferBuilder"
],
"client": [],
"setSourceFile": true
}
4 changes: 1 addition & 3 deletions loader-neoforge/src/main/resources/mixins.cyclopscore.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
"required": true,
"compatibilityLevel": "JAVA_17",
"package": "org.cyclops.cyclopscore.mixin",
"client": [
"MixinBufferBuilder"
],
"client": [],
"setSourceFile": true
}

0 comments on commit 536ba22

Please sign in to comment.