65 lines
3.2 KiB
Java
65 lines
3.2 KiB
Java
/*
|
|
* This file is part of ViaFabric - https://github.com/ViaVersion/ViaFabric
|
|
* Copyright (C) 2018-2024 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.fabric.mc1201.mixin.gui.client;
|
|
|
|
import com.viaversion.fabric.common.gui.ViaServerInfo;
|
|
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
|
import net.minecraft.client.gui.DrawContext;
|
|
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.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;
|
|
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;
|
|
|
|
@Unique
|
|
private static final Identifier viaFabric$GUI_ICONS_TEXTURES = new Identifier("textures/gui/icons.png");
|
|
|
|
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0,
|
|
target = "Lnet/minecraft/client/gui/DrawContext;drawTexture(Lnet/minecraft/util/Identifier;IIFFIIII)V"))
|
|
private void redirectPingIcon(DrawContext instance, Identifier texture, int x, int y, float u, float v, int width, int height, int textureWidth, int textureHeight) {
|
|
if (texture.equals(viaFabric$GUI_ICONS_TEXTURES) && ((ViaServerInfo) this.server).viaFabric$translating()) {
|
|
instance.drawTexture(new Identifier("viafabric:textures/gui/icons.png"), x, y, u, v, width, height, textureWidth, textureHeight);
|
|
return;
|
|
}
|
|
instance.drawTexture(texture, x, y, u, v, width, height, textureWidth, textureHeight);
|
|
}
|
|
|
|
@Redirect(method = "render", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/client/gui/screen/multiplayer/MultiplayerScreen;setMultiplayerScreenTooltip(Ljava/util/List;)V"))
|
|
private void addServerVer(MultiplayerScreen multiplayerScreen, List<Text> tooltipText) {
|
|
ProtocolVersion proto = ProtocolVersion.getProtocol(((ViaServerInfo) this.server).viaFabric$getServerVer());
|
|
List<Text> lines = new ArrayList<>(tooltipText);
|
|
lines.add(Text.translatable("gui.ping_version.translated", proto.getName(), proto.getVersion()));
|
|
lines.add(this.server.version.copy());
|
|
multiplayerScreen.setMultiplayerScreenTooltip(lines);
|
|
}
|
|
} |