-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
blazingly fast bordered text renderer ⚡ #347
Open
RedthMC
wants to merge
8
commits into
Polyfrost:develop-v0
Choose a base branch
from
RedthMC:develop-v0
base: develop-v0
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4b1c58e
blazingly fast bordered text renderer ⚡
RedthMC 345db83
Update build.gradle.kts
RedthMC 97f8947
lol
RedthMC b51f8aa
added option & use mixin
RedthMC b3e46a6
bug fix
RedthMC 31f320d
another bug fix oops
RedthMC c797946
mixin moment
RedthMC 39ee456
mixin fix (?
RedthMC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
223 changes: 223 additions & 0 deletions
223
versions/src/main/java/cc/polyfrost/oneconfig/internal/mixin/FontRendererMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,223 @@ | ||
/* | ||
* This file is part of OneConfig. | ||
* OneConfig - Next Generation Config Library for Minecraft: Java Edition | ||
* Copyright (C) 2021~2023 Polyfrost. | ||
* <https://polyfrost.cc> <https://github.com/Polyfrost/> | ||
* | ||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | ||
* | ||
* OneConfig is licensed under the terms of version 3 of the GNU Lesser | ||
* General Public License as published by the Free Software Foundation, AND | ||
* under the Additional Terms Applicable to OneConfig, as published by Polyfrost, | ||
* either version 1.0 of the Additional Terms, or (at your option) any later | ||
* version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
* Lesser General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Lesser General Public | ||
* License. If not, see <https://www.gnu.org/licenses/>. You should | ||
* have also received a copy of the Additional Terms Applicable | ||
* to OneConfig, as published by Polyfrost. If not, see | ||
* <https://polyfrost.cc/legal/oneconfig/additional-terms> | ||
*/ | ||
|
||
//#if FORGE==1 && MC<=11202 | ||
package cc.polyfrost.oneconfig.internal.mixin; | ||
|
||
import cc.polyfrost.oneconfig.internal.config.Preferences; | ||
import cc.polyfrost.oneconfig.internal.renderer.BorderedTextRenderer; | ||
import cc.polyfrost.oneconfig.renderer.TextRenderer; | ||
import net.minecraft.client.gui.FontRenderer; | ||
import net.minecraft.util.ResourceLocation; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Constant; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.ModifyArg; | ||
import org.spongepowered.asm.mixin.injection.ModifyConstant; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
@Mixin(value = FontRenderer.class) | ||
public class FontRendererMixin { | ||
@Shadow | ||
protected float posX; | ||
|
||
@Shadow | ||
protected float posY; | ||
|
||
@Inject(method = "drawString(Ljava/lang/String;FFIZ)I", at = @At(value = "HEAD"), cancellable = true) | ||
private void cachedShadow(String text, float x, float y, int color, boolean dropShadow, CallbackInfoReturnable<Integer> cir) { | ||
if (Preferences.optimizedFontRenderer && dropShadow) { | ||
cir.setReturnValue((int) BorderedTextRenderer.INSTANCE.drawString(text, x, y, color, TextRenderer.TextType.SHADOW)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do not overwrite this whole method |
||
} | ||
} | ||
|
||
@ModifyConstant(method = "renderDefaultChar", constant = @Constant(floatValue = 128f)) | ||
private float asciiTextureSize(float constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return 144f; | ||
case FULL: | ||
return 160f; | ||
default: | ||
return constant; | ||
} | ||
} | ||
|
||
@Inject(method = "renderDefaultChar", at = @At("HEAD")) | ||
private void asciiShift(int ch, boolean italic, CallbackInfoReturnable<Float> cir) { | ||
if (BorderedTextRenderer.INSTANCE.getTextType() == TextRenderer.TextType.FULL) { | ||
posX -= 1; | ||
posY -= 1; | ||
} | ||
} | ||
|
||
@Inject(method = "renderDefaultChar", at = @At("TAIL")) | ||
private void asciiUnshift(CallbackInfoReturnable<Float> cir) { | ||
if (BorderedTextRenderer.INSTANCE.getTextType() == TextRenderer.TextType.FULL) { | ||
posX += 1; | ||
posY += 1; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "renderDefaultChar", constant = @Constant(intValue = 8)) | ||
private int asciiGlyphSize(int constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return 9; | ||
case FULL: | ||
return 10; | ||
default: | ||
return constant; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "renderDefaultChar", constant = @Constant(floatValue = 0.01f)) | ||
private float asciiGlyphWidth(float constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return constant - 1.0f; | ||
case FULL: | ||
return constant - 4.0f; | ||
default: | ||
return constant; | ||
} | ||
} | ||
@ModifyConstant(method = "renderDefaultChar", constant = @Constant(floatValue = 7.99f)) | ||
private float asciiPixelSize(float constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return 8.99f; | ||
case FULL: | ||
return 9.99f; | ||
default: | ||
return constant; | ||
} | ||
} | ||
|
||
@ModifyArg(method = "renderDefaultChar", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/FontRenderer;bindTexture(Lnet/minecraft/util/ResourceLocation;)V")) | ||
private ResourceLocation asciiTexture(ResourceLocation location) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return BorderedTextRenderer.INSTANCE.getAsciiTexture().getShadowed().getLocation(); | ||
case FULL: | ||
return BorderedTextRenderer.INSTANCE.getAsciiTexture().getBordered().getLocation(); | ||
default: | ||
return location; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "renderUnicodeChar", constant = @Constant(floatValue = 256f)) | ||
private float unicodeTextureSize(float constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return 272f; | ||
case FULL: | ||
return 320f; | ||
default: | ||
return constant; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "renderUnicodeChar", constant = {@Constant(intValue = 16, ordinal = 1), @Constant(intValue = 16, ordinal = 3)}) | ||
private int unicodeGlyphSize(int constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return 17; | ||
case FULL: | ||
return 20; | ||
default: | ||
return constant; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "renderUnicodeChar", constant = @Constant(floatValue = 0.02f)) | ||
private float unicodeGlyphWidth(float constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return constant - 1.0f; | ||
case FULL: | ||
return constant - 4.0f; | ||
default: | ||
return constant; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "renderUnicodeChar", constant = @Constant(floatValue = 15.98F)) | ||
private float unicodeGlyphHeight(float constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return 16.98f; | ||
case FULL: | ||
return 19.98f; | ||
default: | ||
return constant; | ||
} | ||
} | ||
|
||
@ModifyConstant(method = "renderUnicodeChar", constant = @Constant(floatValue = 7.99f)) | ||
private float unicodePixelSize(float constant) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
return 8.49f; | ||
case FULL: | ||
return 9.99f; | ||
default: | ||
return constant; | ||
} | ||
} | ||
|
||
@Inject(method = "getUnicodePageLocation", at = @At("HEAD"), cancellable = true) | ||
private void unicodeTexture(int page, CallbackInfoReturnable<ResourceLocation> cir) { | ||
switch (BorderedTextRenderer.INSTANCE.getTextType()) { | ||
case SHADOW: | ||
cir.setReturnValue(BorderedTextRenderer.INSTANCE.getUnicodeTexture()[page].getShadowed().getLocation()); | ||
break; | ||
case FULL: | ||
cir.setReturnValue(BorderedTextRenderer.INSTANCE.getUnicodeTexture()[page].getBordered().getLocation()); | ||
break; | ||
} | ||
} | ||
|
||
|
||
@Inject(method = "renderUnicodeChar", at = @At("HEAD")) | ||
private void unicodeShift(char ch, boolean italic, CallbackInfoReturnable<Float> cir) { | ||
if (BorderedTextRenderer.INSTANCE.getTextType() == TextRenderer.TextType.FULL) { | ||
posX -= 1f; | ||
posY -= 1f; | ||
} | ||
} | ||
|
||
@Inject(method = "renderUnicodeChar", at = @At("TAIL")) | ||
private void unicodeUnshift(CallbackInfoReturnable<Float> cir) { | ||
if (BorderedTextRenderer.INSTANCE.getTextType() == TextRenderer.TextType.FULL) { | ||
posX += 1f; | ||
posY += 1f; | ||
} | ||
} | ||
} | ||
//#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
transfer all of this to a patcher font renderer mixin as well