Skip to content

Commit

Permalink
[1.21.3] Fix nametag rendering and optional text filtering (#1604)
Browse files Browse the repository at this point in the history
  • Loading branch information
XFactHD authored Nov 10, 2024
1 parent 9f4b630 commit 82eddb0
Show file tree
Hide file tree
Showing 6 changed files with 156 additions and 117 deletions.
44 changes: 40 additions & 4 deletions patches/net/minecraft/client/gui/Font.java.patch
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,48 @@
private static final float EFFECT_DEPTH = 0.01F;
private static final Vector3f SHADOW_OFFSET = new Vector3f(0.0F, 0.0F, 0.03F);
public static final int ALPHA_CUTOFF = 8;
@@ -309,6 +_,8 @@
public StringSplitter getSplitter() {
@@ -42,6 +_,8 @@
private final Function<ResourceLocation, FontSet> fonts;
final boolean filterFishyGlyphs;
private final StringSplitter splitter;
+ /** Neo: enables linear filtering on text */
+ public boolean enableTextTextureLinearFiltering = false;

public Font(Function<ResourceLocation, FontSet> p_243253_, boolean p_243245_) {
this.fonts = p_243253_;
@@ -310,6 +_,8 @@
return this.splitter;
}
+
+ @Override public Font self() { return this; }

+ @Override public Font self() { return this; }
+
@OnlyIn(Dist.CLIENT)
public static enum DisplayMode {
NORMAL,
@@ -417,7 +_,7 @@
p_381032_ - 1.0F, this.y + 9.0F, this.x, this.y - 1.0F, this.getUnderTextEffectDepth(), this.backgroundColor
);
bakedglyph = Font.this.getFontSet(Style.DEFAULT_FONT).whiteGlyph();
- VertexConsumer vertexconsumer = this.bufferSource.getBuffer(bakedglyph.renderType(this.mode));
+ VertexConsumer vertexconsumer = this.bufferSource.getBuffer(bakedglyph.renderType(this.mode, Font.this.enableTextTextureLinearFiltering));
bakedglyph.renderEffect(bakedglyph$effect, this.pose, vertexconsumer, this.packedLightCoords);
}

@@ -427,7 +_,7 @@
bakedglyph = Font.this.getFontSet(Style.DEFAULT_FONT).whiteGlyph();
}

- VertexConsumer vertexconsumer1 = this.bufferSource.getBuffer(bakedglyph.renderType(this.mode));
+ VertexConsumer vertexconsumer1 = this.bufferSource.getBuffer(bakedglyph.renderType(this.mode, Font.this.enableTextTextureLinearFiltering));

for (BakedGlyph.Effect bakedglyph$effect1 : this.effects) {
bakedglyph.renderEffect(bakedglyph$effect1, this.pose, vertexconsumer1, this.packedLightCoords);
@@ -440,7 +_,7 @@
void renderCharacters() {
for (BakedGlyph.GlyphInstance bakedglyph$glyphinstance : this.glyphInstances) {
BakedGlyph bakedglyph = bakedglyph$glyphinstance.glyph();
- VertexConsumer vertexconsumer = this.bufferSource.getBuffer(bakedglyph.renderType(this.mode));
+ VertexConsumer vertexconsumer = this.bufferSource.getBuffer(bakedglyph.renderType(this.mode, Font.this.enableTextTextureLinearFiltering));
bakedglyph.renderChar(bakedglyph$glyphinstance, this.pose, vertexconsumer, this.packedLightCoords);
}
}
50 changes: 50 additions & 0 deletions patches/net/minecraft/client/gui/font/GlyphRenderTypes.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
--- a/net/minecraft/client/gui/font/GlyphRenderTypes.java
+++ b/net/minecraft/client/gui/font/GlyphRenderTypes.java
@@ -7,22 +_,42 @@
import net.neoforged.api.distmarker.OnlyIn;

@OnlyIn(Dist.CLIENT)
-public record GlyphRenderTypes(RenderType normal, RenderType seeThrough, RenderType polygonOffset) {
+public record GlyphRenderTypes(RenderType normal, RenderType seeThrough, RenderType polygonOffset, RenderType normalBlur, RenderType seeThroughBlur, RenderType polygonOffsetBlur) {
+ /** @deprecated Neo: Use {@link GlyphRenderTypes(RenderType,RenderType,RenderType,RenderType,RenderType,RenderType)} instead */
+ @Deprecated
+ public GlyphRenderTypes(RenderType normal, RenderType seeThrough, RenderType polygonOffset) {
+ this(normal, seeThrough, polygonOffset, normal, seeThrough, polygonOffset);
+ }
+
public static GlyphRenderTypes createForIntensityTexture(ResourceLocation p_285411_) {
return new GlyphRenderTypes(
RenderType.textIntensity(p_285411_), RenderType.textIntensitySeeThrough(p_285411_), RenderType.textIntensityPolygonOffset(p_285411_)
+ , net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextIntensityFiltered(p_285411_),
+ net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextIntensitySeeThroughFiltered(p_285411_),
+ net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextIntensityPolygonOffsetFiltered(p_285411_)
);
}

public static GlyphRenderTypes createForColorTexture(ResourceLocation p_285486_) {
- return new GlyphRenderTypes(RenderType.text(p_285486_), RenderType.textSeeThrough(p_285486_), RenderType.textPolygonOffset(p_285486_));
+ return new GlyphRenderTypes(RenderType.text(p_285486_), RenderType.textSeeThrough(p_285486_), RenderType.textPolygonOffset(p_285486_),
+ net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextFiltered(p_285486_),
+ net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextSeeThroughFiltered(p_285486_),
+ net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextPolygonOffsetFiltered(p_285486_)
+ );
}

public RenderType select(Font.DisplayMode p_285259_) {
+ return this.select(p_285259_, false);
+ }
+
+ /**
+ * Neo: returns the {@link RenderType} to use for the given {@link Font.DisplayMode} and blur setting
+ */
+ public RenderType select(Font.DisplayMode p_285259_, boolean blur) {
return switch (p_285259_) {
- case NORMAL -> this.normal;
- case SEE_THROUGH -> this.seeThrough;
- case POLYGON_OFFSET -> this.polygonOffset;
+ case NORMAL -> blur ? this.normalBlur : this.normal;
+ case SEE_THROUGH -> blur ? this.seeThroughBlur : this.seeThrough;
+ case POLYGON_OFFSET -> blur ? this.polygonOffsetBlur : this.polygonOffset;
};
}
}
18 changes: 18 additions & 0 deletions patches/net/minecraft/client/gui/font/glyphs/BakedGlyph.java.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
--- a/net/minecraft/client/gui/font/glyphs/BakedGlyph.java
+++ b/net/minecraft/client/gui/font/glyphs/BakedGlyph.java
@@ -75,6 +_,15 @@
p_95223_.addVertex(p_254370_, p_95221_.x0, p_95221_.y1, p_95221_.depth).setColor(p_95221_.color).setUv(this.u1, this.v0).setLight(p_95224_);
}

+ /**
+ * Neo: returns the {@link RenderType} to use for the given {@link Font.DisplayMode} and blur setting
+ */
+ public RenderType renderType(Font.DisplayMode p_181388_, boolean blur) {
+ return this.renderTypes.select(p_181388_, blur);
+ }
+
+ /** @deprecated Neo: Use {@link #renderType(Font.DisplayMode, boolean)} instead */
+ @Deprecated
public RenderType renderType(Font.DisplayMode p_181388_) {
return this.renderTypes.select(p_181388_);
}
49 changes: 3 additions & 46 deletions patches/net/minecraft/client/renderer/RenderType.java.patch
Original file line number Diff line number Diff line change
@@ -1,52 +1,9 @@
--- a/net/minecraft/client/renderer/RenderType.java
+++ b/net/minecraft/client/renderer/RenderType.java
@@ -1098,7 +_,7 @@
}

public static RenderType text(ResourceLocation p_110498_) {
- return TEXT.apply(p_110498_);
+ return net.neoforged.neoforge.client.NeoForgeRenderTypes.getText(p_110498_);
}

public static RenderType textBackground() {
@@ -1106,19 +_,19 @@
}

public static RenderType textIntensity(ResourceLocation p_173238_) {
- return TEXT_INTENSITY.apply(p_173238_);
+ return net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextIntensity(p_173238_);
}

public static RenderType textPolygonOffset(ResourceLocation p_181445_) {
- return TEXT_POLYGON_OFFSET.apply(p_181445_);
+ return net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextPolygonOffset(p_181445_);
}

public static RenderType textIntensityPolygonOffset(ResourceLocation p_181447_) {
- return TEXT_INTENSITY_POLYGON_OFFSET.apply(p_181447_);
+ return net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextIntensityPolygonOffset(p_181447_);
}

public static RenderType textSeeThrough(ResourceLocation p_110501_) {
- return TEXT_SEE_THROUGH.apply(p_110501_);
+ return net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextSeeThrough(p_110501_);
}

public static RenderType textBackgroundSeeThrough() {
@@ -1126,7 +_,7 @@
}

public static RenderType textIntensitySeeThrough(ResourceLocation p_173241_) {
- return TEXT_INTENSITY_SEE_THROUGH.apply(p_173241_);
+ return net.neoforged.neoforge.client.NeoForgeRenderTypes.getTextIntensitySeeThrough(p_173241_);
}

public static RenderType lightning() {
@@ -1622,5 +_,17 @@
public String toString() {
@@ -1623,4 +_,16 @@
return this.name;
}
+ }
}
+
+ // Neo: Assign internal IDs for RenderType to be used in rendering
+ private int chunkLayerId = -1;
Expand All @@ -58,5 +15,5 @@
+ int i = 0;
+ for (var layer : chunkBufferLayers())
+ layer.chunkLayerId = i++;
}
+ }
}
Loading

0 comments on commit 82eddb0

Please sign in to comment.