Skip to content

Commit

Permalink
Merge font rendering changes again, overall cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianMichael committed Jan 8, 2025
1 parent 6f328e5 commit 18d9d59
Show file tree
Hide file tree
Showing 26 changed files with 136 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import com.viaversion.viafabricplus.features.entity.attribute.EnchantmentAttributesEmulation1_20_6;
import com.viaversion.viafabricplus.features.footstep_particle.FootStepParticle1_12_2;
import com.viaversion.viafabricplus.features.networking.resource_pack_header.ResourcePackHeaderDiff;
import com.viaversion.viafabricplus.features.font.replace_blank_glyph.FontCacheReload;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.MinecraftClient;

Expand Down Expand Up @@ -65,6 +66,9 @@ public final class FeaturesLoading {
// Reloads all bounding boxes of the blocks that we changed
CollisionShapes.reloadBlockShapes();

// Clears the font cache to replace the empty glyph
FontCacheReload.reload();

// Reloads the clientside recipes
if (newVersion.olderThanOrEqualTo(ProtocolVersion.v1_11_1)) {
Recipes1_11_2.reset();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.visuals.features.filter_non_existing_characters;
package com.viaversion.viafabricplus.features.font.filter_non_existing_characters;

import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features.replace_blank_glyph;
package com.viaversion.viafabricplus.features.font.replace_blank_glyph;

import net.minecraft.client.font.BakedGlyph;
import net.minecraft.client.font.Glyph;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
* This file is part of ViaFabricPlus - https://github.com/ViaVersion/ViaFabricPlus
* Copyright (C) 2021-2025 the original authors
* - FlorianMichael/EnZaXD <[email protected]>
* - RK_01/RaphiMC
* Copyright (C) 2023-2025 ViaVersion and contributors
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.features.font.replace_blank_glyph;

import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.FontStorage;

public final class FontCacheReload {

public static void reload() {
final MinecraftClient client = MinecraftClient.getInstance();
if (client != null) {
for (FontStorage storage : client.fontManager.fontStorages.values()) {
storage.bakedGlyphCache.clear();
storage.glyphCache.clear();
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,18 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.viaversion.viafabricplus.injection.mixin.features.replace_blank_glyph;
package com.viaversion.viafabricplus.injection.mixin.features.font;

import com.viaversion.viafabricplus.features.replace_blank_glyph.BuiltinEmptyGlyph1_12_2;
import com.viaversion.viafabricplus.ViaFabricPlus;
import com.viaversion.viafabricplus.features.font.filter_non_existing_characters.RenderableGlyphDiff;
import com.viaversion.viafabricplus.features.font.replace_blank_glyph.BuiltinEmptyGlyph1_12_2;
import com.viaversion.viafabricplus.protocoltranslator.ProtocolTranslator;
import com.viaversion.viafabricplus.settings.impl.DebugSettings;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.font.*;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
Expand All @@ -39,18 +45,35 @@ public abstract class MixinFontStorage {

@Shadow
private BakedGlyph blankBakedGlyph;

@Shadow
protected abstract BakedGlyph bake(RenderableGlyph c);

@Final
private Identifier id;
@Unique
private BakedGlyph viaFabricPlus$blankBakedGlyph1_12_2;

@Shadow
protected abstract BakedGlyph bake(RenderableGlyph c);

@Inject(method = "clear", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/font/BuiltinEmptyGlyph;bake(Ljava/util/function/Function;)Lnet/minecraft/client/font/BakedGlyph;", ordinal = 0))
private void bakeBlankGlyph1_12_2(CallbackInfo ci) {
this.viaFabricPlus$blankBakedGlyph1_12_2 = BuiltinEmptyGlyph1_12_2.INSTANCE.bake(this::bake);
}

@Inject(method = "findGlyph", at = @At("RETURN"), cancellable = true)
private void filterGlyphs(int codePoint, CallbackInfoReturnable<FontStorage.GlyphPair> cir) {
if (this.viaFabricPlusVisuals$shouldBeInvisible(codePoint)) {
cir.setReturnValue(this.viaFabricPlus$getBlankGlyphPair());
}
}

@Inject(method = "bake(I)Lnet/minecraft/client/font/BakedGlyph;", at = @At("RETURN"), cancellable = true)
private void filterBakedGlyph(int codePoint, CallbackInfoReturnable<BakedGlyph> cir) {
if (this.viaFabricPlusVisuals$shouldBeInvisible(codePoint)) {
cir.setReturnValue(this.viaFabricPlus$getBlankBakedGlyph());
}
}


@Inject(method = "findGlyph", at = @At("RETURN"), cancellable = true)
private void fixBlankGlyph1_12_2(int codePoint, CallbackInfoReturnable<FontStorage.GlyphPair> cir) {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
Expand All @@ -61,11 +84,30 @@ private void fixBlankGlyph1_12_2(int codePoint, CallbackInfoReturnable<FontStora
}
}


@Redirect(method = "bake(I)Lnet/minecraft/client/font/BakedGlyph;", at = @At(value = "FIELD", target = "Lnet/minecraft/client/font/FontStorage;blankBakedGlyph:Lnet/minecraft/client/font/BakedGlyph;"))
private BakedGlyph fixBlankBakedGlyph1_12_2(FontStorage instance) {
return this.viaFabricPlus$getBlankBakedGlyph();
}

@Unique
private boolean viaFabricPlusVisuals$shouldBeInvisible(final int codePoint) {
if (DebugSettings.INSTANCE.filterNonExistingGlyphs.getValue()) {
return (this.id.equals(MinecraftClient.DEFAULT_FONT_ID) || this.id.equals(MinecraftClient.UNICODE_FONT_ID)) && !RenderableGlyphDiff.isGlyphRenderable(codePoint);
} else {
return false;
}
}

@Unique
private FontStorage.GlyphPair viaFabricPlus$getBlankGlyphPair() {
if (ViaFabricPlus.getImpl().getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_21_2)) {
return new FontStorage.GlyphPair(BuiltinEmptyGlyph1_12_2.INSTANCE, BuiltinEmptyGlyph1_12_2.INSTANCE);
} else {
return FontStorage.GlyphPair.MISSING;
}
}

@Unique
private BakedGlyph viaFabricPlus$getBlankBakedGlyph() {
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import com.viaversion.viafabricplus.api.settings.SettingGroup;
import com.viaversion.viafabricplus.api.settings.type.BooleanSetting;
import com.viaversion.viafabricplus.api.settings.type.VersionedBooleanSetting;
import com.viaversion.viafabricplus.features.font.replace_blank_glyph.FontCacheReload;
import com.viaversion.vialoader.util.VersionRange;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.text.Text;
Expand All @@ -37,6 +38,12 @@ public final class DebugSettings extends SettingGroup {
public final BooleanSetting printNetworkingErrorsToLogs = new BooleanSetting(this, Text.translatable("debug_settings.viafabricplus.print_networking_errors_to_logs"), true);
public final BooleanSetting ignoreFabricSyncErrors = new BooleanSetting(this, Text.translatable("debug_settings.viafabricplus.ignore_fabric_sync_errors"), false);
public final BooleanSetting hideModernJigsawScreenFeatures = new BooleanSetting(this, Text.translatable("debug_settings.viafabricplus.hide_modern_jigsaw_screen_features"), true);
public final BooleanSetting filterNonExistingGlyphs = new BooleanSetting(this, Text.translatable("debug_settings.viafabricplus.filter_non_existing_glyphs"), true) {
@Override
public void onValueChanged() {
FontCacheReload.reload();
}
};

// 1.20.5 -> 1.20.4
public final VersionedBooleanSetting dontCreatePacketErrorCrashReports = new VersionedBooleanSetting(this, Text.translatable("debug_settings.viafabricplus.dont_create_packet_error_crash_reports"), VersionRange.andOlder(ProtocolVersion.v1_20_3));
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/viafabricplus/lang/de_de.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"debug_settings.viafabricplus.hide_modern_command_block_screen_features": "Moderne Befehlsblock-Bildschirmfunktionen ausblenden",
"debug_settings.viafabricplus.disable_server_pinging": "Server-Pinging deaktivieren",
"debug_settings.viafabricplus.hide_modern_jigsaw_screen_features": "Moderne Verbundblock-Bildschirmeigenschaften ausblenden",
"debug_settings.viafabricplus.filter_non_existing_glyphs": "Nicht vorhandene Glyphen filtern",

"authentication_settings.viafabricplus.use_beta_craft_authentication": "BetaCraft-Authentifizierung verwenden",
"authentication_settings.viafabricplus.verify_session_for_online_mode": "Sitzung für Server im Online-Modus verifizieren",
Expand All @@ -103,7 +104,6 @@
"visual_settings.viafabricplus.hide_furnace_recipe_book": "Ofenrezeptbuch ausblenden",
"visual_settings.viafabricplus.hide_crafting_recipe_book": "Handwerksrezeptbuch ausblenden",
"visual_settings.viafabricplus.force_unicode_font_for_non_ascii_languages": "Unicode-Schriftart für Nicht-ASCII-Sprachen erzwingen",
"visual_settings.viafabricplus.filter_non_existing_glyphs": "Nicht vorhandene Glyphen filtern",
"visual_settings.viafabricplus.sneak_instantly": "Sofort schleichen",
"visual_settings.viafabricplus.change_body_rotation_interpolation": "Interpolation der Körperdrehung ändern",

Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/assets/viafabricplus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"debug_settings.viafabricplus.emulate_armor_hud": "Emulate armor HUD",
"debug_settings.viafabricplus.hide_modern_command_block_screen_features": "Hide modern command block screen features",
"debug_settings.viafabricplus.disable_server_pinging": "Disable server pinging",
"debug_settings.viafabricplus.filter_non_existing_glyphs": "Filter non existing glyphs",

"authentication_settings.viafabricplus.use_beta_craft_authentication": "Use BetaCraft authentication",
"authentication_settings.viafabricplus.verify_session_for_online_mode": "Verify session for online mode servers",
Expand All @@ -103,7 +104,6 @@
"visual_settings.viafabricplus.hide_furnace_recipe_book": "Hide furnace recipe book",
"visual_settings.viafabricplus.hide_crafting_recipe_book": "Hide crafting recipe book",
"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",
"visual_settings.viafabricplus.sneak_instantly": "Sneak instantly",
"visual_settings.viafabricplus.lock_blocking_arm_rotation": "Lock third-person arm rotation whilst blocking",
"visual_settings.viafabricplus.change_body_rotation_interpolation": "Change body rotation interpolation",
Expand Down
12 changes: 6 additions & 6 deletions src/main/resources/assets/viafabricplus/lang/ja_jp.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,12 @@
"debug_settings.viafabricplus.print_networking_errors_to_logs": "ネットワークエラーをログに出力",
"debug_settings.viafabricplus.dont_create_packet_error_crash_reports": "パケットエラークラッシュレポートを作成しない",
"debug_settings.viafabricplus.ignore_fabric_sync_errors": "ファブリック同期エラーを無視する",
"debug_settings.viafabricplus.legacy_tab_completions": "古いタブ補完",
"debug_settings.viafabricplus.legacy_tab_completions": "古いタブ補完",
"debug_settings.viafabricplus.emulate_armor_hud": "アーマーのHUDをエミュレート",
"debug_settings.viafabricplus.hide_modern_command_block_screen_features": "コマンドブロック画面から新機能を削除",
"debug_settings.viafabricplus.disable_server_pinging": "サーバーへのpingを無効化",
"debug_settings.viafabricplus.hide_modern_jigsaw_screen_features": "最新のジグソー画面機能を非表示",
"debug_settings.viafabricplus.filter_non_existing_glyphs": "存在しないグリフをフィルタリング",

"authentication_settings.viafabricplus.use_beta_craft_authentication": "BetaCraft認証を使用",
"authentication_settings.viafabricplus.verify_session_for_online_mode": "オンラインモードサーバーのセッションを検証",
Expand All @@ -88,22 +93,17 @@
"visual_settings.viafabricplus.hide_download_terrain_screen_transition_effects": "ダウンロード地形画面遷移効果を非表示",
"visual_settings.viafabricplus.replace_petrified_oak_slab": "石化したオークのハーフブロックを「不明」なテクスチャに置換",
"visual_settings.viafabricplus.always_render_crosshair": "常にクロスヘアを描写",
"visual_settings.viafabricplus.emulate_armor_hud": "アーマーのHUDをエミュレート",
"visual_settings.viafabricplus.hide_modern_command_block_screen_features": "コマンドブロック画面から新機能を削除",
"visual_settings.viafabricplus.replace_hurt_sound_with_oof_sound": "ダメージ音をオゥに置換",
"visual_settings.viafabricplus.hide_modern_hud_elements": "新しいHUD要素を削除",
"visual_settings.viafabricplus.replace_creative_inventory_with_classic_inventory": "クリエイティブインベントリを置換",
"visual_settings.viafabricplus.old_walking_animation": "古いウォーキングアニメーション",
"visual_settings.viafabricplus.swing_hand_on_item_use": "アイテム使用時に手を振る",
"visual_settings.viafabricplus.disable_server_pinging": "サーバーへのpingを無効化",
"visual_settings.viafabricplus.sideways_backwards_walking": "横向き後方歩行",
"visual_settings.viafabricplus.enable_legacy_tablist": "古いタブリストを有効化",
"visual_settings.viafabricplus.tilt_item_positions": "タイトルアイテムの位置",
"visual_settings.viafabricplus.hide_furnace_recipe_book": "かまどのレシピブックを非表示",
"visual_settings.viafabricplus.hide_crafting_recipe_book": "クラフトレシピブックを非表示",
"visual_settings.viafabricplus.hide_modern_jigsaw_screen_features": "最新のジグソー画面機能を非表示",
"visual_settings.viafabricplus.force_unicode_font_for_non_ascii_languages": "非ASCII言語にUnicodeフォントを強制",
"visual_settings.viafabricplus.filter_non_existing_glyphs": "存在しないグリフをフィルタリング",
"visual_settings.viafabricplus.sneak_instantly": "即座にスニーク",
"visual_settings.viafabricplus.lock_blocking_arm_rotation": "ブロック中の三人称の腕の回転を固定",
"visual_settings.viafabricplus.change_body_rotation_interpolation": "ボディ回転補間を変更",
Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/assets/viafabricplus/lang/ko_kr.json
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@
"debug_settings.viafabricplus.dont_create_packet_error_crash_reports": "패킷 오류로 인한 충돌 보고서 생성하지 않기",
"debug_settings.viafabricplus.ignore_fabric_sync_errors": "페브릭 동기화 오류 무시",
"debug_settings.viafabricplus.legacy_tab_completions": "레거시 탭 자동 완성",
"debug_settings.viafabricplus.emulate_armor_hud": "갑옷 HUD 추가",
"debug_settings.viafabricplus.hide_modern_command_block_screen_features": "새로운 명령 블록 기능 숨기기",
"debug_settings.viafabricplus.disable_server_pinging": "서버 핑 비활성화",
"debug_settings.viafabricplus.hide_modern_jigsaw_screen_features": "최신 직소 화면 기능 숨기기",
"debug_settings.viafabricplus.filter_non_existing_glyphs": "존재하지 않는 글자 제거",

"authentication_settings.viafabricplus.use_beta_craft_authentication": "BetaCraft 인증 사용",
"authentication_settings.viafabricplus.verify_session_for_online_mode": "온라인 모드 서버에 대한 세션 검증",
Expand All @@ -88,22 +93,17 @@
"visual_settings.viafabricplus.hide_download_terrain_screen_transition_effects": "지형 다운로드 화면 전환 효과 숨기기",
"visual_settings.viafabricplus.replace_petrified_oak_slab": "규화한 참나무 반 블록 텍스처를 'unknown' 으로 바꾸기",
"visual_settings.viafabricplus.always_render_crosshair": "조준점 항상 보이기",
"visual_settings.viafabricplus.emulate_armor_hud": "갑옷 HUD 추가",
"visual_settings.viafabricplus.hide_modern_command_block_screen_features": "새로운 명령 블록 기능 숨기기",
"visual_settings.viafabricplus.replace_hurt_sound_with_oof_sound": "다칠 떄 나는 소리를 OOF 소리로 변경",
"visual_settings.viafabricplus.hide_modern_hud_elements": "새로운 HUD 요소 숨기기",
"visual_settings.viafabricplus.replace_creative_inventory_with_classic_inventory": "크리에이티브 인벤토리를 클래식으로 바꾸기",
"visual_settings.viafabricplus.old_walking_animation": "예전 걷기 에니메이션",
"visual_settings.viafabricplus.swing_hand_on_item_use": "블럭 치는 에니메이션 허용",
"visual_settings.viafabricplus.disable_server_pinging": "서버 핑 비활성화",
"visual_settings.viafabricplus.sideways_backwards_walking": "옆과 뒤로 걷기",
"visual_settings.viafabricplus.enable_legacy_tablist": "레거시 탭 리스트 허용",
"visual_settings.viafabricplus.tilt_item_positions": "손에 든 아이템 기울이기",
"visual_settings.viafabricplus.hide_furnace_recipe_book": "화로 제작법 책 숨기기",
"visual_settings.viafabricplus.hide_crafting_recipe_book": "제작대 제작법 책 숨기기",
"visual_settings.viafabricplus.hide_modern_jigsaw_screen_features": "최신 직소 화면 기능 숨기기",
"visual_settings.viafabricplus.force_unicode_font_for_non_ascii_languages": "ASCII가 아닌 언어에 유니코드 글꼴 강제 적용",
"visual_settings.viafabricplus.filter_non_existing_glyphs": "존재하지 않는 글자 제거",
"visual_settings.viafabricplus.sneak_instantly": "즉시 웅크리기",
"visual_settings.viafabricplus.lock_blocking_arm_rotation": "방어하는 동안 3인칭 팔 회전 막기",
"visual_settings.viafabricplus.change_body_rotation_interpolation": "몸체 회전 보간 방법 바꾸기",
Expand Down
Loading

0 comments on commit 18d9d59

Please sign in to comment.