Skip to content

Commit 9f581e0

Browse files
committed
fix: Revert to the manual background hack.
Vanilla's implementation is evidently, still ill-suited.
1 parent f6dbb96 commit 9f581e0

File tree

1 file changed

+25
-47
lines changed

1 file changed

+25
-47
lines changed

src/main/java/dev/hephaestus/glowcase/client/render/block/entity/TextBlockEntityRenderer.java

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -3,28 +3,22 @@
33
import dev.hephaestus.glowcase.Glowcase;
44
import dev.hephaestus.glowcase.block.entity.TextBlockEntity;
55
import dev.hephaestus.glowcase.client.util.BlockEntityRenderUtil;
6+
import dev.hephaestus.glowcase.mixin.client.TextRendererAccessor;
67
import net.minecraft.client.MinecraftClient;
78
import net.minecraft.client.font.BakedGlyph;
89
import net.minecraft.client.font.TextRenderer;
910
import net.minecraft.client.font.TextRenderer.TextLayerType;
1011
import net.minecraft.client.render.LightmapTextureManager;
11-
import net.minecraft.client.render.VertexConsumer;
1212
import net.minecraft.client.render.VertexConsumerProvider;
1313
import net.minecraft.client.render.block.entity.BlockEntityRendererFactory;
1414
import net.minecraft.client.util.math.MatrixStack;
1515
import net.minecraft.entity.Entity;
1616
import net.minecraft.state.property.Properties;
17-
import net.minecraft.text.PlainTextContent;
17+
import net.minecraft.text.Style;
1818
import net.minecraft.text.Text;
1919
import net.minecraft.util.Identifier;
20-
import net.minecraft.util.math.MathHelper;
2120
import net.minecraft.util.math.RotationAxis;
2221
import net.minecraft.util.math.Vec3d;
23-
import org.jetbrains.annotations.NotNull;
24-
import org.joml.Matrix4f;
25-
import org.joml.Quaternionf;
26-
27-
import java.util.concurrent.atomic.AtomicBoolean;
2822

2923
public class TextBlockEntityRenderer extends BakedBlockEntityRenderer<TextBlockEntity> {
3024
public static Identifier ITEM_TEXTURE = Glowcase.id("textures/item/text_block.png");
@@ -125,18 +119,37 @@ public void renderBaked(TextBlockEntity entity, MatrixStack matrices, VertexCons
125119
double dX = switch (entity.textAlignment) {
126120
case LEFT -> -maxLength / 2D;
127121
case CENTER -> (maxLength - width) / 2D - maxLength / 2D;
128-
case CENTER_LEFT -> - (50D / entity.scale) - (width / 2D);
122+
case CENTER_LEFT -> -(50D / entity.scale) - (width / 2D);
129123
case CENTER_RIGHT -> (50D / entity.scale) - (width / 2D);
130124
case RIGHT -> maxLength - width - maxLength / 2D;
131125
};
132126

133127
matrices.push();
134128
matrices.translate(dX, 0, 0);
135129

136-
TextRenderer.Drawer drawer = (TextRenderer.Drawer) textRenderer.prepare(line.asOrderedText(), 0, i * 12, entity.color, entity.shadow, entity.backgroundColor);
130+
TextRenderer.Drawer drawer = (TextRenderer.Drawer) textRenderer.prepare(line.asOrderedText(), 0, i * 12, entity.color, entity.shadow, 0);
131+
132+
TextRenderer.GlyphDrawer glyphDrawer = TextRenderer.GlyphDrawer.drawing(
133+
vertexConsumers,
134+
matrices.peek().getPositionMatrix(),
135+
TextLayerType.NORMAL,
136+
// TODO: use the light param and add a toggle to make it glow (use LightmapTextureManager.MAX_LIGHT_COORDINATE)
137+
LightmapTextureManager.MAX_LIGHT_COORDINATE
138+
);
137139

138-
// TODO: use the light param and add a toggle to make it glow (use LightmapTextureManager.MAX_LIGHT_COORDINATE)
139-
TextRenderer.GlyphDrawer glyphDrawer = getGlyphDrawer(matrices, vertexConsumers, LightmapTextureManager.MAX_LIGHT_COORDINATE);
140+
// Yep, we're back to that hack again.
141+
if (entity.backgroundColor != 0) {
142+
BakedGlyph rectangleBakedGlyph = ((TextRendererAccessor) textRenderer)
143+
.invokeGetFontStorage(Style.DEFAULT_FONT_ID)
144+
.getRectangleBakedGlyph();
145+
146+
final BakedGlyph.Rectangle rect = new BakedGlyph.Rectangle(
147+
-4, i * 12 - 2f,
148+
(float) width + 4, (i + 1) * 12 - 2f,
149+
-0.01F, entity.backgroundColor);
150+
151+
glyphDrawer.drawRectangle(rectangleBakedGlyph, rect);
152+
}
140153

141154
drawer.draw(glyphDrawer);
142155

@@ -146,39 +159,4 @@ public void renderBaked(TextBlockEntity entity, MatrixStack matrices, VertexCons
146159
matrices.pop();
147160
}
148161

149-
private static TextRenderer.@NotNull GlyphDrawer getGlyphDrawer(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light) {
150-
return new TextRenderer.GlyphDrawer() {
151-
public void drawGlyph(BakedGlyph.DrawnGlyph glyph) {
152-
BakedGlyph bakedGlyph = glyph.glyph();
153-
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(bakedGlyph.getLayer(TextLayerType.NORMAL));
154-
bakedGlyph.draw(glyph, matrices.peek().getPositionMatrix(), vertexConsumer, light, false);
155-
}
156-
157-
public void drawRectangle(BakedGlyph bakedGlyph, BakedGlyph.Rectangle rect) {
158-
rect = new BakedGlyph.Rectangle(rect.minX() - 4, rect.minY() - 2, rect.maxX() + 4, rect.maxY() + 2, rect.zIndex(), rect.color(), rect.shadowColor(), rect.shadowOffset());
159-
VertexConsumer vertexConsumer = vertexConsumers.getBuffer(bakedGlyph.getLayer(TextLayerType.NORMAL));
160-
bakedGlyph.drawRectangle(rect, matrices.peek().getPositionMatrix(), vertexConsumer, light, false);
161-
}
162-
};
163-
}
164-
165-
@SuppressWarnings("SameParameterValue")
166-
private void drawFillRect(MatrixStack matrices, VertexConsumerProvider vcp, int x1, int y1, int x2, int y2, int color) {
167-
float red = (float) (color >> 16 & 255) / 255.0F;
168-
float green = (float) (color >> 8 & 255) / 255.0F;
169-
float blue = (float) (color & 255) / 255.0F;
170-
float alpha = (float) (color >> 24 & 255) / 255.0F;
171-
172-
// Horrible up to no good hack to get proper translucency sorting :3
173-
/*final GlyphRenderer renderer = ((TextRendererAccessor) MinecraftClient.getInstance().textRenderer)
174-
.invokeGetFontStorage(Style.DEFAULT_FONT_ID).getRectangleRenderer();
175-
176-
final RenderLayer renderLayer = renderer.getLayer(TextLayerType.NORMAL);
177-
final VertexConsumer consumer = vcp.getBuffer(renderLayer);
178-
final Matrix4f matrix = matrices.peek().getPositionMatrix();
179-
180-
renderer.drawRectangle(new GlyphRenderer.Rectangle(
181-
x1, y1, x2, y2, 0.2f, red, green, blue, alpha
182-
), matrix, consumer, LightmapTextureManager.MAX_LIGHT_COORDINATE);*/
183-
}
184162
}

0 commit comments

Comments
 (0)