Skip to content

Commit

Permalink
add logger interval
Browse files Browse the repository at this point in the history
  • Loading branch information
RedLime committed Dec 20, 2022
1 parent 0a5edc4 commit 44bc71a
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 3 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
plugins {
id 'fabric-loom' version '0.12-SNAPSHOT'
id 'fabric-loom' version '1.0-SNAPSHOT'
id 'maven-publish'
}

Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.16.1
yarn_mappings=1.16.1+build.21
loader_version=0.13.3
# Mod Properties
mod_version=3.7.2
mod_version=3.8
maven_group=com.redlimerl
archives_base_name=sleepbackground

Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,16 @@ public void loadToInit(JsonObject configObject) {
public static final FrameTickConfigValue WORLD_INITIAL_FRAME_RATE =
new FrameTickConfigValue("world_setup", 10, 30, "same with (background) config but for (max_ticks) ticks after the joined the world.");

public static final LogIntervalConfigValue LOG_INTERVAL =
new LogIntervalConfigValue(500, "Changes how often the game prints the worldgen progress to the log file, may be useful for macros (minimum: 50ms, max/default: 500ms)");


static {
ALL_CONFIGS.add(BACKGROUND_FRAME_RATE);
ALL_CONFIGS.add(LOADING_SCREEN_FRAME_RATE);
ALL_CONFIGS.add(WORLD_PREVIEW_RENDER_TIMES);
ALL_CONFIGS.add(WORLD_INITIAL_FRAME_RATE);
ALL_CONFIGS.add(NONE_PLAYING_FRAME_RATE);
ALL_CONFIGS.add(LOG_INTERVAL);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.redlimerl.sleepbackground.config;

import com.google.gson.JsonObject;
import org.jetbrains.annotations.Nullable;

public class LogIntervalConfigValue extends ConfigValue {

private int logInterval;

public LogIntervalConfigValue(int defaultLimit, String comment) {
super("log_interval", comment);
this.logInterval = defaultLimit;
}

@Override
public void loadToInit(JsonObject configObject) {
if (configObject.has(this.getKeyName())) {
this.logInterval = configObject.get(this.getKeyName()).getAsInt();
if (this.logInterval < 50 || this.logInterval > 500) throw new IllegalArgumentException("Logging interval must be >= 50ms and <= 500ms");
}
}

@Override
public void writeToJson(JsonObject configObject) {
configObject.addProperty(this.getKeyName(), this.logInterval);
}

public int getLogInterval() {
return this.isEnable() ? logInterval : 500;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.redlimerl.sleepbackground.mixin;

import com.redlimerl.sleepbackground.config.ConfigValues;
import net.minecraft.server.WorldGenerationProgressLogger;
import net.minecraft.util.math.ChunkPos;
import net.minecraft.world.chunk.ChunkStatus;
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.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(WorldGenerationProgressLogger.class)
public class MixinWorldGenerationProgressLogger {

@Shadow private long nextMessageTime;

/**
* @author DuncanRuns, jojoe77777
*/
@Inject(method = "setChunkStatus", at = @At(value = "INVOKE", target = "Lorg/apache/logging/log4j/Logger;info(Ljava/lang/String;)V", shift = At.Shift.BEFORE, remap = false))
public void injectMessageTime(ChunkPos pos, ChunkStatus status, CallbackInfo ci) {
nextMessageTime -= (500 - ConfigValues.LOG_INTERVAL.getLogInterval());
}
}
3 changes: 2 additions & 1 deletion src/main/resources/sleepbackground.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"MixinSnooper",
"MixinThreadExecutor",
"MixinToastManager",
"MixinWindow"
"MixinWindow",
"MixinWorldGenerationProgressLogger"
]
}

0 comments on commit 44bc71a

Please sign in to comment.