|
| 1 | +/* |
| 2 | + * Copyright 2025 Lambda |
| 3 | + * |
| 4 | + * This program is free software: you can redistribute it and/or modify |
| 5 | + * it under the terms of the GNU General Public License as published by |
| 6 | + * the Free Software Foundation, either version 3 of the License, or |
| 7 | + * (at your option) any later version. |
| 8 | + * |
| 9 | + * This program is distributed in the hope that it will be useful, |
| 10 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + * GNU General Public License for more details. |
| 13 | + * |
| 14 | + * You should have received a copy of the GNU General Public License |
| 15 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | + */ |
| 17 | + |
| 18 | +package com.lambda.mixin.render; |
| 19 | + |
| 20 | +import com.lambda.module.modules.render.NoRender; |
| 21 | +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; |
| 22 | +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; |
| 23 | +import net.minecraft.client.particle.Particle; |
| 24 | +import net.minecraft.client.particle.ParticleManager; |
| 25 | +import net.minecraft.client.particle.ParticleTextureSheet; |
| 26 | +import net.minecraft.client.render.Camera; |
| 27 | +import net.minecraft.client.render.VertexConsumerProvider; |
| 28 | +import org.spongepowered.asm.mixin.Mixin; |
| 29 | +import org.spongepowered.asm.mixin.Unique; |
| 30 | +import org.spongepowered.asm.mixin.injection.At; |
| 31 | + |
| 32 | +import java.util.LinkedList; |
| 33 | +import java.util.Queue; |
| 34 | +import java.util.stream.Collectors; |
| 35 | + |
| 36 | +@Mixin(ParticleManager.class) |
| 37 | +public class ParticleManagerMixin { |
| 38 | + // prevents the particles from being stored and potential overhead. Downside being they need to spawn back in rather than just enabling rendering again |
| 39 | +// @Inject(method = "addParticle(Lnet/minecraft/client/particle/Particle;)V", at = @At("HEAD"), cancellable = true) |
| 40 | +// private void injectAddParticle(Particle particle, CallbackInfo ci) { |
| 41 | +// if (NoRender.shouldOmitParticle(particle)) ci.cancel(); |
| 42 | +// } |
| 43 | + |
| 44 | + @WrapOperation(method = "renderParticles(Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/VertexConsumerProvider$Immediate;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleManager;renderParticles(Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/VertexConsumerProvider$Immediate;Lnet/minecraft/client/particle/ParticleTextureSheet;Ljava/util/Queue;)V")) |
| 45 | + private void wrapRenderParticles(Camera camera, float tickProgress, VertexConsumerProvider.Immediate vertexConsumers, ParticleTextureSheet sheet, Queue<Particle> particles, Operation<Void> original) { |
| 46 | + original.call(camera, tickProgress, vertexConsumers, sheet, filterParticles(particles)); |
| 47 | + } |
| 48 | + |
| 49 | + @WrapOperation(method = "renderParticles(Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/VertexConsumerProvider$Immediate;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/particle/ParticleManager;renderCustomParticles(Lnet/minecraft/client/render/Camera;FLnet/minecraft/client/render/VertexConsumerProvider$Immediate;Ljava/util/Queue;)V")) |
| 50 | + private void wrapRenderParticles(Camera camera, float tickProgress, VertexConsumerProvider.Immediate vertexConsumers, Queue<Particle> particles, Operation<Void> original) { |
| 51 | + original.call(camera, tickProgress, vertexConsumers, filterParticles(particles)); |
| 52 | + } |
| 53 | + |
| 54 | + @Unique |
| 55 | + private Queue<Particle> filterParticles(Queue<Particle> particles) { |
| 56 | + return particles.stream().filter(particle -> |
| 57 | + !NoRender.shouldOmitParticle(particle)).collect(Collectors.toCollection(LinkedList::new) |
| 58 | + ); |
| 59 | + } |
| 60 | +} |
0 commit comments