Skip to content

Commit 834480c

Browse files
committed
Merge branch 'ver/1.16.5' of github.com:YatopiaMC/C2ME-fabric into ver/1.16.5
2 parents da2eb01 + 2eaa71f commit 834480c

20 files changed

+265
-105
lines changed

.github/workflows/build.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ jobs:
1111

1212
steps:
1313
- uses: actions/checkout@v2
14-
- name: Set up JDK 11
14+
- name: Set up JDK 16
1515
uses: actions/setup-java@v1
1616
with:
17-
java-version: 11
17+
java-version: 16
1818

1919
- uses: actions/cache@v2
2020
with:

Jenkinsfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ pipeline {
44
stages {
55
stage('Build') {
66
tools {
7-
jdk "OpenJDK 11"
7+
jdk "OpenJDK 16"
88
}
99
steps {
1010
withMaven(

build.gradle

+11-7
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,12 @@ version = project.mod_version
2121
group = project.maven_group // http://maven.apache.org/guides/mini/guide-naming-conventions.html
2222
archivesBaseName = "${project.archives_base_name}-mc${project.minecraft_version}"
2323

24-
sourceCompatibility = JavaVersion.VERSION_11
25-
targetCompatibility = JavaVersion.VERSION_11
24+
sourceCompatibility = JavaVersion.VERSION_15
25+
targetCompatibility = JavaVersion.VERSION_15
26+
27+
tasks.withType(JavaCompile).each {
28+
it.options.compilerArgs.add('--enable-preview')
29+
}
2630

2731
println('Java: ' + System.getProperty('java.version') + ' JVM: ' + System.getProperty('java.vm.version') + '(' + System.getProperty('java.vendor') + ') Arch: ' + System.getProperty('os.arch'))
2832
minecraft {
@@ -134,10 +138,8 @@ dependencies {
134138
// The userdev artifact is a special name and will get all sorts of transformations applied to it.
135139
minecraft "net.minecraftforge:forge:${project.minecraft_version}-${project.forge_version}"
136140

137-
// You may put jars on which you depend on in ./libs or you may define them like so..
138-
// compile "some.group:artifact:version:classifier"
139-
// compile "some.group:artifact:version"
140-
compile "com.ibm.async:asyncutil:0.1.0"
141+
implementation "com.ibm.async:asyncutil:${async_util_version}"
142+
implementation "com.electronwill.night-config:toml:${night_config_version}"
141143

142144
// Real examples
143145
// compile 'com.mod-buildcraft:buildcraft:6.0.8:dev' // adds buildcraft to the dev env
@@ -187,7 +189,9 @@ jar {
187189

188190
shadowJar {
189191
dependencies {
190-
include(dependency("com.ibm.async:asyncutil:0.1.0"))
192+
include(dependency("com.ibm.async:asyncutil:${async_util_version}"))
193+
include(dependency("com.electronwill.night-config:toml:${night_config_version}"))
194+
include(dependency("com.electronwill.night-config:core:${night_config_version}"))
191195
}
192196
finalizedBy('reobfJar')
193197
}

gradle.properties

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
# Done to increase the memory available to gradle.
1+
# Done to increase the memory available to gradle and improve build times.
22
org.gradle.jvmargs=-Xmx4G
33
org.gradle.parallel=true
4-
org.gradle.daemon=false
4+
org.gradle.configureondemand=true
55
# Minecraft properties
66
minecraft_version=1.16.5
77
forge_version=36.1.2
88
# Mod Properties
99
mod_version=0.1-SNAPSHOT
1010
maven_group=org.yatopiamc.c2me
1111
archives_base_name=c2me-forge
12-
12+
# Java Dependencies
13+
async_util_version=0.1.0
14+
night_config_version=3.6.3
+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
1+
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9-all.zip

src/main/java/org/yatopiamc/c2me/common/config/C2MEConfig.java

+23-7
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,17 @@
44
import com.electronwill.nightconfig.core.file.CommentedFileConfig;
55
import com.google.common.base.Preconditions;
66
import net.minecraftforge.fml.loading.FMLLoader;
7+
import org.apache.logging.log4j.LogManager;
8+
import org.apache.logging.log4j.Logger;
79
import org.yatopiamc.c2me.C2MEMod;
810
import org.yatopiamc.c2me.common.util.ConfigDirUtil;
911

12+
import java.util.List;
13+
1014
public class C2MEConfig {
1115

16+
static final Logger LOGGER = LogManager.getLogger("C2ME Config");
17+
1218
public static final AsyncIoConfig asyncIoConfig;
1319
public static final ThreadedWorldGenConfig threadedWorldGenConfig;
1420

@@ -21,34 +27,44 @@ public class C2MEConfig {
2127
.build();
2228
config.load();
2329

24-
asyncIoConfig = new AsyncIoConfig(ConfigUtils.getValue(config, "asyncIO", CommentedConfig::inMemory, "Configuration for async io system"));
25-
threadedWorldGenConfig = new ThreadedWorldGenConfig(ConfigUtils.getValue(config, "threadedWorldGen", CommentedConfig::inMemory, "Configuration for threaded world generation"));
30+
final ConfigUtils.ConfigScope configScope = new ConfigUtils.ConfigScope(config);
31+
asyncIoConfig = new AsyncIoConfig(ConfigUtils.getValue(configScope, "asyncIO", CommentedConfig::inMemory, "Configuration for async io system", List.of(), null));
32+
threadedWorldGenConfig = new ThreadedWorldGenConfig(ConfigUtils.getValue(configScope, "threadedWorldGen", CommentedConfig::inMemory, "Configuration for threaded world generation", List.of(), null));
33+
configScope.removeUnusedKeys();
2634
config.save();
2735
config.close();
2836
C2MEMod.LOGGER.info("Configuration loaded successfully after {}ms", (System.nanoTime() - startTime) / 1_000_000.0);
2937
}
3038

3139
public static class AsyncIoConfig {
40+
public final boolean enabled;
3241
public final int serializerParallelism;
3342
public final int ioWorkerParallelism;
3443

3544
public AsyncIoConfig(CommentedConfig config) {
3645
Preconditions.checkNotNull(config, "asyncIo config is not present");
37-
this.serializerParallelism = ConfigUtils.getValue(config, "serializerParallelism", () -> Math.min(2, Runtime.getRuntime().availableProcessors()), "IO worker executor parallelism", ConfigUtils.CheckType.THREAD_COUNT);
38-
this.ioWorkerParallelism = ConfigUtils.getValue(config, "ioWorkerParallelism", () -> Math.min(6, Runtime.getRuntime().availableProcessors()), "Serializer executor parallelism", ConfigUtils.CheckType.THREAD_COUNT);
46+
final ConfigUtils.ConfigScope configScope = new ConfigUtils.ConfigScope(config);
47+
this.enabled = ConfigUtils.getValue(configScope, "enabled", () -> true, "Whether to enable this feature", List.of("radon", "immersive_portals"), false);
48+
this.serializerParallelism = ConfigUtils.getValue(configScope, "serializerParallelism", () -> Math.min(2, Runtime.getRuntime().availableProcessors()), "unused", List.of(), null, ConfigUtils.CheckType.THREAD_COUNT);
49+
this.ioWorkerParallelism = ConfigUtils.getValue(configScope, "ioWorkerParallelism", () -> Math.min(6, Runtime.getRuntime().availableProcessors()), "Serializer executor parallelism", List.of(), null, ConfigUtils.CheckType.THREAD_COUNT);
50+
configScope.removeUnusedKeys();
3951
}
4052
}
4153

4254
public static class ThreadedWorldGenConfig {
4355
public final boolean enabled;
4456
public final int parallelism;
4557
public final boolean allowThreadedFeatures;
58+
public final boolean reduceLockRadius;
4659

4760
public ThreadedWorldGenConfig(CommentedConfig config) {
4861
Preconditions.checkNotNull(config, "threadedWorldGen config is not present");
49-
this.enabled = ConfigUtils.getValue(config, "enabled", () -> true, "Whether to enable this feature");
50-
this.parallelism = ConfigUtils.getValue(config, "parallelism", () -> Math.min(6, Runtime.getRuntime().availableProcessors()), "World generation worker executor parallelism", ConfigUtils.CheckType.THREAD_COUNT);
51-
this.allowThreadedFeatures = ConfigUtils.getValue(config, "allowThreadedFeatures", () -> false, "Whether to allow feature generation (world decorations like trees, ores and etc.) run in parallel");
62+
final ConfigUtils.ConfigScope configScope = new ConfigUtils.ConfigScope(config);
63+
this.enabled = ConfigUtils.getValue(configScope, "enabled", () -> true, "Whether to enable this feature", List.of(), null);
64+
this.parallelism = ConfigUtils.getValue(configScope, "parallelism", () -> Math.min(6, Runtime.getRuntime().availableProcessors()), "World generation worker executor parallelism", List.of(), null, ConfigUtils.CheckType.THREAD_COUNT);
65+
this.allowThreadedFeatures = ConfigUtils.getValue(configScope, "allowThreadedFeatures", () -> false, "Whether to allow feature generation (world decorations like trees, ores and etc.) run in parallel \n (may cause incompatibility with other mods)", List.of(), null);
66+
this.reduceLockRadius = ConfigUtils.getValue(configScope, "reduceLockRadius", () -> false, "Whether to allow reducing lock radius (faster but UNSAFE) (YOU HAVE BEEN WARNED) \n (may cause incompatibility with other mods)", List.of(), null);
67+
configScope.removeUnusedKeys();
5268
}
5369
}
5470

src/main/java/org/yatopiamc/c2me/common/config/ConfigUtils.java

+42-6
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,62 @@
11
package org.yatopiamc.c2me.common.config;
22

33
import com.electronwill.nightconfig.core.CommentedConfig;
4+
import com.electronwill.nightconfig.core.Config;
45
import com.google.common.base.Preconditions;
6+
import com.google.common.base.Suppliers;
7+
import net.minecraftforge.fml.loading.FMLLoader;
8+
import net.minecraftforge.fml.loading.moddiscovery.ModInfo;
59

610
import java.util.Arrays;
11+
import java.util.Collections;
12+
import java.util.HashSet;
13+
import java.util.List;
714
import java.util.Objects;
15+
import java.util.Set;
816
import java.util.function.Supplier;
17+
import java.util.stream.Collectors;
918

1019
public class ConfigUtils {
1120

12-
public static <T> T getValue(CommentedConfig config, String key, Supplier<T> def, String comment, CheckType... checks) {
21+
private static final boolean IGNORE_INCOMPATIBILITY = Boolean.parseBoolean(System.getProperty("org.yatopia.c2me.common.config.ignoreIncompatibility", "false"));
22+
23+
public static <T> T getValue(ConfigScope config, String key, Supplier<T> deff, String comment, List<String> incompatibleMods, T incompatibleDefault, CheckType... checks) {
24+
if (IGNORE_INCOMPATIBILITY) C2MEConfig.LOGGER.fatal("Ignoring incompatibility check. You will get NO support if you do this unless explicitly stated. ");
1325
Preconditions.checkNotNull(config);
1426
Preconditions.checkNotNull(key);
1527
Preconditions.checkArgument(!key.isEmpty());
16-
Preconditions.checkNotNull(def);
17-
if (!config.contains(key) || (checks.length != 0 && Arrays.stream(checks).anyMatch(checkType -> !checkType.check(config.get(key))))) config.set(key, def.get());
18-
config.setComment(key, " " + comment);
19-
return Objects.requireNonNull(config.get(key));
28+
Preconditions.checkNotNull(deff);
29+
Preconditions.checkNotNull(incompatibleMods);
30+
final Set<ModInfo> foundIncompatibleMods = IGNORE_INCOMPATIBILITY ? Collections.emptySet() : FMLLoader.getLoadingModList().getMods().stream().filter(modInfo -> incompatibleMods.contains(modInfo.getModId())).collect(Collectors.toSet());
31+
Supplier<T> def = Suppliers.memoize(deff::get);
32+
if (!foundIncompatibleMods.isEmpty()) {
33+
comment = comment + " \n INCOMPATIBILITY: Set to " + incompatibleDefault + " forcefully by: " + String.join(", ", foundIncompatibleMods.stream().map(ModInfo::getModId).collect(Collectors.toSet()));
34+
35+
}
36+
config.processedKeys.add(key);
37+
if (!config.config.contains(key) || (checks.length != 0 && Arrays.stream(checks).anyMatch(checkType -> !checkType.check(config.config.get(key)))))
38+
config.config.set(key, def.get());
39+
if (def.get() instanceof Config) config.config.setComment(key, String.format(" %s", comment));
40+
else config.config.setComment(key, String.format(" (Default: %s) %s", def.get(), comment));
41+
return foundIncompatibleMods.isEmpty() ? Objects.requireNonNull(config.config.get(key)) : incompatibleDefault;
42+
}
43+
44+
static class ConfigScope {
45+
final CommentedConfig config;
46+
final Set<String> processedKeys;
47+
48+
ConfigScope(CommentedConfig config) {
49+
this.config = config;
50+
this.processedKeys = new HashSet<>();
51+
}
52+
53+
void removeUnusedKeys() {
54+
config.entrySet().removeIf(entry -> !processedKeys.contains(entry.getKey()));
55+
}
2056
}
2157

2258
public enum CheckType {
23-
THREAD_COUNT {
59+
THREAD_COUNT() {
2460
@Override
2561
public <T> boolean check(T value) {
2662
return value instanceof Number && ((Number) value).intValue() >= 1 && ((Number) value).intValue() <= 0x7fff;

src/main/java/org/yatopiamc/c2me/common/structs/LongHashSet.java

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public Object[] toArray() {
5252
}
5353

5454
@Nonnull
55+
@SuppressWarnings("SuspiciousToArrayCall")
5556
@Override
5657
public <T> T[] toArray(@Nonnull T[] a) {
5758
return delegate.toArray(a);

src/main/java/org/yatopiamc/c2me/common/threading/chunkio/AsyncSerializationManager.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,20 @@ public static class Scope {
6565
public final Map<BlockPos, TileEntity> blockEntities;
6666
private final AtomicBoolean isOpen = new AtomicBoolean(false);
6767

68+
@SuppressWarnings("unchecked")
6869
public Scope(IChunk chunk, ServerWorld world) {
6970
this.pos = chunk.getPos();
7071
this.lighting = Arrays.stream(LightType.values()).map(type -> new CachedLightingView(world.getLightEngine(), chunk.getPos(), type)).collect(Collectors.toMap(CachedLightingView::getLightType, Function.identity()));
7172
final ITickList<Block> blockTickScheduler = chunk.getBlockTicks();
72-
if (blockTickScheduler instanceof DeepCloneable) {
73-
this.blockTickScheduler = (ITickList<Block>) ((DeepCloneable) blockTickScheduler).deepClone();
73+
if (blockTickScheduler instanceof DeepCloneable cloneable) {
74+
this.blockTickScheduler = (ITickList<Block>) cloneable.deepClone();
7475
} else {
7576
final ServerTickList<Block> worldBlockTickScheduler = world.getBlockTicks();
7677
this.blockTickScheduler = new SerializableTickList<>(Registry.BLOCK::getKey, worldBlockTickScheduler.fetchTicksInChunk(chunk.getPos(), false, true), world.getGameTime());
7778
}
7879
final ITickList<Fluid> fluidTickScheduler = chunk.getLiquidTicks();
79-
if (fluidTickScheduler instanceof DeepCloneable) {
80-
this.fluidTickScheduler = (ITickList<Fluid>) ((DeepCloneable) fluidTickScheduler).deepClone();
80+
if (fluidTickScheduler instanceof DeepCloneable cloneable) {
81+
this.fluidTickScheduler = (ITickList<Fluid>) cloneable.deepClone();
8182
} else {
8283
final ServerTickList<Fluid> worldFluidTickScheduler = world.getLiquidTicks();
8384
this.fluidTickScheduler = new SerializableTickList<>(Registry.FLUID::getKey, worldFluidTickScheduler.fetchTicksInChunk(chunk.getPos(), false, true), world.getGameTime());

src/main/java/org/yatopiamc/c2me/common/threading/worldgen/ChunkStatusUtils.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,12 @@ public static ChunkStatusThreadingType getThreadingType(final ChunkStatus status
4242

4343
public static <T> CompletableFuture<T> runChunkGenWithLock(ChunkPos target, int radius, AsyncNamedLock<ChunkPos> chunkLock, Supplier<CompletableFuture<T>> action) {
4444
return CompletableFuture.supplyAsync(() -> {
45-
List<AsyncLock> fetchedLocks = new ArrayList<>((radius + 1) * (radius + 1));
45+
ArrayList<ChunkPos> fetchedLocks = new ArrayList<>((2 * radius + 1) * (2 * radius + 1));
4646
for (int x = target.x - radius; x <= target.x + radius; x++)
4747
for (int z = target.z - radius; z <= target.z + radius; z++)
48-
fetchedLocks.add(new AsyncNamedLockDelegateAsyncLock<>(chunkLock, new ChunkPos(x, z)));
48+
fetchedLocks.add(new ChunkPos(x, z));
4949

50-
return new AsyncCombinedLock(new HashSet<>(fetchedLocks)).getFuture().thenComposeAsync(lockToken -> {
50+
return new AsyncCombinedLock(chunkLock, new HashSet<>(fetchedLocks)).getFuture().thenComposeAsync(lockToken -> {
5151
final CompletableFuture<T> future = action.get();
5252
future.thenRun(lockToken::releaseLock);
5353
return future;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package org.yatopiamc.c2me.common.threading.worldgen;
2+
3+
public interface IChunkStatus {
4+
5+
void calculateReducedTaskRadius();
6+
7+
}

0 commit comments

Comments
 (0)