Fix light beam render (WIP)

This commit is contained in:
Aleksey 2020-12-02 23:21:36 +03:00
parent 4eefc50385
commit ced6fb23ce
3 changed files with 29 additions and 28 deletions

View file

@ -2,6 +2,7 @@ package ru.betterend.blocks.entities.render;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.block.BlockState;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.RenderLayer;
@ -16,9 +17,9 @@ import net.minecraft.client.util.math.Vector3f;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.DyeColor;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper;
import ru.betterend.blocks.EternalPedestal;
import ru.betterend.blocks.basis.BlockPedestal;
import ru.betterend.blocks.entities.PedestalBlockEntity;
@ -58,20 +59,21 @@ public class PedestalItemRenderer<T extends PedestalBlockEntity> extends BlockEn
} else {
matrices.scale(1.25F, 1.25F, 1.25F);
}
int age = blockEntity.getAge();
if (state.isOf(EndBlocks.ETERNAL_PEDESTAL) && state.get(EternalPedestal.ACTIVATED)) {
float[] colors = DyeColor.MAGENTA.getColorComponents();
float[] colors = EternalCrystalRenderer.colors(age);
int y = blockEntity.getPos().getY();
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(RenderLayer.getBeaconBeam(BEAM_TEXTURE, true));
BeamRenderer.renderLightBeam(matrices, vertexConsumer, tickDelta, -y, 1024 - y, colors, 0.25F, 0.15F, 0.2F);
BeamRenderer.renderLightBeam(matrices, vertexConsumer, age, tickDelta, -y, 1024 - y, colors, 0.25F, 0.15F, 0.18F);
float altitude = MathHelper.sin((blockEntity.getAge() + tickDelta) / 10.0F) * 0.1F + 0.1F;
matrices.translate(0.0D, altitude, 0.0D);
}
if (activeItem.getItem() == Items.END_CRYSTAL) {
EndCrystalRenderer.render(blockEntity.getAge(), blockEntity.getMaxAge(), tickDelta, matrices, vertexConsumers, light);
EndCrystalRenderer.render(age, blockEntity.getMaxAge(), tickDelta, matrices, vertexConsumers, light);
} else if (activeItem.getItem() == EndItems.ETERNAL_CRYSTAL) {
EternalCrystalRenderer.render(blockEntity.getAge(), tickDelta, matrices, vertexConsumers, light);
EternalCrystalRenderer.render(age, tickDelta, matrices, vertexConsumers, light);
} else {
float rotation = (blockEntity.getAge() + tickDelta) / 25.0F + 6.0F;
float rotation = (age + tickDelta) / 25.0F + 6.0F;
matrices.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(rotation));
minecraft.getItemRenderer().renderItem(activeItem, ModelTransformation.Mode.GROUND, false, matrices, vertexConsumers, light, overlay, model);
}

View file

@ -9,34 +9,33 @@ import net.minecraft.util.math.Matrix3f;
import net.minecraft.util.math.Matrix4f;
public class BeamRenderer {
public static void renderLightBeam(MatrixStack matrixStack, VertexConsumer vertexConsumer, float tick, int minY, int maxY, float[] colors, float alpha, float h, float k) {
public static void renderLightBeam(MatrixStack matrixStack, VertexConsumer vertexConsumer, int age, float tick, int minY, int maxY, float[] colors, float alpha, float h, float k) {
int m = minY + maxY;
float o = maxY < 0 ? tick : -tick;
float p = MathHelper.fractionalPart(o * 0.2F - (float) MathHelper.floor(o * 0.1F));
float delta = maxY < 0 ? tick : -tick;
float p = MathHelper.fractionalPart(delta * 0.2F - (float) MathHelper.floor(delta * 0.1F));
float red = colors[0];
float green = colors[1];
float blue = colors[2];
matrixStack.push();
matrixStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(tick * 2.25F - 45.0F));
float af = 0.0F;
float ai = 0.0F;
float aj = -h;
float aa = -h;
float ap = -1.0F + p;
float ap = p - 1.0F;
float aq = (float) maxY * (0.5F / h) + ap;
renderBeam(matrixStack, vertexConsumer, red, green, blue, alpha, minY, m, 0.0F, h, h, 0.0F, aj, 0.0F, 0.0F, aa, 0.0F, 1.0F, aq, ap);
float rotation = (age + tick) / 25.0F + 6.0F;
matrixStack.push();
matrixStack.push();
matrixStack.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(-rotation));
renderBeam(matrixStack, vertexConsumer, red, green, blue, alpha, minY, m, 0.0F, h, h, 0.0F, aj, 0.0F, 0.0F, aj, 0.0F, 1.0F, aq, ap);
matrixStack.pop();
af = -k;
float ag = -k;
ai = -k;
aj = -k;
ap = -1.0F + p;
aq = (float) maxY + ap;
renderBeam(matrixStack, vertexConsumer, red, green, blue, alpha, minY, m, af, ag, k, ai, aj, k, k, k, 0.0F, 1.0F, aq, ap);
matrixStack.multiply(Vector3f.POSITIVE_Y.getRadialQuaternion(-rotation));
renderBeam(matrixStack, vertexConsumer, red, green, blue, alpha, minY, m, af, af, k, af, af, k, k, k, 0.0F, 1.0F, aq, ap);
matrixStack.pop();
}
private static void renderBeam(MatrixStack matrixStack, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int j, int k, float l, float m, float n, float o, float p, float q, float r, float s, float t, float u, float v, float w) {
@ -49,14 +48,14 @@ public class BeamRenderer {
renderBeam(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, j, k, p, q, l, m, t, u, v, w);
}
private static void renderBeam(Matrix4f matrix4f, Matrix3f matrix3f, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int j, int k, float l, float m, float n, float o, float p, float q, float r, float s) {
addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, k, l, m, q, r);
addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, j, l, m, q, s);
addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, j, n, o, p, s);
addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, k, n, o, p, r);
private static void renderBeam(Matrix4f matrix4f, Matrix3f matrix3f, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, int maxY, int minY, float maxX, float m, float minX, float o, float minU, float maxU, float minV, float maxV) {
addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxX, minY, m, maxU, minV);
addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, maxX, maxY, m, maxU, maxV);
addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, minX, maxY, o, minU, maxV);
addVertex(matrix4f, matrix3f, vertexConsumer, red, green, blue, alpha, minX, minY, o, minU, minV);
}
private static void addVertex(Matrix4f matrix4f, Matrix3f matrix3f, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, float y, float x, float l, float m, float n) {
vertexConsumer.vertex(matrix4f, x, y, l).color(red, green, blue, alpha).texture(m, n).overlay(OverlayTexture.DEFAULT_UV).light(15728880).normal(matrix3f, 0.0F, 1.0F, 0.0F).next();
private static void addVertex(Matrix4f matrix4f, Matrix3f matrix3f, VertexConsumer vertexConsumer, float red, float green, float blue, float alpha, float x, float y, float d, float u, float v) {
vertexConsumer.vertex(matrix4f, x, y, d).color(red, green, blue, alpha).texture(u, v).overlay(OverlayTexture.DEFAULT_UV).light(15728880).normal(matrix3f, 0.0F, 1.0F, 0.0F).next();
}
}

View file

@ -33,7 +33,7 @@ public class EternalCrystalRenderer {
matrices.pop();
}
private static float[] colors(int age) {
public static float[] colors(int age) {
double delta = age * 0.01;
int index = MHelper.floor(delta);
int index2 = (index + 1) & 3;