diff --git a/README.md b/README.md index cd9648de..300c64e5 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,7 @@ All changes are toggleable via config files. * **Husk & Stray Spawning:** Lets husks and strays spawn underground like regular zombies and skeletons * **Improve Barrier Particle Display:** Causes Barrier Particles to always be displayed to players in Creative mode * **Improve Language Switching Speed:** Improves the speed of switching languages in the Language GUI +* **Improve Server Connection Speed:** Improves the speed of connecting to servers by setting the InetAddress host name to the IP in situations where it can be represented as the IP address, preventing getHostFromNameService from being to be run * **Improved Entity Tracker Warning:** Provides more information to addPacket removed entity warnings * **Incurable Potions:** Excludes potion effects from being curable with curative items like buckets of milk * **Infinite Music:** Lets background music play continuously without delays diff --git a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java index 1eab5146..9e0ebda4 100644 --- a/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java +++ b/src/main/java/mod/acgaming/universaltweaks/config/UTConfigTweaks.java @@ -1998,6 +1998,15 @@ public static class PerformanceCategory @Config.Comment("Improves the speed of switching languages in the Language GUI") public boolean utImproveLanguageSwitchingSpeed = true; + @Config.RequiresMcRestart + @Config.Name("Improve Server Connection Speed") + @Config.Comment + ({ + "Improves the speed of connecting to servers by setting the InetAddress host name to the IP in situations", + "where it can be represented as the IP address, preventing getHostFromNameService from being to be run" + }) + public boolean utImproveServerConnectionSpeed = true; + @Config.RequiresMcRestart @Config.Name("Mute Advancement Errors") @Config.Comment("Silences advancement errors") diff --git a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java index 8ab5e631..4113f0a0 100644 --- a/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java +++ b/src/main/java/mod/acgaming/universaltweaks/core/UTLoadingPlugin.java @@ -206,6 +206,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader put("mixins.tweaks.misc.smoothscrolling.json", () -> UTConfigTweaks.MISC.SMOOTH_SCROLLING.utSmoothScrollingToggle); put("mixins.tweaks.misc.toastcontrol.json", () -> UTConfigTweaks.MISC.TOAST_CONTROL.utToastControlToggle); put("mixins.tweaks.performance.audioreload.json", () -> UTConfigTweaks.PERFORMANCE.utDisableAudioDebugToggle && !surgeLoaded); + put("mixins.tweaks.performance.connectionspeed.json", () -> UTConfigTweaks.PERFORMANCE.utImproveLanguageSwitchingSpeed); put("mixins.tweaks.performance.fps.json", () -> UTConfigTweaks.PERFORMANCE.utUncapFPSToggle); put("mixins.tweaks.performance.languageswitching.json", () -> UTConfigTweaks.PERFORMANCE.utImproveLanguageSwitchingSpeed); put("mixins.tweaks.performance.missingmodel.json", () -> UTConfigTweaks.PERFORMANCE.utDisableFancyMissingModelToggle); diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/UTConnectionPatch.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/UTConnectionPatch.java new file mode 100644 index 00000000..b4f2cfc8 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/UTConnectionPatch.java @@ -0,0 +1,28 @@ +package mod.acgaming.universaltweaks.tweaks.performance.connectionspeed; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import com.google.common.net.InetAddresses; + +import mod.acgaming.universaltweaks.UniversalTweaks; + +public class UTConnectionPatch +{ + public static InetAddress patch(String hostName) throws UnknownHostException + { + return patch(InetAddress.getByName(hostName), hostName); + } + + @SuppressWarnings("UnstableApiUsage") + public static InetAddress patch(InetAddress original, String hostName) throws UnknownHostException + { + if (InetAddresses.isInetAddress(hostName)) + { + InetAddress patched = InetAddress.getByAddress(original.getHostAddress(), original.getAddress()); + UniversalTweaks.LOGGER.debug("Patching ip-only InetAddress from {} to {}", original, patched); + return patched; + } + return original; + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTGuiConnectingMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTGuiConnectingMixin.java new file mode 100644 index 00000000..6e0457e2 --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTGuiConnectingMixin.java @@ -0,0 +1,24 @@ +package mod.acgaming.universaltweaks.tweaks.performance.connectionspeed.mixin; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import mod.acgaming.universaltweaks.config.UTConfigTweaks; +import mod.acgaming.universaltweaks.tweaks.performance.connectionspeed.UTConnectionPatch; + +// Courtesy of WaitingIdly +@Mixin(targets = "net.minecraft.client.multiplayer.GuiConnecting$1") +public class UTGuiConnectingMixin +{ + @WrapOperation(method = "run", at = @At(value = "INVOKE", target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;")) + private InetAddress utPatchInetAddress(String ip, Operation original) throws UnknownHostException + { + if (!UTConfigTweaks.PERFORMANCE.utImproveServerConnectionSpeed) return original.call(ip); + return UTConnectionPatch.patch(ip); + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTRealmsConnectMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTRealmsConnectMixin.java new file mode 100644 index 00000000..8ad34ffa --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTRealmsConnectMixin.java @@ -0,0 +1,24 @@ +package mod.acgaming.universaltweaks.tweaks.performance.connectionspeed.mixin; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import mod.acgaming.universaltweaks.config.UTConfigTweaks; +import mod.acgaming.universaltweaks.tweaks.performance.connectionspeed.UTConnectionPatch; + +// Courtesy of WaitingIdly +@Mixin(targets = "net.minecraft.realms.RealmsConnect$1") +public class UTRealmsConnectMixin +{ + @WrapOperation(method = "run", at = @At(value = "INVOKE", target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;")) + private InetAddress utPatchInetAddress(String ip, Operation original) throws UnknownHostException + { + if (!UTConfigTweaks.PERFORMANCE.utImproveServerConnectionSpeed) return original.call(ip); + return UTConnectionPatch.patch(ip); + } +} diff --git a/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTServerPingerMixin.java b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTServerPingerMixin.java new file mode 100644 index 00000000..c0bea2dd --- /dev/null +++ b/src/main/java/mod/acgaming/universaltweaks/tweaks/performance/connectionspeed/mixin/UTServerPingerMixin.java @@ -0,0 +1,26 @@ +package mod.acgaming.universaltweaks.tweaks.performance.connectionspeed.mixin; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +import net.minecraft.client.network.ServerPinger; + +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; + +import mod.acgaming.universaltweaks.config.UTConfigTweaks; +import mod.acgaming.universaltweaks.tweaks.performance.connectionspeed.UTConnectionPatch; + +// Courtesy of WaitingIdly +@Mixin(value = ServerPinger.class) +public class UTServerPingerMixin +{ + @WrapOperation(method = "ping", at = @At(value = "INVOKE", target = "Ljava/net/InetAddress;getByName(Ljava/lang/String;)Ljava/net/InetAddress;")) + private InetAddress utPatchInetAddress(String ip, Operation original) throws UnknownHostException + { + if (!UTConfigTweaks.PERFORMANCE.utImproveServerConnectionSpeed) return original.call(ip); + return UTConnectionPatch.patch(ip); + } +} diff --git a/src/main/resources/mixins.tweaks.performance.connectionspeed.json b/src/main/resources/mixins.tweaks.performance.connectionspeed.json new file mode 100644 index 00000000..4c555cd5 --- /dev/null +++ b/src/main/resources/mixins.tweaks.performance.connectionspeed.json @@ -0,0 +1,7 @@ +{ + "package": "mod.acgaming.universaltweaks.tweaks.performance.connectionspeed.mixin", + "refmap": "universaltweaks.refmap.json", + "minVersion": "0.8", + "compatibilityLevel": "JAVA_8", + "client": ["UTGuiConnectingMixin", "UTRealmsConnectMixin", "UTServerPingerMixin"] +} \ No newline at end of file