Skip to content

Commit

Permalink
Merge pull request ACGaming#556 from jchung01/vanilla-tweaks
Browse files Browse the repository at this point in the history
Add RandomPatches timeout tweaks
  • Loading branch information
ACGaming authored Sep 25, 2024
2 parents d006e13 + ad99178 commit beb9efe
Show file tree
Hide file tree
Showing 10 changed files with 149 additions and 0 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,8 @@ All changes are toggleable via config files.
* **Chicken Shedding:** Allows chickens to have a chance to shed feathers (similarly to laying eggs)
* **Chunk Gen Limit:** Limits maximum chunk generation per tick for improved server performance
* **Cobweb Slowness:** Modifies the applied slowness factor when entities are moving in cobwebs
* **Connection Timeouts:** Allows configuring read/login timeouts
* Helps slow clients log into a server of a large modpack
* **Copy World Seed:** Enables clicking of `/seed` world seed in chat to copy to clipboard
* **Crafting Cache:** Adds an IRecipe cache to improve recipe performance in large modpacks
* **Creeper Confetti:** Replaces deadly creeper explosions with delightful confetti (with a configurable chance)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import mod.acgaming.universaltweaks.tweaks.misc.incurablepotions.UTIncurablePotions;
import mod.acgaming.universaltweaks.tweaks.misc.loadsound.UTLoadSound;
import mod.acgaming.universaltweaks.tweaks.misc.swingthroughgrass.UTSwingThroughGrassLists;
import mod.acgaming.universaltweaks.tweaks.misc.timeouts.UTTimeoutManager;
import mod.acgaming.universaltweaks.tweaks.performance.autosave.UTAutoSaveOFCompat;
import mod.acgaming.universaltweaks.tweaks.performance.entityradiuscheck.UTEntityRadiusCheck;

Expand Down Expand Up @@ -1374,6 +1375,10 @@ public static class MiscCategory
@Config.Name("Chat")
public final ChatCategory CHAT = new ChatCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.misc.timeouts")
@Config.Name("Connection Timeouts")
public final TimeoutsCategory TIMEOUTS = new TimeoutsCategory();

@Config.LangKey("cfg.universaltweaks.tweaks.misc.incurablepotions")
@Config.Name("Incurable Potions")
public final IncurablePotionsCategory INCURABLE_POTIONS = new IncurablePotionsCategory();
Expand Down Expand Up @@ -1948,6 +1953,34 @@ public static class SwingThroughGrassCategory
public String[] utSwingThroughGrassWhitelist = new String[] {};
}

public static class TimeoutsCategory
{
@Config.Name("[1] Connection Timeouts Toggle")
@Config.Comment
({
"Allows configuring read/login timeouts.",
"If you are having trouble logging into a server of a large modpack, try changing the timeouts below."
})
public boolean utTimeoutsToggle = true;

@Config.Name("[2] Read Timeout")
@Config.Comment
({
"The connection read timeout in seconds.",
"This value is used on both client and server.",
"On the server, also extends the time allowed to respond to a KeepAlive packet."
})
public int utReadTimeout = 90;

@Config.Name("[3] Login Timeout")
@Config.Comment
({
"The login timeout in seconds. (Vanilla default: 600 ticks, or 30 secs)",
"Only used on the server.",
})
public int utLoginTimeout = 90;
}

public static class ToastControlCategory
{
@Config.RequiresMcRestart
Expand Down Expand Up @@ -2303,6 +2336,7 @@ public static class VoidFogCategory
static
{
ConfigAnytime.register(UTConfigTweaks.class);
UTTimeoutManager.init();
}

@Mod.EventBusSubscriber(modid = UniversalTweaks.MODID)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.misc.lightning.damage.json", () -> UTConfigTweaks.MISC.LIGHTNING.utLightningDamage != 5.0D || UTConfigTweaks.MISC.LIGHTNING.utLightningFireTicks != 8);
put("mixins.tweaks.misc.lightning.fire.json", () -> UTConfigTweaks.MISC.LIGHTNING.utLightningFireToggle);
put("mixins.tweaks.misc.recipebook.server.json", () -> UTConfigTweaks.MISC.utRecipeBookToggle);
put("mixins.tweaks.misc.timeouts.json", () -> UTConfigTweaks.MISC.TIMEOUTS.utTimeoutsToggle);
put("mixins.tweaks.misc.xp.cap.json", () -> UTConfigTweaks.MISC.utXPLevelCap > -1);
put("mixins.tweaks.misc.xp.linear.json", () -> UTConfigTweaks.MISC.utLinearXP > 0);
put("mixins.tweaks.misc.xp.smelting.json", () -> UTConfigTweaks.MISC.utSmeltingXPToggle);
Expand Down Expand Up @@ -217,6 +218,7 @@ public class UTLoadingPlugin implements IFMLLoadingPlugin, IEarlyMixinLoader
put("mixins.tweaks.misc.personalpotionparticles.json", () -> UTConfigTweaks.MISC.utPoVEffectParticles);
put("mixins.tweaks.misc.recipebook.client.json", () -> UTConfigTweaks.MISC.utRecipeBookToggle);
put("mixins.tweaks.misc.smoothscrolling.json", () -> UTConfigTweaks.MISC.SMOOTH_SCROLLING.utSmoothScrollingToggle);
put("mixins.tweaks.misc.timeouts.client.json", () -> UTConfigTweaks.MISC.TIMEOUTS.utTimeoutsToggle);
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package mod.acgaming.universaltweaks.tweaks.misc.timeouts;

import org.apache.commons.lang3.math.NumberUtils;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;

public class UTTimeoutManager
{
public static long readTimeoutMillis;
public static int loginTimeoutTicks;

public static void init()
{
if (!UTConfigTweaks.MISC.TIMEOUTS.utTimeoutsToggle) return;
int readTimeout = NumberUtils.toInt(System.getProperty("fml.readTimeout"), UTConfigTweaks.MISC.TIMEOUTS.utReadTimeout);
// Don't overwrite read timeout that was specified by command line.
if (readTimeout == UTConfigTweaks.MISC.TIMEOUTS.utReadTimeout)
{
System.setProperty("fml.readTimeout", String.valueOf(UTConfigTweaks.MISC.TIMEOUTS.utReadTimeout));
}
readTimeoutMillis = UTConfigTweaks.MISC.TIMEOUTS.utReadTimeout * 1000L;
loginTimeoutTicks = UTConfigTweaks.MISC.TIMEOUTS.utLoginTimeout * 20;
// fml.loginTimeout is unused
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package mod.acgaming.universaltweaks.tweaks.misc.timeouts.mixin;

import mod.acgaming.universaltweaks.config.UTConfigTweaks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

// Courtesy of jchung01, TheRandomLabs (RandomPatches)
@Mixin(targets = "net.minecraft.network.NetworkManager$5")
public class UTClientReadTimeoutMixin
{
@SuppressWarnings("UnresolvedMixinReference")
@ModifyConstant(method = "initChannel", constant = @Constant(intValue = 30))
private int utModifyReadTimeout(int original)
{
return UTConfigTweaks.MISC.TIMEOUTS.utReadTimeout;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package mod.acgaming.universaltweaks.tweaks.misc.timeouts.mixin;

import net.minecraft.server.network.NetHandlerLoginServer;

import mod.acgaming.universaltweaks.tweaks.misc.timeouts.UTTimeoutManager;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.Constant;
import org.spongepowered.asm.mixin.injection.ModifyConstant;

// Courtesy of jchung01, TheRandomLabs (RandomPatches)
@Mixin(value = NetHandlerLoginServer.class)
public class UTLoginTimeoutMixin
{
@ModifyConstant(method = "update", constant = @Constant(intValue = 600))
private int utModifyLoginTimeout(int original)
{
return UTTimeoutManager.loginTimeoutTicks;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mod.acgaming.universaltweaks.tweaks.misc.timeouts.mixin;

import net.minecraft.network.NetHandlerPlayServer;
import net.minecraft.util.text.ITextComponent;

import com.llamalad7.mixinextras.injector.wrapoperation.Operation;
import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation;
import com.llamalad7.mixinextras.sugar.Local;
import mod.acgaming.universaltweaks.tweaks.misc.timeouts.UTTimeoutManager;
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.Slice;

// Courtesy of jchung01, TheRandomLabs (RandomPatches)
@Mixin(value = NetHandlerPlayServer.class)
public class UTServerReadTimeoutMixin
{
// lastPingTime, not sure why this is MCP name
@Shadow
private long field_194402_f;

@WrapOperation(method = "update",
slice = @Slice(from = @At(value = "CONSTANT", args = "stringValue=keepAlive"),
to = @At(value = "INVOKE", target = "Lnet/minecraft/profiler/Profiler;endSection()V")),
at = @At(value = "INVOKE", target = "Lnet/minecraft/network/NetHandlerPlayServer;disconnect(Lnet/minecraft/util/text/ITextComponent;)V"))
private void utKeepAliveUntilReadTimeout(NetHandlerPlayServer instance, ITextComponent textComponent, Operation<Void> original, @Local long currentTimeMillis)
{
if (currentTimeMillis - field_194402_f >= UTTimeoutManager.readTimeoutMillis)
{
original.call(instance, textComponent);
}
}
}
1 change: 1 addition & 0 deletions src/main/resources/assets/universaltweaks/lang/en_us.lang
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ cfg.universaltweaks.tweaks.misc.loadsounds=Load Sounds
cfg.universaltweaks.tweaks.misc.pickupnotification=Pickup Notification
cfg.universaltweaks.tweaks.misc.smoothscrolling=Smooth Scrolling
cfg.universaltweaks.tweaks.misc.stg=Swing Through Grass
cfg.universaltweaks.tweaks.misc.timeouts=Connection Timeouts
cfg.universaltweaks.tweaks.misc.toastcontrol=Toast Control
cfg.universaltweaks.tweaks.performance.entityradiuscheck=Entity Radius Check
cfg.universaltweaks.tweaks.world.chunkgenlimit=Chunk Gen Limit
Expand Down
7 changes: 7 additions & 0 deletions src/main/resources/mixins.tweaks.misc.timeouts.client.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.tweaks.misc.timeouts.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"client": ["UTClientReadTimeoutMixin"]
}
7 changes: 7 additions & 0 deletions src/main/resources/mixins.tweaks.misc.timeouts.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"package": "mod.acgaming.universaltweaks.tweaks.misc.timeouts.mixin",
"refmap": "universaltweaks.refmap.json",
"minVersion": "0.8",
"compatibilityLevel": "JAVA_8",
"mixins": ["UTLoginTimeoutMixin", "UTServerReadTimeoutMixin"]
}

0 comments on commit beb9efe

Please sign in to comment.