FlorianMichael 2023-06-02 17:34:56 +02:00
parent a251ff00c7
commit 6e19aa6534
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
7 changed files with 145 additions and 0 deletions

View File

@ -37,6 +37,7 @@ public class GeneralSettings extends SettingGroup {
public final BooleanSetting showExtraInformationInDebugHud = new BooleanSetting(this, Text.translatable("general.viafabricplus.extrainformation"), true);
public final BooleanSetting showClassicLoadingProgressInConnectScreen = new BooleanSetting(this, Text.translatable("general.viafabricplus.classicloading"), true);
public final BooleanSetting autoDetectVersion = new BooleanSetting(this, Text.translatable("general.viafabricplus.autodetect"), false);
public final BooleanSetting showAdvertisedServerVersion = new BooleanSetting(this, Text.translatable("general.viafabricplus.advertised"), true);
public GeneralSettings() {
super(Text.translatable("settings.viafabricplus.general"));

View File

@ -23,4 +23,10 @@ public interface IServerInfo {
VersionEnum viafabricplus_forcedVersion();
void viafabricplus_forceVersion(VersionEnum version);
boolean viafabricplus_enabled();
void viafabricplus_enable();
int viafabricplus_translatingVersion();
void viafabricplus_setTranslatingVersion(final int version);
}

View File

@ -0,0 +1,53 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD 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 de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
import de.florianmichael.viafabricplus.protocolhack.ProtocolHack;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.network.ClientConnection;
import net.minecraft.network.listener.ClientQueryPacketListener;
import net.minecraft.network.packet.s2c.query.QueryResponseS2CPacket;
import org.spongepowered.asm.mixin.Final;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(targets = "net.minecraft.client.network.MultiplayerServerListPinger$1")
public abstract class MixinMultiplayerServerListPinger_1 implements ClientQueryPacketListener {
@Final
@Shadow
ClientConnection field_3774;
@Final
@Shadow
ServerInfo field_3776;
@Inject(method = "onResponse(Lnet/minecraft/network/packet/s2c/query/QueryResponseS2CPacket;)V", at = @At("HEAD"))
public void trackTranslatingState(QueryResponseS2CPacket packet, CallbackInfo ci) {
if (field_3774.channel.hasAttr(ProtocolHack.LOCAL_VIA_CONNECTION)) {
((IServerInfo) field_3776).viafabricplus_enable();
final var userConnection = field_3774.channel.attr(ProtocolHack.LOCAL_VIA_CONNECTION).get();
((IServerInfo) field_3776).viafabricplus_setTranslatingVersion(userConnection.getProtocolInfo().getServerProtocolVersion());
}
}
}

View File

@ -0,0 +1,55 @@
/*
* This file is part of ViaFabricPlus - https://github.com/FlorianMichael/ViaFabricPlus
* Copyright (C) 2021-2023 FlorianMichael/EnZaXD 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 de.florianmichael.viafabricplus.injection.mixin.base;
import de.florianmichael.viafabricplus.base.settings.groups.GeneralSettings;
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
import net.minecraft.client.gui.screen.multiplayer.MultiplayerServerListWidget;
import net.minecraft.client.network.ServerInfo;
import net.minecraft.text.Text;
import net.raphimc.vialoader.util.VersionEnum;
import org.spongepowered.asm.mixin.Final;
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.Redirect;
import java.util.ArrayList;
import java.util.List;
@Mixin(MultiplayerServerListWidget.ServerEntry.class)
public class MixinMultiplayerServerListWidget_ServerEntry {
@Shadow @Final private ServerInfo server;
@Redirect(method = "render", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setMultiplayerScreenTooltip(Ljava/util/List;)V", ordinal = 0))
public void showTranslatingInformation(MultiplayerScreen instance, List<Text> tooltip) {
final List<Text> tooltipOverwrite = new ArrayList<>(tooltip);
if (GeneralSettings.INSTANCE.showAdvertisedServerVersion.getValue()) {
final IServerInfo accessor = ((IServerInfo) server);
if (accessor.viafabricplus_enabled()) {
final var versionEnum = VersionEnum.fromProtocolId(accessor.viafabricplus_translatingVersion());
tooltipOverwrite.add(Text.translatable("words.viafabricplus.translate", versionEnum != VersionEnum.UNKNOWN ? versionEnum.getName() + " (" + versionEnum.getVersion() + ")" : accessor.viafabricplus_translatingVersion()));
tooltipOverwrite.add(Text.of("Server version: " + server.version.getString() + " (" + server.protocolVersion + ")"));
}
}
instance.setMultiplayerScreenTooltip(tooltipOverwrite);
}
}

View File

@ -70,4 +70,30 @@ public class MixinServerInfo implements IServerInfo {
public void trackForcedVersion(ServerInfo serverInfo, CallbackInfo ci) {
viafabricplus_forceVersion(((IServerInfo) serverInfo).viafabricplus_forcedVersion());
}
@Unique
private boolean viafabricplus_enabled;
@Override
public boolean viafabricplus_enabled() {
return viafabricplus_enabled;
}
@Override
public void viafabricplus_enable() {
viafabricplus_enabled = true;
}
@Unique
private int viafabricplus_translatingVersion;
@Override
public int viafabricplus_translatingVersion() {
return viafabricplus_translatingVersion;
}
@Override
public void viafabricplus_setTranslatingVersion(int version) {
viafabricplus_translatingVersion = version;
}
}

View File

@ -13,6 +13,7 @@
"words.viafabricplus.reset": "Reset",
"words.viafabricplus.copy": "Copy code",
"words.viafabricplus.error": "Something went wrong! Please try again later",
"words.viafabricplus.translate": "Via translates to: %s",
"settings.viafabricplus.authentication": "Authentication",
"settings.viafabricplus.experimental": "Experimental",
@ -27,6 +28,7 @@
"general.viafabricplus.creative": "Remove not available items from creative tab",
"general.viafabricplus.protocolsync": "Automatically change Settings based on the current version",
"general.viafabricplus.autodetect": "Auto detect version",
"general.viafabricplus.advertised": "Show advertised/server version in Multiplayer",
"experimental.viafabricplus.chunkborderfix": "Fix Chunk borders",
"experimental.viafabricplus.watermovement": "Water movement edge detection",

View File

@ -16,6 +16,8 @@
"base.MixinMinecraftClient",
"base.MixinMultiplayerScreen",
"base.MixinMultiplayerServerListPinger",
"base.MixinMultiplayerServerListPinger_1",
"base.MixinMultiplayerServerListWidget_ServerEntry",
"base.MixinOptionsScreen",
"base.MixinServerInfo",
"base.MixinSharedConstants",