mirror of
https://github.com/BX-Team/DivineMC.git
synced 2025-12-22 16:29:23 +00:00
regionized chunk ticking
This commit is contained in:
@@ -246,6 +246,24 @@ public class DivineConfig {
|
||||
"modpacks where many structure mods are using very high weight values in their template pools.");
|
||||
}
|
||||
|
||||
public static boolean enableRegionizedChunkTicking = false;
|
||||
public static int regionizedChunkTickingExecutorThreadCount = 4;
|
||||
public static int regionizedChunkTickingExecutorThreadPriority = Thread.NORM_PRIORITY;
|
||||
private static void regionizedChunkTicking() {
|
||||
enableRegionizedChunkTicking = getBoolean("settings.regionized-chunk-ticking.enable", enableRegionizedChunkTicking,
|
||||
"Enables regionized chunk ticking. This feature is similar to Folia");
|
||||
|
||||
regionizedChunkTickingExecutorThreadCount = getInt("settings.regionized-chunk-ticking.executor-thread-count", regionizedChunkTickingExecutorThreadCount,
|
||||
"The amount of threads to allocate to regionized chunk ticking.");
|
||||
regionizedChunkTickingExecutorThreadPriority = getInt("settings.regionized-chunk-ticking.executor-thread-priority", regionizedChunkTickingExecutorThreadPriority,
|
||||
"Configures the thread priority of the executor");
|
||||
|
||||
if (regionizedChunkTickingExecutorThreadCount < 1 || regionizedChunkTickingExecutorThreadCount > 10) {
|
||||
LOGGER.warn("Invalid regionized chunk ticking thread count: " + regionizedChunkTickingExecutorThreadCount + ", resetting to default (5)");
|
||||
regionizedChunkTickingExecutorThreadCount = 5;
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean skipUselessSecondaryPoiSensor = true;
|
||||
public static boolean clumpOrbs = true;
|
||||
public static boolean ignoreMovedTooQuicklyWhenLagging = true;
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package org.bxteam.divinemc.util;
|
||||
|
||||
import com.mojang.logging.LogUtils;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
public class NamedAgnosticThreadFactory<T extends Thread> implements ThreadFactory {
|
||||
private static final Logger LOGGER = LogUtils.getLogger();
|
||||
private final ThreadGroup group;
|
||||
private final AtomicInteger threadNumber = new AtomicInteger(1);
|
||||
private final String namePrefix;
|
||||
private final ThreadBuilderFunction<T> typeOfThread;
|
||||
private final int priority;
|
||||
|
||||
public NamedAgnosticThreadFactory(String name, ThreadBuilderFunction<T> typeOfThread, int priority) {
|
||||
this.typeOfThread = typeOfThread;
|
||||
this.priority = priority;
|
||||
this.group = Thread.currentThread().getThreadGroup();
|
||||
this.namePrefix = name + "-";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Thread newThread(@NotNull Runnable runnable) {
|
||||
T thread = typeOfThread.apply(this.group, runnable, this.namePrefix + this.threadNumber.getAndIncrement());
|
||||
thread.setUncaughtExceptionHandler((threadx, throwable) -> {
|
||||
LOGGER.error("Caught exception in thread {} from {}", threadx, runnable);
|
||||
LOGGER.error("", throwable);
|
||||
});
|
||||
if (thread.getPriority() != priority) {
|
||||
thread.setPriority(priority);
|
||||
}
|
||||
|
||||
return thread;
|
||||
}
|
||||
|
||||
public interface ThreadBuilderFunction<T extends Thread> {
|
||||
T apply(ThreadGroup threadGroup, Runnable runnable, String name);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user