Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backport 1.20's 'pause-when-empty-seconds' server property #470

Merged
merged 12 commits into from
Jan 13, 2025
2 changes: 1 addition & 1 deletion dependencies.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ dependencies {
transformedModCompileOnly(deobf("https://forum.industrial-craft.net/core/attachment/4316-advancedsolarpanel-1-7-10-3-5-1-jar/"))
transformedModCompileOnly(rfg.deobf("curse.maven:candycraft-251118:2330488"))

devOnlyNonPublishable(deobf("https://github.com/makamys/CoreTweaks/releases/download/0.3.3.2/CoreTweaks-1.7.10-0.3.3.2+nomixin.jar"))
transformedModCompileOnly(deobf("https://github.com/makamys/CoreTweaks/releases/download/0.3.3.2/CoreTweaks-1.7.10-0.3.3.2+nomixin.jar"))
}

// Replace when RFG support deobfuscation from notch mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public class TweaksConfig {
@Config.DefaultInt(900)
public static int autoSaveInterval;

@Config.Comment("Backports 1.20's 'pause-when-empty-seconds' server property")
@Config.DefaultBoolean(true)
serenibyss marked this conversation as resolved.
Show resolved Hide resolved
public static boolean pauseWhenEmpty;

@Config.Comment("Reduces water opacity from 3 to 1, to match modern")
@Config.DefaultBoolean(false)
public static boolean useLighterWater;
Expand Down Expand Up @@ -306,5 +310,4 @@ public class TweaksConfig {
@Config.Comment("Avoids droping items on container close, and instead places them in the player inventory. (Inspired from EFR)")
@Config.DefaultBoolean(true)
public static boolean avoidDroppingItemsWhenClosing;

}
5 changes: 5 additions & 0 deletions src/main/java/com/mitchej123/hodgepodge/mixins/Mixins.java
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,11 @@ public enum Mixins {
.addMixinClasses("minecraft.server.MixinMinecraftServer_AutoSaveInterval")
.setApplyIf(() -> TweaksConfig.autoSaveInterval != 900)),

PAUSE_WHEN_EMPTY(new Builder("Pauses the server when noone is online after X seconds; Servers Only")
.setPhase(Phase.EARLY).setSide(Side.SERVER).addTargetedMod(TargetedMod.VANILLA)
.addMixinClasses("minecraft.server.MixinMinecraftServer_PauseWhenEmpty")
.setApplyIf(() -> TweaksConfig.pauseWhenEmpty)),

LIGHTER_WATER(new Builder("Decreases water opacity from 3 to 1, like in modern").setPhase(Phase.EARLY)
.setSide(Side.BOTH).addTargetedMod(TargetedMod.VANILLA).addMixinClasses("minecraft.MixinBlock_LighterWater")
.setApplyIf(() -> TweaksConfig.useLighterWater)),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.mitchej123.hodgepodge.mixins.early.minecraft.server;

import java.io.File;
import java.net.Proxy;

import net.minecraft.server.MinecraftServer;
import net.minecraft.server.dedicated.DedicatedServer;
import net.minecraft.server.dedicated.PropertyManager;

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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import com.mitchej123.hodgepodge.Common;

@Mixin(DedicatedServer.class)
public abstract class MixinMinecraftServer_PauseWhenEmpty extends MinecraftServer {

@Shadow
private PropertyManager settings;

@Unique
private int hodgepodge$pauseWhenEmptySeconds = 0;
@Unique
private int hodgepodge$emptyTicks = 0;

public MixinMinecraftServer_PauseWhenEmpty(File workDir, Proxy proxy) {
super(workDir, proxy);
}

@Inject(
method = "startServer",
at = @At(
value = "INVOKE",
target = "Lcpw/mods/fml/common/FMLCommonHandler;onServerStarted()V",
remap = false,
shift = At.Shift.AFTER))
public void hodgepodge$setupServer(CallbackInfoReturnable<Boolean> cir) {
hodgepodge$pauseWhenEmptySeconds = settings.getIntProperty("pause-when-empty-seconds", 0);
}

@Override
public void tick() {
Caedis marked this conversation as resolved.
Show resolved Hide resolved
int pauseTicks = hodgepodge$pauseWhenEmptySeconds * 20;
if (pauseTicks > 0) {
if (getCurrentPlayerCount() == 0) {
this.hodgepodge$emptyTicks++;
} else {
this.hodgepodge$emptyTicks = 0;
}

if (hodgepodge$emptyTicks >= pauseTicks) {
if (hodgepodge$emptyTicks == pauseTicks) {
Common.log
.info("Server empty for {} seconds, saving and pausing", hodgepodge$pauseWhenEmptySeconds);
this.serverConfigManager.saveAllPlayerData();
this.saveAllWorlds(true);
}

// to process new connections
this.func_147137_ag().networkTick();
return;
}
}

super.tick();
}
}
2 changes: 2 additions & 0 deletions src/main/resources/META-INF/hodgepodge_at.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ public net.minecraft.client.resources.SimpleReloadableResourceManager field_1105
public net.minecraft.entity.EntityList field_75624_e # classToIDMapping
public net.minecraft.world.WorldServer func_73053_d()V # wakeAllPlayers()

protected net.minecraft.server.MinecraftServer field_71318_t # serverConfigManager

public net.minecraft.server.management.PlayerManager$PlayerInstance