mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-02-01 23:21:40 +01:00
Cleanup code
Prevents usages of RenderSystem#recordRenderCall
This commit is contained in:
parent
a18cd5ca0a
commit
7166646b56
@ -19,7 +19,6 @@
|
||||
|
||||
package de.florianmichael.viafabricplus.fixes;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.viafabricplus.event.*;
|
||||
import de.florianmichael.viafabricplus.fixes.data.EntityDimensionDiff;
|
||||
@ -29,9 +28,9 @@ import de.florianmichael.viafabricplus.fixes.versioned.classic.CPEAdditions;
|
||||
import de.florianmichael.viafabricplus.fixes.versioned.classic.GridItemSelectionScreen;
|
||||
import de.florianmichael.viafabricplus.fixes.versioned.visual.ArmorHudEmulation1_8;
|
||||
import de.florianmichael.viafabricplus.fixes.versioned.visual.FootStepParticle1_12_2;
|
||||
import de.florianmichael.viafabricplus.fixes.versioned.visual.UnicodeFontFix1_12_2;
|
||||
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.util.LanguageUtil;
|
||||
import de.florianmichael.viafabricplus.settings.impl.BedrockSettings;
|
||||
import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
|
||||
import de.florianmichael.viafabricplus.util.DataCustomPayload;
|
||||
@ -39,12 +38,9 @@ import net.minecraft.block.*;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
import net.minecraft.client.option.SimpleOption;
|
||||
import net.minecraft.client.resource.language.TranslationStorage;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.util.Language;
|
||||
import net.raphimc.viaaprilfools.api.AprilFoolsProtocolVersion;
|
||||
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
||||
import net.raphimc.viabedrock.protocol.data.ProtocolConstants;
|
||||
@ -81,12 +77,6 @@ public class ClientsideFixes {
|
||||
@ApiStatus.Internal
|
||||
public static int globalTablistIndex = 0;
|
||||
|
||||
/**
|
||||
* Older versions only had unicode font support for some languages and therefore servers are expecting the client
|
||||
* to use a unicode font, not using it on older versions can cause issues with wrong dimensions in chat components.
|
||||
*/
|
||||
private static boolean forcingUnicodeFont = false;
|
||||
|
||||
static {
|
||||
// Register additional CPE features
|
||||
CPEAdditions.modifyMappings();
|
||||
@ -94,6 +84,8 @@ public class ClientsideFixes {
|
||||
// Check if the pack format mappings are correct
|
||||
ResourcePackHeaderDiff.checkOutdated();
|
||||
|
||||
UnicodeFontFix1_12_2.init();
|
||||
|
||||
PostGameLoadCallback.EVENT.register(() -> {
|
||||
// Handle clientside enchantment calculations in <= 1.20.6
|
||||
EnchantmentAttributesEmulation1_20_6.init();
|
||||
@ -106,41 +98,36 @@ public class ClientsideFixes {
|
||||
});
|
||||
|
||||
// Reloads some clientside stuff when the protocol version changes
|
||||
ChangeProtocolVersionCallback.EVENT.register((oldVersion, newVersion) -> {
|
||||
MinecraftClient.getInstance().execute(() -> {
|
||||
VisualSettings.global().filterNonExistingGlyphs.onValueChanged();
|
||||
ChangeProtocolVersionCallback.EVENT.register((oldVersion, newVersion) -> MinecraftClient.getInstance().execute(() -> {
|
||||
VisualSettings.global().filterNonExistingGlyphs.onValueChanged();
|
||||
|
||||
// Reloads all bounding boxes of the blocks that we changed
|
||||
for (Block block : Registries.BLOCK) {
|
||||
if (block instanceof AnvilBlock || block instanceof BedBlock || block instanceof BrewingStandBlock
|
||||
|| block instanceof CarpetBlock || block instanceof CauldronBlock || block instanceof ChestBlock
|
||||
|| block instanceof EnderChestBlock || block instanceof EndPortalBlock || block instanceof EndPortalFrameBlock
|
||||
|| block instanceof FarmlandBlock || block instanceof FenceBlock || block instanceof FenceGateBlock
|
||||
|| block instanceof HopperBlock || block instanceof LadderBlock || block instanceof LeavesBlock
|
||||
|| block instanceof LilyPadBlock || block instanceof PaneBlock || block instanceof PistonBlock
|
||||
|| block instanceof PistonHeadBlock || block instanceof SnowBlock || block instanceof WallBlock
|
||||
|| block instanceof CropBlock || block instanceof FlowerbedBlock
|
||||
) {
|
||||
for (BlockState state : block.getStateManager().getStates()) {
|
||||
state.initShapeCache();
|
||||
}
|
||||
// Reloads all bounding boxes of the blocks that we changed
|
||||
for (Block block : Registries.BLOCK) {
|
||||
if (block instanceof AnvilBlock || block instanceof BedBlock || block instanceof BrewingStandBlock
|
||||
|| block instanceof CarpetBlock || block instanceof CauldronBlock || block instanceof ChestBlock
|
||||
|| block instanceof EnderChestBlock || block instanceof EndPortalBlock || block instanceof EndPortalFrameBlock
|
||||
|| block instanceof FarmlandBlock || block instanceof FenceBlock || block instanceof FenceGateBlock
|
||||
|| block instanceof HopperBlock || block instanceof LadderBlock || block instanceof LeavesBlock
|
||||
|| block instanceof LilyPadBlock || block instanceof PaneBlock || block instanceof PistonBlock
|
||||
|| block instanceof PistonHeadBlock || block instanceof SnowBlock || block instanceof WallBlock
|
||||
|| block instanceof CropBlock || block instanceof FlowerbedBlock
|
||||
) {
|
||||
for (BlockState state : block.getStateManager().getStates()) {
|
||||
state.initShapeCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Rebuilds the item selection screen grid
|
||||
if (newVersion.olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
|
||||
GridItemSelectionScreen.INSTANCE.itemGrid = null;
|
||||
}
|
||||
// Rebuilds the item selection screen grid
|
||||
if (newVersion.olderThanOrEqualTo(LegacyProtocolVersion.c0_28toc0_30)) {
|
||||
GridItemSelectionScreen.INSTANCE.itemGrid = null;
|
||||
}
|
||||
|
||||
// Reload sound system when switching between 3D Shareware and normal versions
|
||||
if (oldVersion.equals(AprilFoolsProtocolVersion.s3d_shareware) || newVersion.equals(AprilFoolsProtocolVersion.s3d_shareware)) {
|
||||
MinecraftClient.getInstance().getSoundManager().reloadSounds();
|
||||
}
|
||||
});
|
||||
|
||||
// Runs its own code already inside the game thread
|
||||
updateUnicodeFontOverride(newVersion);
|
||||
});
|
||||
// Reload sound system when switching between 3D Shareware and normal versions
|
||||
if (oldVersion.equals(AprilFoolsProtocolVersion.s3d_shareware) || newVersion.equals(AprilFoolsProtocolVersion.s3d_shareware)) {
|
||||
MinecraftClient.getInstance().getSoundManager().reloadSounds();
|
||||
}
|
||||
}));
|
||||
|
||||
// Register the footstep particle
|
||||
FootStepParticle1_12_2.init();
|
||||
@ -153,21 +140,6 @@ public class ClientsideFixes {
|
||||
// Calls the static block
|
||||
}
|
||||
|
||||
@ApiStatus.Internal
|
||||
public static void updateUnicodeFontOverride(final ProtocolVersion version) {
|
||||
final SimpleOption<Boolean> option = MinecraftClient.getInstance().options.getForceUnicodeFont();
|
||||
|
||||
if (VisualSettings.global().forceUnicodeFontForNonAsciiLanguages.isEnabled(version)) {
|
||||
if (Language.getInstance() instanceof TranslationStorage storage) {
|
||||
forcingUnicodeFont = LanguageUtil.isUnicodeFont1_12_2(storage.translations);
|
||||
RenderSystem.recordRenderCall(() -> option.setValue(forcingUnicodeFont));
|
||||
}
|
||||
} else if (forcingUnicodeFont) {
|
||||
RenderSystem.recordRenderCall(() -> option.setValue(false));
|
||||
forcingUnicodeFont = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculates the maximum chat length for the selected protocol version in {@link ProtocolTranslator#getTargetVersion()}
|
||||
*
|
||||
|
@ -0,0 +1,69 @@
|
||||
/*
|
||||
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
|
||||
* Copyright (C) 2021-2024 FlorianMichael/EnZaXD <florian.michael07@gmail.com> and RK_01/RaphiMC
|
||||
* Copyright (C) 2023-2024 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 de.florianmichael.viafabricplus.fixes.versioned.visual;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.viafabricplus.event.ChangeProtocolVersionCallback;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.util.LanguageUtil;
|
||||
import de.florianmichael.viafabricplus.settings.impl.VisualSettings;
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.option.SimpleOption;
|
||||
import net.minecraft.client.resource.language.TranslationStorage;
|
||||
import net.minecraft.util.Language;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
|
||||
/**
|
||||
* Older versions only had unicode font support for some languages and therefore servers are expecting the client
|
||||
* to use a unicode font, not using it on older versions can cause issues with wrong dimensions in chat components.
|
||||
*/
|
||||
@ApiStatus.Internal
|
||||
public class UnicodeFontFix1_12_2 {
|
||||
|
||||
private static boolean enabled = false;
|
||||
private static Runnable task = null;
|
||||
|
||||
public static void init() {
|
||||
ChangeProtocolVersionCallback.EVENT.register((oldVersion, newVersion) -> updateUnicodeFontOverride(newVersion));
|
||||
|
||||
ClientTickEvents.START_CLIENT_TICK.register(client -> {
|
||||
// Prevent usages of RenderSystem.recordRenderCall()
|
||||
if (task != null) {
|
||||
task.run();
|
||||
task = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static void updateUnicodeFontOverride(final ProtocolVersion version) {
|
||||
final SimpleOption<Boolean> option = MinecraftClient.getInstance().options.getForceUnicodeFont();
|
||||
|
||||
if (VisualSettings.global().forceUnicodeFontForNonAsciiLanguages.isEnabled(version)) {
|
||||
if (Language.getInstance() instanceof TranslationStorage storage) {
|
||||
enabled = LanguageUtil.isUnicodeFont1_12_2(storage.translations);
|
||||
task = () -> option.setValue(enabled);
|
||||
}
|
||||
} else if (enabled) {
|
||||
enabled = false;
|
||||
task = () -> option.setValue(false);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -19,7 +19,7 @@
|
||||
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft;
|
||||
|
||||
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
|
||||
import de.florianmichael.viafabricplus.fixes.versioned.visual.UnicodeFontFix1_12_2;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
import net.minecraft.client.resource.language.LanguageManager;
|
||||
import net.minecraft.resource.ResourceManager;
|
||||
@ -33,7 +33,7 @@ public abstract class MixinLanguageManager {
|
||||
|
||||
@Inject(method = "reload", at = @At("RETURN"))
|
||||
private void updateUnicodeFontOverride(ResourceManager manager, CallbackInfo ci) {
|
||||
ClientsideFixes.updateUnicodeFontOverride(ProtocolTranslator.getTargetVersion());
|
||||
UnicodeFontFix1_12_2.updateUnicodeFontOverride(ProtocolTranslator.getTargetVersion());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,8 +116,13 @@ public class VFPScreen extends Screen {
|
||||
*/
|
||||
public void open(final Screen prevScreen) {
|
||||
this.prevScreen = prevScreen;
|
||||
setScreen(this);
|
||||
}
|
||||
|
||||
RenderSystem.recordRenderCall(() -> MinecraftClient.getInstance().setScreen(this));
|
||||
public static void setScreen(final Screen screen) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
client.execute(() -> client.setScreen(screen));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -81,7 +81,7 @@ public class ClassiCubeLoginScreen extends VFPScreen {
|
||||
|
||||
@Override
|
||||
public void handleSuccessfulLogin(CCAccount account) {
|
||||
RenderSystem.recordRenderCall(() -> ClassiCubeServerListScreen.open(prevScreen, this));
|
||||
ClassiCubeServerListScreen.open(prevScreen, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -62,7 +62,7 @@ public class ClassiCubeMFAScreen extends VFPScreen {
|
||||
|
||||
@Override
|
||||
public void handleSuccessfulLogin(CCAccount account) {
|
||||
RenderSystem.recordRenderCall(() -> ClassiCubeServerListScreen.open(prevScreen, this));
|
||||
ClassiCubeServerListScreen.open(prevScreen, this);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -57,7 +57,7 @@ public class ClassiCubeServerListScreen extends VFPScreen {
|
||||
|
||||
ClassiCubeHandler.requestServerList(account, serverList -> {
|
||||
ClassiCubeServerListScreen.SERVER_LIST.addAll(serverList.servers());
|
||||
RenderSystem.recordRenderCall(() -> ClassiCubeServerListScreen.INSTANCE.open(prevScreen));
|
||||
ClassiCubeServerListScreen.INSTANCE.open(prevScreen);
|
||||
}, loginProcessHandler::handleException);
|
||||
}
|
||||
|
||||
|
@ -89,18 +89,18 @@ public class BedrockSettings extends SettingGroup {
|
||||
final Screen prevScreen = client.currentScreen;
|
||||
try {
|
||||
accountsSave.setBedrockAccount(MinecraftAuth.BEDROCK_DEVICE_CODE_LOGIN.getFromInput(GUI_LOGGER, MinecraftAuth.createHttpClient(), new StepMsaDeviceCode.MsaDeviceCodeCallback(msaDeviceCode -> {
|
||||
client.execute(() -> client.setScreen(new ConfirmScreen(copyUrl -> {
|
||||
VFPScreen.setScreen(new ConfirmScreen(copyUrl -> {
|
||||
if (copyUrl) {
|
||||
client.keyboard.setClipboard(msaDeviceCode.getDirectVerificationUri());
|
||||
} else {
|
||||
client.setScreen(prevScreen);
|
||||
Thread.currentThread().interrupt();
|
||||
}
|
||||
}, TITLE, Text.translatable("click_to_set_bedrock_account.viafabricplus.notice"), Text.translatable("base.viafabricplus.copy_link"), Text.translatable("base.viafabricplus.cancel"))));
|
||||
}, TITLE, Text.translatable("click_to_set_bedrock_account.viafabricplus.notice"), Text.translatable("base.viafabricplus.copy_link"), Text.translatable("base.viafabricplus.cancel")));
|
||||
Util.getOperatingSystem().open(msaDeviceCode.getDirectVerificationUri());
|
||||
})));
|
||||
|
||||
RenderSystem.recordRenderCall(() -> client.setScreen(prevScreen));
|
||||
VFPScreen.setScreen(prevScreen);
|
||||
} catch (Throwable e) {
|
||||
Thread.currentThread().interrupt();
|
||||
VFPScreen.showErrorScreen(TITLE, e, prevScreen);
|
||||
|
Loading…
Reference in New Issue
Block a user