Add setting for glyph filtering in <= 1.20

Closes https://github.com/ViaVersion/ViaFabricPlus/issues/492
This commit is contained in:
FlorianMichael 2024-08-15 12:55:45 +02:00
parent 552c4a6b0d
commit fe6f2618b1
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
6 changed files with 28 additions and 7 deletions

View File

@ -37,7 +37,6 @@ import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
import de.florianmichael.viafabricplus.util.DataCustomPayload;
import net.minecraft.block.*;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.FontStorage;
import net.minecraft.client.network.ClientPlayNetworkHandler;
import net.minecraft.client.network.ServerAddress;
import net.minecraft.client.option.SimpleOption;
@ -109,11 +108,7 @@ public class ClientsideFixes {
// Reloads some clientside stuff when the protocol version changes
ChangeProtocolVersionCallback.EVENT.register((oldVersion, newVersion) -> {
MinecraftClient.getInstance().execute(() -> {
// Clear all font caches to enforce a reload of all fonts (this is needed because we change the font renderer behavior)
for (FontStorage storage : MinecraftClient.getInstance().fontManager.fontStorages.values()) {
storage.glyphRendererCache.clear();
storage.glyphCache.clear();
}
VisualSettings.global().filterNonExistingGlyphs.onValueChanged();
// Reloads all bounding boxes of the blocks that we changed
for (Block block : Registries.BLOCK) {

View File

@ -87,7 +87,11 @@ public abstract class MixinFontStorage {
@Unique
private boolean viaFabricPlus$shouldBeInvisible(final int codePoint) {
return (this.id.equals(MinecraftClient.DEFAULT_FONT_ID) || this.id.equals(MinecraftClient.UNICODE_FONT_ID)) && !RenderableGlyphDiff.isGlyphRenderable(codePoint);
if (VisualSettings.global().filterNonExistingGlyphs.getValue()) {
return (this.id.equals(MinecraftClient.DEFAULT_FONT_ID) || this.id.equals(MinecraftClient.UNICODE_FONT_ID)) && !RenderableGlyphDiff.isGlyphRenderable(codePoint);
} else {
return false;
}
}
@Unique

View File

@ -60,6 +60,9 @@ public abstract class AbstractSetting<T> {
public abstract void write(final JsonObject object);
public abstract void read(final JsonObject object);
public void onValueChanged() {
}
public MutableText getName() {
return name;
}
@ -91,6 +94,7 @@ public abstract class AbstractSetting<T> {
public void setValue(T value) {
this.value = value;
onValueChanged();
}
public Text getTooltip() {

View File

@ -20,9 +20,12 @@
package de.florianmichael.viafabricplus.settings.impl;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import de.florianmichael.viafabricplus.settings.base.BooleanSetting;
import de.florianmichael.viafabricplus.settings.base.ModeSetting;
import de.florianmichael.viafabricplus.settings.base.SettingGroup;
import de.florianmichael.viafabricplus.settings.base.VersionedBooleanSetting;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.FontStorage;
import net.minecraft.text.Text;
import net.raphimc.vialegacy.api.LegacyProtocolVersion;
import net.raphimc.vialoader.util.VersionRange;
@ -36,6 +39,19 @@ public class VisualSettings extends SettingGroup {
Text.translatable("change_game_menu_screen_layout.viafabricplus.adjusted"),
Text.translatable("base.viafabricplus.off")
);
public final BooleanSetting filterNonExistingGlyphs = new BooleanSetting(this, Text.translatable("visual_settings.viafabricplus.filter_non_existing_glyphs"), true) {
@Override
public void onValueChanged() {
final MinecraftClient client = MinecraftClient.getInstance();
if (client != null) {
for (FontStorage storage : client.fontManager.fontStorages.values()) {
storage.glyphRendererCache.clear();
storage.glyphCache.clear();
}
}
}
};
// 1.21 -> 1.20.5
public final VersionedBooleanSetting hideDownloadTerrainScreenTransitionEffects = new VersionedBooleanSetting(this, Text.translatable("visual_settings.viafabricplus.hide_download_terrain_screen_transition_effects"), VersionRange.andOlder(ProtocolVersion.v1_20_5));

View File

@ -101,6 +101,7 @@
"visual_settings.viafabricplus.hide_crafting_recipe_book": "Bastelrezeptbuch verstecken",
"visual_settings.viafabricplus.hide_modern_jigsaw_screen_features": "Moderne Puzzle-Funktionen ausblenden",
"visual_settings.viafabricplus.force_unicode_font_for_non_ascii_languages": "Unicode-Schrift für nicht-ASCII-Sprachen erzwingen",
"visual_settings.viafabricplus.filter_non_existing_glyphs": "Nicht vorhandene Glyphen filtern",
"force_version.viafabricplus.title": "Version festlegen, mit der der Server gepingt/verbunden werden soll",

View File

@ -103,6 +103,7 @@
"visual_settings.viafabricplus.hide_crafting_recipe_book": "Hide crafting recipe book",
"visual_settings.viafabricplus.hide_modern_jigsaw_screen_features": "Hide modern Jigsaw screen features",
"visual_settings.viafabricplus.force_unicode_font_for_non_ascii_languages": "Force Unicode font for non-ASCII languages",
"visual_settings.viafabricplus.filter_non_existing_glyphs": "Filter non existing glyphs",
"force_version.viafabricplus.title": "Please select the version with which the server should be pinged/connected",