mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-01-22 21:42:44 +01:00
Added setting to replace the default port when bedrock is selected
This commit is contained in:
parent
5abef51ce9
commit
f899271881
@ -28,13 +28,16 @@ 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.injection.ViaFabricPlusMixinPlugin;
|
||||
import de.florianmichael.viafabricplus.injection.access.IClientConnection;
|
||||
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
import de.florianmichael.viafabricplus.settings.impl.BedrockSettings;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.font.FontStorage;
|
||||
import net.minecraft.client.network.ClientPlayNetworkHandler;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
import net.minecraft.client.network.ServerInfo;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.raphimc.viabedrock.api.BedrockProtocolVersion;
|
||||
@ -43,6 +46,7 @@ import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.dat
|
||||
import net.raphimc.vialegacy.protocols.classic.protocolc0_28_30toc0_28_30cpe.storage.ExtensionProtocolMetadataStorage;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
@ -141,6 +145,28 @@ public class ClientsideFixes {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replaces the default port when parsing a server address if the default port should be replaced
|
||||
*
|
||||
* @param info The server info
|
||||
* @return The server address with the replaced default port
|
||||
*/
|
||||
public static ServerAddress replaceDefaultPort(final ServerInfo info) {
|
||||
ProtocolVersion targetVersion = ((IServerInfo) info).viaFabricPlus$forcedVersion();
|
||||
if (targetVersion == null) {
|
||||
targetVersion = ProtocolTranslator.getTargetVersion();
|
||||
}
|
||||
final boolean isBedrock = Objects.equals(targetVersion, BedrockProtocolVersion.bedrockLatest);
|
||||
|
||||
// If the default port for this entry should be replaced, check if the address already contains a port
|
||||
// We can't just replace vanilla's default port because a bedrock server might be running on the same port
|
||||
if (BedrockSettings.global().replaceDefaultPort.getValue() && isBedrock && !info.address.contains(":")) {
|
||||
return ServerAddress.parse(info.address + ":" + 19132);
|
||||
} else {
|
||||
return ServerAddress.parse(info.address);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Executes a sync task and returns the uuid of the task
|
||||
*
|
||||
|
@ -19,15 +19,20 @@
|
||||
|
||||
package de.florianmichael.viafabricplus.injection.mixin.base.integration;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
|
||||
import de.florianmichael.viafabricplus.screen.base.ProtocolSelectionScreen;
|
||||
import de.florianmichael.viafabricplus.settings.impl.GeneralSettings;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.multiplayer.MultiplayerScreen;
|
||||
import net.minecraft.client.gui.widget.ButtonWidget;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
import net.minecraft.client.network.ServerInfo;
|
||||
import net.minecraft.text.Text;
|
||||
import org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.injection.At;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.Redirect;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
@Mixin(MultiplayerScreen.class)
|
||||
@ -49,4 +54,9 @@ public abstract class MixinMultiplayerScreen extends Screen {
|
||||
this.addDrawableChild(GeneralSettings.withOrientation(builder, buttonPosition, width, height).build());
|
||||
}
|
||||
|
||||
@Redirect(method = "connect(Lnet/minecraft/client/network/ServerInfo;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ServerAddress;parse(Ljava/lang/String;)Lnet/minecraft/client/network/ServerAddress;"))
|
||||
private ServerAddress replaceDefaultPort(String address, @Local(argsOnly = true) ServerInfo entry) {
|
||||
return ClientsideFixes.replaceDefaultPort(entry);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,9 +21,11 @@ package de.florianmichael.viafabricplus.injection.mixin.base.perserverversion;
|
||||
|
||||
import com.llamalad7.mixinextras.sugar.Local;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.viafabricplus.fixes.ClientsideFixes;
|
||||
import de.florianmichael.viafabricplus.injection.access.IPerformanceLog;
|
||||
import de.florianmichael.viafabricplus.injection.access.IServerInfo;
|
||||
import net.minecraft.client.network.MultiplayerServerListPinger;
|
||||
import net.minecraft.client.network.ServerAddress;
|
||||
import net.minecraft.client.network.ServerInfo;
|
||||
import net.minecraft.network.ClientConnection;
|
||||
import net.minecraft.util.profiler.PerformanceLog;
|
||||
@ -36,8 +38,13 @@ import java.net.InetSocketAddress;
|
||||
@Mixin(MultiplayerServerListPinger.class)
|
||||
public abstract class MixinMultiplayerServerListPinger {
|
||||
|
||||
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/network/ServerAddress;parse(Ljava/lang/String;)Lnet/minecraft/client/network/ServerAddress;"))
|
||||
private ServerAddress replaceDefaultPort(String address, @Local(argsOnly = true) ServerInfo entry) {
|
||||
return ClientsideFixes.replaceDefaultPort(entry);
|
||||
}
|
||||
|
||||
@Redirect(method = "add", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/ClientConnection;connect(Ljava/net/InetSocketAddress;ZLnet/minecraft/util/profiler/PerformanceLog;)Lnet/minecraft/network/ClientConnection;"))
|
||||
private ClientConnection setForcedVersion(InetSocketAddress address, boolean useEpoll, PerformanceLog packetSizeLog, @Local ServerInfo serverInfo) {
|
||||
private ClientConnection setForcedVersion(InetSocketAddress address, boolean useEpoll, PerformanceLog packetSizeLog, @Local(argsOnly = true) ServerInfo serverInfo) {
|
||||
final ProtocolVersion forcedVersion = ((IServerInfo) serverInfo).viaFabricPlus$forcedVersion();
|
||||
|
||||
if (forcedVersion != null && !((IServerInfo) serverInfo).viaFabricPlus$passedDirectConnectScreen()) {
|
||||
|
@ -55,6 +55,7 @@ public class BedrockSettings extends SettingGroup {
|
||||
}
|
||||
};
|
||||
public final BooleanSetting openPromptGUIToConfirmTransfer = new BooleanSetting(this, Text.translatable("bedrock_settings.viafabricplus.confirm_transfer_server_prompt"), true);
|
||||
public final BooleanSetting replaceDefaultPort = new BooleanSetting(this, Text.translatable("bedrock_settings.viafabricplus.replace_default_port"), true);
|
||||
|
||||
public BedrockSettings() {
|
||||
super(Text.translatable("setting_group_name.viafabricplus.bedrock"));
|
||||
|
@ -48,6 +48,7 @@
|
||||
|
||||
"bedrock_settings.viafabricplus.confirm_transfer_server_prompt": "Open prompt GUI to confirm transferring to other servers",
|
||||
"bedrock_settings.viafabricplus.click_to_set_bedrock_account": "Click to set account for Bedrock edition",
|
||||
"bedrock_settings.viafabricplus.replace_default_port": "Replace default port in server list",
|
||||
|
||||
"debug_settings.viafabricplus.queue_config_packets": "Queue config packets",
|
||||
"debug_settings.viafabricplus.disable_sequencing": "Disable sequencing",
|
||||
|
@ -129,6 +129,7 @@
|
||||
"fixes.minecraft.item.MixinItemPlacementContext",
|
||||
"fixes.minecraft.item.MixinItemRenderer",
|
||||
"fixes.minecraft.item.MixinItemStack",
|
||||
"fixes.minecraft.item.MixinMiningToolItem",
|
||||
"fixes.minecraft.item.MixinPickaxeItem",
|
||||
"fixes.minecraft.item.MixinShearsItem",
|
||||
"fixes.minecraft.item.MixinShovelItem",
|
||||
@ -199,8 +200,7 @@
|
||||
"vialegacy.MixinExtensionProtocolMetadataStorage",
|
||||
"vialegacy.MixinViaLegacyConfig",
|
||||
"viaversion.MixinConfig",
|
||||
"viaversion.MixinProtocolVersion",
|
||||
"fixes.minecraft.item.MixinMiningToolItem"
|
||||
"viaversion.MixinProtocolVersion"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
Loading…
Reference in New Issue
Block a user