Untitled

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

import com.mojang.blaze3d.vertex.*;
import com.mojang.math.Quaternion;
import com.mojang.math.Vector3f;
import com.radon.naruto_universe.entity.projectile.FireBulletProjectile;
import net.minecraft.client.Camera;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.entity.*;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.phys.Vec3;

public class FireBulletRenderer extends EntityRenderer<FireBulletProjectile> {
    public FireBulletRenderer(EntityRendererProvider.Context context) {
        super(context);
    }

    @Override
    public void render(FireBulletProjectile entity, float entityYaw, float partialTicks, PoseStack pMatrixStack, MultiBufferSource buffer, int packedLight) {
        Camera camera = Minecraft.getInstance().getEntityRenderDispatcher().camera;

        Vec3 position = camera.getPosition();
        float x = (float)(Mth.lerp(partialTicks, entity.xo, entity.getX()) - position.x());
        float y = (float)(Mth.lerp(partialTicks, entity.yo, entity.getY()) - position.y());
        float z = (float)(Mth.lerp(partialTicks, entity.zo, entity.getZ()) - position.z());
        Quaternion quaternion = camera.rotation();

        new Vector3f(-1.0F, -1.0F, 0.0F).transform(quaternion);
        Vector3f[] rotation = new Vector3f[] { new Vector3f(-1.0F, -1.0F, 0.0F), new Vector3f(-1.0F, 1.0F, 0.0F), new Vector3f(1.0F, 1.0F, 0.0F), new Vector3f(1.0F, -1.0F, 0.0F) };
        float quadSize = 10.0F;

        for (int i = 0; i < 4; ++i) {
            rotation[i].transform(quaternion);
            rotation[i].mul(quadSize);
            rotation[i].add(x, y, z);
        }

        int lightColor = 15728640;

        VertexConsumer consumer = buffer.getBuffer(RenderTypeRegistry.FIREBALL_RENDER);

        float U0 = 0.0F;
        float U1 = 1.0F;
        float V0 = 0.0F;
        float V1 = 1.0F;

        consumer.vertex(rotation[0].x(), rotation[0].y(), rotation[0].z()).uv(U1, V1).color(1.0F, 0.5F, 0.0F, 1.0F).uv2(lightColor).endVertex();
        consumer.vertex(rotation[1].x(), rotation[1].y(), rotation[1].z()).uv(U1, V0).color(1.0F, 0.5F, 0.0F, 1.0F).uv2(lightColor).endVertex();
        consumer.vertex(rotation[2].x(), rotation[2].y(), rotation[2].z()).uv(U0, V0).color(1.0F, 0.5F, 0.0F, 1.0F).uv2(lightColor).endVertex();
        consumer.vertex(rotation[3].x(), rotation[3].y(), rotation[3].z()).uv(U0, V1).color(1.0F, 0.5F, 0.0F, 1.0F).uv2(lightColor).endVertex();
    }

    @Override
    public ResourceLocation getTextureLocation(FireBulletProjectile pEntity) {
        return null;
    }
}