Add util class to work around MC bug (instead of copy-pasted workaround).
This commit is contained in:
@@ -6,6 +6,7 @@ import com.mojang.math.Matrix4f;
|
||||
import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.client.renderer.ModRenderType;
|
||||
import li.cil.oc2.common.blockentity.ChargerBlockEntity;
|
||||
import li.cil.oc2.common.util.ChainableVertexConsumer;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
|
||||
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
|
||||
@@ -31,7 +32,7 @@ public final class ChargerRenderer implements BlockEntityRenderer<ChargerBlockEn
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
|
||||
public ChargerRenderer(final BlockEntityRendererProvider.Context ignored) {
|
||||
public ChargerRenderer(final BlockEntityRendererProvider.Context ignoredContext) {
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////
|
||||
@@ -67,24 +68,21 @@ public final class ChargerRenderer implements BlockEntityRenderer<ChargerBlockEn
|
||||
}
|
||||
|
||||
private static void renderQuad(final Matrix4f matrix, final VertexConsumer consumer) {
|
||||
// NB: We may get a SpriteAwareVertexBuilder here. Sadly, its chaining is broken,
|
||||
// because methods may return the underlying vertex builder, so e.g. calling
|
||||
// buffer.pos(...).tex(...) will not actually call SpriteAwareVertexBuilder.tex(...)
|
||||
// but SpriteAwareVertexBuilder.vertexBuilder.tex(...), skipping the UV remapping.
|
||||
consumer.vertex(matrix, -0.5f, 0, -0.5f);
|
||||
consumer.uv(0, 0);
|
||||
consumer.endVertex();
|
||||
final VertexConsumer wrapper = new ChainableVertexConsumer(consumer);
|
||||
wrapper.vertex(matrix, -0.5f, 0, -0.5f)
|
||||
.uv(0, 0)
|
||||
.endVertex();
|
||||
|
||||
consumer.vertex(matrix, -0.5f, 0, 0.5f);
|
||||
consumer.uv(0, 1);
|
||||
consumer.endVertex();
|
||||
wrapper.vertex(matrix, -0.5f, 0, 0.5f)
|
||||
.uv(0, 1)
|
||||
.endVertex();
|
||||
|
||||
consumer.vertex(matrix, 0.5f, 0, 0.5f);
|
||||
consumer.uv(1, 1);
|
||||
consumer.endVertex();
|
||||
wrapper.vertex(matrix, 0.5f, 0, 0.5f)
|
||||
.uv(1, 1)
|
||||
.endVertex();
|
||||
|
||||
consumer.vertex(matrix, 0.5f, 0, -0.5f);
|
||||
consumer.uv(1, 0);
|
||||
consumer.endVertex();
|
||||
wrapper.vertex(matrix, 0.5f, 0, -0.5f)
|
||||
.uv(1, 0)
|
||||
.endVertex();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ import li.cil.oc2.api.API;
|
||||
import li.cil.oc2.client.renderer.ModRenderType;
|
||||
import li.cil.oc2.common.block.ComputerBlock;
|
||||
import li.cil.oc2.common.blockentity.ComputerBlockEntity;
|
||||
import li.cil.oc2.common.util.ChainableVertexConsumer;
|
||||
import li.cil.oc2.common.vm.Terminal;
|
||||
import net.minecraft.client.gui.Font;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
@@ -228,25 +229,22 @@ public final class ComputerRenderer implements BlockEntityRenderer<ComputerBlock
|
||||
}
|
||||
|
||||
private static void renderQuad(final Matrix4f matrix, final VertexConsumer consumer) {
|
||||
// NB: We may get a SpriteAwareVertexBuilder here. Sadly, its chaining is broken,
|
||||
// because methods may return the underlying vertex builder, so e.g. calling
|
||||
// buffer.pos(...).tex(...) will not actually call SpriteAwareVertexBuilder.tex(...)
|
||||
// but SpriteAwareVertexBuilder.vertexBuilder.tex(...), skipping the UV remapping.
|
||||
consumer.vertex(matrix, 0, 0, 0);
|
||||
consumer.uv(0, 0);
|
||||
consumer.endVertex();
|
||||
final VertexConsumer wrapper = new ChainableVertexConsumer(consumer);
|
||||
wrapper.vertex(matrix, 0, 0, 0)
|
||||
.uv(0, 0)
|
||||
.endVertex();
|
||||
|
||||
consumer.vertex(matrix, 0, 16, 0);
|
||||
consumer.uv(0, 1);
|
||||
consumer.endVertex();
|
||||
wrapper.vertex(matrix, 0, 16, 0)
|
||||
.uv(0, 1)
|
||||
.endVertex();
|
||||
|
||||
consumer.vertex(matrix, 16, 16, 0);
|
||||
consumer.uv(1, 1);
|
||||
consumer.endVertex();
|
||||
wrapper.vertex(matrix, 16, 16, 0)
|
||||
.uv(1, 1)
|
||||
.endVertex();
|
||||
|
||||
consumer.vertex(matrix, 16, 0, 0);
|
||||
consumer.uv(1, 0);
|
||||
consumer.endVertex();
|
||||
wrapper.vertex(matrix, 16, 0, 0)
|
||||
.uv(1, 0)
|
||||
.endVertex();
|
||||
}
|
||||
|
||||
private static void updateCache(final TickEvent.ClientTickEvent event) {
|
||||
|
||||
@@ -0,0 +1,153 @@
|
||||
package li.cil.oc2.common.util;
|
||||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.math.Matrix3f;
|
||||
import com.mojang.math.Matrix4f;
|
||||
import com.mojang.math.Vector3f;
|
||||
import net.minecraft.client.renderer.SpriteCoordinateExpander;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
/**
|
||||
* Provides a safe wrapper around any kind of {@link VertexConsumer} implementation so that
|
||||
* call-chaining still works expected.
|
||||
* <p>
|
||||
* This is primarily a workaround for the broken chaining in {@link SpriteCoordinateExpander}.
|
||||
* It may return the inner {@link VertexConsumer} instead of itself from some methods,
|
||||
* breaking chaining due to UV remapping missing later on in the chain.
|
||||
*/
|
||||
public record ChainableVertexConsumer(VertexConsumer inner) implements VertexConsumer {
|
||||
@Override
|
||||
public VertexConsumer vertex(final double x, final double y, final double z) {
|
||||
inner.vertex(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(final int r, final int g, final int b, final int a) {
|
||||
inner.color(r, g, b, a);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv(final float u, final float v) {
|
||||
inner.uv(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlayCoords(final int u, final int v) {
|
||||
inner.overlayCoords(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv2(final int u, final int v) {
|
||||
inner.uv2(u, v);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(final float x, final float y, final float z) {
|
||||
inner.normal(x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void endVertex() {
|
||||
inner.endVertex();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void defaultColor(final int r, final int g, final int b, final int a) {
|
||||
inner.defaultColor(r, g, b, a);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void unsetDefaultColor() {
|
||||
inner.unsetDefaultColor();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void vertex(final float x, final float y, final float z, final float r, final float g, final float b, final float a, final float u, final float v, final int overlay, final int uv2, final float nx, final float ny, final float nz) {
|
||||
inner.vertex(x, y, z, r, g, b, a, u, v, overlay, uv2, nx, ny, nz);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(final float r, final float g, final float b, final float a) {
|
||||
inner.color(r, g, b, a);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer color(final int rgba) {
|
||||
inner.color(rgba);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer uv2(final int uv) {
|
||||
inner.uv2(uv);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer overlayCoords(final int uv) {
|
||||
inner.overlayCoords(uv);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBulkData(final PoseStack.Pose pose, final BakedQuad quad, final float red, final float green, final float blue, final int overlayCoords, final int readExistingColor) {
|
||||
inner.putBulkData(pose, quad, red, green, blue, overlayCoords, readExistingColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBulkData(final PoseStack.Pose pose, final BakedQuad quad, final float[] baseBrightness, final float red, final float green, final float blue, final int[] lightmapCoords, final int overlayCoords, final boolean readExistingColor) {
|
||||
inner.putBulkData(pose, quad, baseBrightness, red, green, blue, lightmapCoords, overlayCoords, readExistingColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer vertex(final Matrix4f matrix, final float x, final float y, final float z) {
|
||||
inner.vertex(matrix, x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public VertexConsumer normal(final Matrix3f matrix, final float x, final float y, final float z) {
|
||||
inner.normal(matrix, x, y, z);
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBulkData(final PoseStack.Pose matrixStack, final BakedQuad bakedQuad, final float red, final float green, final float blue, final int lightmapCoord, final int overlayColor, final boolean readExistingColor) {
|
||||
inner.putBulkData(matrixStack, bakedQuad, red, green, blue, lightmapCoord, overlayColor, readExistingColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBulkData(final PoseStack.Pose matrixEntry, final BakedQuad bakedQuad, final float red, final float green, final float blue, final float alpha, final int lightmapCoord, final int overlayColor) {
|
||||
inner.putBulkData(matrixEntry, bakedQuad, red, green, blue, alpha, lightmapCoord, overlayColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBulkData(final PoseStack.Pose matrixEntry, final BakedQuad bakedQuad, final float red, final float green, final float blue, final float alpha, final int lightmapCoord, final int overlayColor, final boolean readExistingColor) {
|
||||
inner.putBulkData(matrixEntry, bakedQuad, red, green, blue, alpha, lightmapCoord, overlayColor, readExistingColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void putBulkData(final PoseStack.Pose matrixEntry, final BakedQuad bakedQuad, final float[] baseBrightness, final float red, final float green, final float blue, final float alpha, final int[] lightmapCoords, final int overlayCoords, final boolean readExistingColor) {
|
||||
inner.putBulkData(matrixEntry, bakedQuad, baseBrightness, red, green, blue, alpha, lightmapCoords, overlayCoords, readExistingColor);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int applyBakedLighting(final int lightmapCoord, final ByteBuffer data) {
|
||||
return inner.applyBakedLighting(lightmapCoord, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyBakedNormals(final Vector3f generated, final ByteBuffer data, final Matrix3f normalTransform) {
|
||||
inner.applyBakedNormals(generated, data, normalTransform);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user