Untitled

mail@pastecode.io avatar
unknown
java
2 years ago
3.5 kB
36
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 com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import net.minecraft.client.Camera;
import net.minecraft.client.HotbarManager;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.client.particle.*;
import net.minecraft.client.player.inventory.Hotbar;
import net.minecraft.client.renderer.GameRenderer;
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.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;
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, SpriteSet sprites) {
        super(level, x, y, z, 0.0D, 0.0D, 0.0D);

        this.xd = 0.0D;
        this.yd = 0.0D;
        this.zd = 0.0D;

        this.setAlpha(1.0F);
        this.setColor(1.0F, 0.5F, 0.0F);
        this.hasPhysics = false;
        this.pickSprite(sprites);
        this.scale(10.0F);
    }

    @Override
    public void tick() {
        this.xo = this.x;
        this.yo = this.y;
        this.zo = this.z;

        this.move(this.xd, this.yd, this.zd);
    }

    @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(false);
            RenderSystem.enableBlend();
            RenderSystem.blendFunc(770, 1);
            RenderSystem.setShaderTexture(0, TextureAtlas.LOCATION_PARTICLES);
            manager.getTexture(TextureAtlas.LOCATION_PARTICLES).setBlurMipmap(true, false);
            builder.begin(VertexFormat.Mode.QUADS, DefaultVertexFormat.PARTICLE);
        }

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

            Minecraft.getInstance().textureManager.getTexture(TextureAtlas.LOCATION_PARTICLES).restoreLastBlurMipmap();
            RenderSystem.disableBlend();
            RenderSystem.depthMask(true);
        }
    };

    @OnlyIn(Dist.CLIENT)
    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, sprites);
            return particle;
        }
    }
}