Show protocol version and advertised version in server listing (#240)

Backport showing protocol version to 1.16, 1.15 and 1.14
This commit is contained in:
adryd 2023-05-07 17:30:05 -04:00 committed by GitHub
parent a2c103c6a1
commit 685efbcddc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
17 changed files with 343 additions and 8 deletions

View File

@ -7,7 +7,7 @@
"gui.viafabric_config.title": "ViaFabric Configurations",
"gui.client_side.enable": "Enable client-side",
"gui.client_side.disable": "Disable client-side",
"gui.ping_version.translated": "VIA: %s",
"gui.ping_version.translated": "VIA: %s (%s)",
"gui.hide_via_button.enable": "Hide VIA button",
"gui.hide_via_button.disable": "Show VIA button",
"gui.via_button": "VIA"

View File

@ -0,0 +1,34 @@
package com.viaversion.fabric.mc114.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc114.mixin.debug.client.MixinClientConnectionAccessor;
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.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
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 MixinMultiplayerServerListPingerListener implements ClientQueryPacketListener {
@Accessor
abstract ClientConnection getField_3774(); // Synthetic
@Accessor
abstract ServerInfo getField_3776(); // Synthetic
@Inject(method = "onResponse", at = @At(value = "HEAD"))
private void onResponseCaptureServerInfo(QueryResponseS2CPacket packet, CallbackInfo ci) {
FabricDecodeHandler decoder = ((MixinClientConnectionAccessor) this.getField_3774()).getChannel()
.pipeline().get(FabricDecodeHandler.class);
if (decoder != null) {
((ViaServerInfo) getField_3776()).setViaTranslating(decoder.getInfo().isActive());
((ViaServerInfo) getField_3776()).setViaServerVer(decoder.getInfo().getProtocolInfo().getServerProtocolVersion());
}
}
}

View File

@ -0,0 +1,43 @@
package com.viaversion.fabric.mc114.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.gui.DrawableHelper;
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.client.texture.TextureManager;
import net.minecraft.text.TranslatableText;
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.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(MultiplayerServerListWidget.ServerEntry.class)
public class MixinServerEntry {
@Shadow
@Final
private ServerInfo server;
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/texture/TextureManager;bindTexture(Lnet/minecraft/util/Identifier;)V"))
private void redirectPingIcon(TextureManager textureManager, Identifier identifier) {
if (identifier.equals(DrawableHelper.GUI_ICONS_LOCATION) && ((ViaServerInfo) this.server).isViaTranslating()) {
textureManager.bindTexture(new Identifier("viafabric:textures/gui/icons.png"));
return;
}
textureManager.bindTexture(identifier);
}
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setTooltip(Ljava/lang/String;)V"))
private void addServerVer(MultiplayerScreen multiplayerScreen, String text) {
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
StringBuilder builder = new StringBuilder(text);
builder.append("\n");
builder.append((new TranslatableText("gui.ping_version.translated", proto.getName(), proto.getVersion())).asString());
builder.append("\n");
builder.append(this.server.version);
multiplayerScreen.setTooltip(builder.toString());
}
}

View File

@ -0,0 +1,30 @@
package com.viaversion.fabric.mc114.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(ServerInfo.class)
public class MixinServerInfo implements ViaServerInfo {
private boolean viaTranslating;
private int viaServerVer;
public int getViaServerVer() {
return viaServerVer;
}
public void setViaServerVer(int viaServerVer) {
this.viaServerVer = viaServerVer;
}
@Override
public boolean isViaTranslating() {
return viaTranslating;
}
@Override
public void setViaTranslating(boolean via) {
this.viaTranslating = via;
}
}

View File

@ -3,9 +3,12 @@
"compatibilityLevel": "JAVA_8",
"package": "com.viaversion.fabric.mc114.mixin.gui",
"mixins": [
"client.MixinMultiplayerServerListPingerListener"
],
"client": [
"client.MixinMultiplayerScreen"
"client.MixinMultiplayerScreen",
"client.MixinServerEntry",
"client.MixinServerInfo"
],
"injectors": {
"defaultRequire": 0

View File

@ -0,0 +1,34 @@
package com.viaversion.fabric.mc115.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc115.mixin.debug.client.MixinClientConnectionAccessor;
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.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
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 MixinMultiplayerServerListPingerListener implements ClientQueryPacketListener {
@Accessor
abstract ClientConnection getField_3774(); // Synthetic
@Accessor
abstract ServerInfo getField_3776(); // Synthetic
@Inject(method = "onResponse", at = @At(value = "HEAD"))
private void onResponseCaptureServerInfo(QueryResponseS2CPacket packet, CallbackInfo ci) {
FabricDecodeHandler decoder = ((MixinClientConnectionAccessor) this.getField_3774()).getChannel()
.pipeline().get(FabricDecodeHandler.class);
if (decoder != null) {
((ViaServerInfo) getField_3776()).setViaTranslating(decoder.getInfo().isActive());
((ViaServerInfo) getField_3776()).setViaServerVer(decoder.getInfo().getProtocolInfo().getServerProtocolVersion());
}
}
}

View File

@ -0,0 +1,43 @@
package com.viaversion.fabric.mc115.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.gui.DrawableHelper;
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.client.texture.TextureManager;
import net.minecraft.text.TranslatableText;
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.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@Mixin(MultiplayerServerListWidget.ServerEntry.class)
public class MixinServerEntry {
@Shadow
@Final
private ServerInfo server;
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/texture/TextureManager;bindTexture(Lnet/minecraft/util/Identifier;)V"))
private void redirectPingIcon(TextureManager textureManager, Identifier identifier) {
if (identifier.equals(DrawableHelper.GUI_ICONS_LOCATION) && ((ViaServerInfo) this.server).isViaTranslating()) {
textureManager.bindTexture(new Identifier("viafabric:textures/gui/icons.png"));
return;
}
textureManager.bindTexture(identifier);
}
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setTooltip(Ljava/lang/String;)V"))
private void addServerVer(MultiplayerScreen multiplayerScreen, String text) {
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
StringBuilder builder = new StringBuilder(text);
builder.append("\n");
builder.append((new TranslatableText("gui.ping_version.translated", proto.getName(), proto.getVersion())).asString());
builder.append("\n");
builder.append(this.server.version);
multiplayerScreen.setTooltip(builder.toString());
}
}

View File

@ -0,0 +1,30 @@
package com.viaversion.fabric.mc115.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(ServerInfo.class)
public class MixinServerInfo implements ViaServerInfo {
private boolean viaTranslating;
private int viaServerVer;
public int getViaServerVer() {
return viaServerVer;
}
public void setViaServerVer(int viaServerVer) {
this.viaServerVer = viaServerVer;
}
@Override
public boolean isViaTranslating() {
return viaTranslating;
}
@Override
public void setViaTranslating(boolean via) {
this.viaTranslating = via;
}
}

View File

@ -3,9 +3,12 @@
"compatibilityLevel": "JAVA_8",
"package": "com.viaversion.fabric.mc115.mixin.gui",
"mixins": [
"client.MixinMultiplayerServerListPingerListener"
],
"client": [
"client.MixinMultiplayerScreen"
"client.MixinMultiplayerScreen",
"client.MixinServerEntry",
"client.MixinServerInfo"
],
"injectors": {
"defaultRequire": 0

View File

@ -0,0 +1,34 @@
package com.viaversion.fabric.mc116.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import com.viaversion.fabric.common.handler.FabricDecodeHandler;
import com.viaversion.fabric.mc116.mixin.debug.client.MixinClientConnectionAccessor;
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.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
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 MixinMultiplayerServerListPingerListener implements ClientQueryPacketListener {
@Accessor
abstract ClientConnection getField_3774(); // Synthetic
@Accessor
abstract ServerInfo getField_3776(); // Synthetic
@Inject(method = "onResponse", at = @At(value = "HEAD"))
private void onResponseCaptureServerInfo(QueryResponseS2CPacket packet, CallbackInfo ci) {
FabricDecodeHandler decoder = ((MixinClientConnectionAccessor) this.getField_3774()).getChannel()
.pipeline().get(FabricDecodeHandler.class);
if (decoder != null) {
((ViaServerInfo) getField_3776()).setViaTranslating(decoder.getInfo().isActive());
((ViaServerInfo) getField_3776()).setViaServerVer(decoder.getInfo().getProtocolInfo().getServerProtocolVersion());
}
}
}

View File

@ -0,0 +1,45 @@
package com.viaversion.fabric.mc116.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
import net.minecraft.client.gui.DrawableHelper;
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.client.texture.TextureManager;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
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.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import java.util.ArrayList;
import java.util.List;
@Mixin(MultiplayerServerListWidget.ServerEntry.class)
public class MixinServerEntry {
@Shadow
@Final
private ServerInfo server;
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/texture/TextureManager;bindTexture(Lnet/minecraft/util/Identifier;)V"))
private void redirectPingIcon(TextureManager textureManager, Identifier identifier) {
if (identifier.equals(DrawableHelper.GUI_ICONS_TEXTURE) && ((ViaServerInfo) this.server).isViaTranslating()) {
textureManager.bindTexture(new Identifier("viafabric:textures/gui/icons.png"));
return;
}
textureManager.bindTexture(identifier);
}
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setTooltip(Ljava/util/List;)V"))
private void addServerVer(MultiplayerScreen multiplayerScreen, List<Text> tooltipText) {
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
List<Text> lines = new ArrayList<>(tooltipText);
lines.add(new TranslatableText("gui.ping_version.translated", proto.getName(), proto.getVersion()));
lines.add(this.server.version.copy());
multiplayerScreen.setTooltip(lines);
}
}

View File

@ -0,0 +1,30 @@
package com.viaversion.fabric.mc116.mixin.gui.client;
import com.viaversion.fabric.common.gui.ViaServerInfo;
import net.minecraft.client.network.ServerInfo;
import org.spongepowered.asm.mixin.Mixin;
@Mixin(ServerInfo.class)
public class MixinServerInfo implements ViaServerInfo {
private boolean viaTranslating;
private int viaServerVer;
public int getViaServerVer() {
return viaServerVer;
}
public void setViaServerVer(int viaServerVer) {
this.viaServerVer = viaServerVer;
}
@Override
public boolean isViaTranslating() {
return viaTranslating;
}
@Override
public void setViaTranslating(boolean via) {
this.viaTranslating = via;
}
}

View File

@ -3,9 +3,12 @@
"compatibilityLevel": "JAVA_8",
"package": "com.viaversion.fabric.mc116.mixin.gui",
"mixins": [
"client.MixinMultiplayerServerListPingerListener"
],
"client": [
"client.MixinMultiplayerScreen"
"client.MixinMultiplayerScreen",
"client.MixinServerEntry",
"client.MixinServerInfo"
],
"injectors": {
"defaultRequire": 0

View File

@ -40,7 +40,8 @@ public class MixinServerEntry {
private void addServerVer(MultiplayerScreen multiplayerScreen, List<Text> tooltipText) {
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
List<Text> lines = new ArrayList<>(tooltipText);
lines.add(new TranslatableText("gui.ping_version.translated", proto.getName()));
lines.add(new TranslatableText("gui.ping_version.translated", proto.getName(), proto.getVersion()));
lines.add(this.server.version.copy());
multiplayerScreen.setTooltip(lines);
}
}

View File

@ -40,7 +40,8 @@ public class MixinServerEntry {
private void addServerVer(MultiplayerScreen multiplayerScreen, List<Text> tooltipText) {
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
List<Text> lines = new ArrayList<>(tooltipText);
lines.add(new TranslatableText("gui.ping_version.translated", proto.getName()));
lines.add(new TranslatableText("gui.ping_version.translated", proto.getName(), proto.getVersion()));
lines.add(this.server.version.copy());
multiplayerScreen.setTooltip(lines);
}
}

View File

@ -38,7 +38,8 @@ public class MixinServerEntry {
private void addServerVer(MultiplayerScreen multiplayerScreen, List<Text> tooltipText) {
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
List<Text> lines = new ArrayList<>(tooltipText);
lines.add(Text.translatable("gui.ping_version.translated", proto.getName()));
lines.add(Text.translatable("gui.ping_version.translated", proto.getName(), proto.getVersion()));
lines.add(this.server.version.copy());
multiplayerScreen.setMultiplayerScreenTooltip(lines);
}
}

View File

@ -38,7 +38,7 @@ public class MixinServerEntry {
private void addServerVer(MultiplayerScreen multiplayerScreen, List<Text> tooltipText) {
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).getViaServerVer());
List<Text> lines = new ArrayList<>(tooltipText);
lines.add(Text.translatable("gui.ping_version.translated", proto.getName()));
lines.add(Text.translatable("gui.ping_version.translated", proto.getName(), proto.getVersion()));
multiplayerScreen.setMultiplayerScreenTooltip(lines);
}
}