Skip to content

Commit

Permalink
Added config file
Browse files Browse the repository at this point in the history
  • Loading branch information
MrHua269 committed Feb 9, 2025
1 parent 4d3ed79 commit e85a317
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 11 deletions.
7 changes: 6 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ base {

repositories {
maven { url = "https://api.modrinth.com/maven" }
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.terraformersmc.com/releases/" }
}

dependencies {
Expand All @@ -20,7 +22,10 @@ dependencies {
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"

modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_version}"
modImplementation "maven.modrinth:moonrise-opt:a8Zqa1bJ"
modImplementation "maven.modrinth:moonrise-opt:J5ayzvZp"
modApi("me.shedaniel.cloth:cloth-config-fabric:17.0.144") {
exclude(group: "net.fabricmc.fabric-api")
}
}

loom {
Expand Down
31 changes: 24 additions & 7 deletions src/main/java/me/mrhua269/chlorophyll/Chlorophyll.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import com.mojang.logging.LogUtils;
import me.mrhua269.chlorophyll.utils.bridges.ITaskSchedulingLevel;
import me.mrhua269.chlorophyll.utils.TickThread;
import me.shedaniel.autoconfig.AutoConfig;
import me.shedaniel.autoconfig.serializer.Toml4jConfigSerializer;
import net.fabricmc.api.ModInitializer;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -17,15 +19,16 @@ public class Chlorophyll implements ModInitializer {
public static final Logger logger = LogUtils.getLogger();

private static final AtomicInteger threadIdGenerator = new AtomicInteger();
public static final ScheduledThreadPoolExecutor workerPool = new ScheduledThreadPoolExecutor(Runtime.getRuntime().availableProcessors(), task -> {
final Thread wrapped = new TickThread(task, "Chlorophyll World Scheduler Thread - " + threadIdGenerator.getAndIncrement(), true);
wrapped.setPriority(8);
wrapped.setContextClassLoader(MinecraftServer.class.getClassLoader());
return wrapped;
});
public static ScheduledThreadPoolExecutor workerPool;

private static ChlorophyllConfig chlorophyllConfig;

public static MinecraftServer server;

public static ChlorophyllConfig getConfig() {
return chlorophyllConfig;
}

public static void killAllAndAwait(){
for (ServerLevel level : server.getAllLevels()){
logger.info("Kill signalled to level {}", level.dimension().location());
Expand All @@ -49,8 +52,22 @@ public static void killAllAndAwait(){
}
}

private static void initExecutor() {
logger.info("Using {} threads for server level ticking.", chlorophyllConfig.worker_thread_count);

workerPool = new ScheduledThreadPoolExecutor(chlorophyllConfig.worker_thread_count, task -> {
final Thread wrapped = new TickThread(task, "Chlorophyll World Scheduler Thread - " + threadIdGenerator.getAndIncrement(), true);
wrapped.setPriority(8);
wrapped.setContextClassLoader(MinecraftServer.class.getClassLoader());
return wrapped;
});
}

@Override
public void onInitialize() {
logger.info("Using {} threads for server level ticking.", workerPool.getCorePoolSize());
AutoConfig.register(ChlorophyllConfig.class, Toml4jConfigSerializer::new);

chlorophyllConfig = AutoConfig.getConfigHolder(ChlorophyllConfig.class).getConfig();
initExecutor();
}
}
7 changes: 6 additions & 1 deletion src/main/java/me/mrhua269/chlorophyll/ChlorophyllConfig.java
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
package me.mrhua269.chlorophyll;

public class ChlorophyllConfig {
import me.shedaniel.autoconfig.ConfigData;
import me.shedaniel.autoconfig.annotation.Config;

@Config(name = "chlorophyll")
public class ChlorophyllConfig implements ConfigData {
public int worker_thread_count = Runtime.getRuntime().availableProcessors();
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void onTickChildren(MinecraftServer minecraftServer, BooleanSupplier bool
Chlorophyll.server = (MinecraftServer) (Object)this;
this.shouldPollChunkTask = false;

// Active the tick loops
// Try activating the tick loops
for (ServerLevel level : this.getAllLevels()){
((ITaskSchedulingLevel) level).chlorophyll$setupTickLoop();
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
"fabricloader": ">=${loader_version}",
"fabric": "*",
"minecraft": "${minecraft_version}",
"moonrise": "*"
"moonrise": "*",
"cloth-config": "*"
}
}

0 comments on commit e85a317

Please sign in to comment.