Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
2.7 kB
6
Indexable
Never
package com.radon.naruto_universe.particle;

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import com.mojang.blaze3d.vertex.*;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.client.renderer.texture.AbstractTexture;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import org.jetbrains.annotations.Nullable;
import org.lwjgl.opengl.GL11;

import java.util.Random;

@OnlyIn(Dist.CLIENT)
public class FlameParticle extends TextureSheetParticle {
    public FlameParticle(ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed, SpriteSet sprites) {
        super(level, x, y, z, xSpeed, ySpeed, zSpeed);
        this.sprite = sprites.get(new Random());
        this.setColor(1.0F, 0.5F, 0.0F);
        this.scale(10.0F);
        this.setLifetime(1000);
    }

    @Override
    public int getLightColor(float pPartialTick) {
        return 15728640;
    }

    @Override
    public ParticleRenderType getRenderType() {
        return NORMAL_RENDER;
    }

    private static final ParticleRenderType NORMAL_RENDER = new ParticleRenderType() {
        @Override
        public void begin(BufferBuilder builder, TextureManager manager) {
            RenderSystem.depthMask(true);
            RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_PARTICLES);
            RenderSystem.enableBlend();
            RenderSystem.blendFunc(770, 1);
            manager.getTexture(TextureAtlas.LOCATION_PARTICLES).setBlurMipmap(true, false);
            builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
        }

        @Override
        public void end(Tesselator tesselator) {
            tesselator.end();
        }
    };

    public static class Provider implements ParticleProvider<SimpleParticleType> {
        private final SpriteSet sprites;

        public Provider(SpriteSet sprites) {
            this.sprites = sprites;
        }

        @Nullable
        @Override
        public Particle createParticle(SimpleParticleType type, ClientLevel level, double x, double y, double z, double xSpeed, double ySpeed, double zSpeed) {
            FlameParticle particle = new FlameParticle(level, x, y, z, xSpeed, ySpeed, zSpeed, sprites);
            return particle;
        }
    }
}