Skip to content

Commit

Permalink
feat: Add a config option to disable the chunk manager rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveplays28 committed Jul 16, 2024
1 parent 5f27dfc commit 0eb0cd5
Show file tree
Hide file tree
Showing 12 changed files with 59 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.isxander.yacl3.config.v2.api.SerialEntry;
import dev.isxander.yacl3.config.v2.api.autogen.AutoGen;
import dev.isxander.yacl3.config.v2.api.autogen.IntField;
import dev.isxander.yacl3.config.v2.api.autogen.TickBox;
import dev.isxander.yacl3.config.v2.api.serializer.GsonConfigSerializerBuilder;
import io.github.steveplays28.noisium.util.ModLoaderUtil;
import net.minecraft.util.Identifier;
Expand All @@ -12,19 +13,24 @@
import static io.github.steveplays28.noisium.Noisium.MOD_ID;

public class NoisiumConfig {
public static final @NotNull String JSON_5_FILE_SUFFIX = ".json5";
public static final @NotNull String JSON_5_FILE_EXTENSION = "json5";
public static final @NotNull ConfigClassHandler<NoisiumConfig> HANDLER = ConfigClassHandler.createBuilder(NoisiumConfig.class).id(
new Identifier(MOD_ID, "config")).serializer(config -> GsonConfigSerializerBuilder.create(config).setPath(
ModLoaderUtil.getConfigDir().resolve(String.format("%s/config%s", MOD_ID, JSON_5_FILE_SUFFIX))).setJson5(true).build()).build();
ModLoaderUtil.getConfigDir().resolve(String.format("%s/config.%s", MOD_ID, JSON_5_FILE_EXTENSION))).setJson5(true).build()).build();

private static final @NotNull String SERVER_CATEGORY = "Server";
private static final @NotNull String SERVER_CATEGORY = "server";
private static final @NotNull String SERVER_WORLD_CHUNK_MANAGER_GROUP = "serverWorldChunkManager";

@AutoGen(category = SERVER_CATEGORY)
@AutoGen(category = SERVER_CATEGORY, group = SERVER_WORLD_CHUNK_MANAGER_GROUP)
@SerialEntry(comment = "A re-implementation of the server world's chunk manager. Every world has its own chunk manager. After changing this option you MUST restart Minecraft.")
@TickBox
public boolean serverWorldChunkManagerEnabled = false;
@AutoGen(category = SERVER_CATEGORY, group = SERVER_WORLD_CHUNK_MANAGER_GROUP)
@SerialEntry(comment = "The amount of threads used by a server world's chunk manager. Every world has its own chunk manager, and thus its own threads. After changing this option you MUST restart the server.")
@IntField(min = 1, format = "%i threads")
public int serverWorldChunkManagerThreads = 2;
@AutoGen(category = SERVER_CATEGORY)
@SerialEntry(comment = "The amount of threads used by a server world's chunk manager lighting populator. Every world has its own chunk manager, and thus its own threads. After changing this option you MUST restart the server")
@AutoGen(category = SERVER_CATEGORY, group = SERVER_WORLD_CHUNK_MANAGER_GROUP)
@SerialEntry(comment = "The amount of threads used by a server world's chunk manager lighting populator. Every world has its own chunk manager, and thus its own threads. After changing this option you MUST restart the server.")
@IntField(min = 1, format = "%i threads")
public int serverWorldChunkManagerLightingThreads = 2;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

import com.google.common.collect.ImmutableMap;
import io.github.steveplays28.noisium.compat.lithium.NoisiumLithiumCompat;
import io.github.steveplays28.noisium.experimental.config.NoisiumConfig;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
Expand All @@ -15,34 +17,39 @@
import static io.github.steveplays28.noisium.util.ModLoaderUtil.isModPresent;

public class NoisiumMixinPlugin implements IMixinConfigPlugin {
private static final Supplier<Boolean> TRUE = () -> true;
private static final @NotNull Supplier<Boolean> TRUE = () -> true;
private static final @NotNull String DISTANT_HORIZONS_MOD_ID = "distanthorizons";

private static final Map<String, Supplier<Boolean>> CONDITIONS = ImmutableMap.of(
private static final @NotNull Map<String, Supplier<Boolean>> CONDITIONS = ImmutableMap.of(
"io.github.steveplays28.noisium.mixin.NoiseChunkGeneratorMixin", () -> !NoisiumLithiumCompat.isLithiumLoaded(),
"io.github.steveplays28.noisium.mixin.compat.lithium.LithiumNoiseChunkGeneratorMixin", NoisiumLithiumCompat::isLithiumLoaded,
"io.github.steveplays28.noisium.mixin.compat.distanthorizons.common.wrappers.world.gen.DHBatchGenerationEnvironmentMixin",
() -> isModPresent(DISTANT_HORIZONS_MOD_ID)
"io.github.steveplays28.noisium.mixin.compat.lithium.LithiumNoiseChunkGeneratorMixin", NoisiumLithiumCompat::isLithiumLoaded
);

@SuppressWarnings("ConstantValue")
@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
@NotNull var mixinPackageName = mixinClassName.replaceFirst("io\\.github\\.steveplays28\\.noisium\\.mixin\\.", "");
if (mixinPackageName.contains("experimental.compat.distanthorizons")) {
return NoisiumConfig.HANDLER.instance().serverWorldChunkManagerEnabled && isModPresent(DISTANT_HORIZONS_MOD_ID);
} else if (mixinPackageName.contains("experimental")) {
return NoisiumConfig.HANDLER.instance().serverWorldChunkManagerEnabled;
}

return CONDITIONS.getOrDefault(mixinClassName, TRUE).get();
}

@Override
public void onLoad(String mixinPackage) {}

@Override
public String getRefMapperConfig() {
public @Nullable String getRefMapperConfig() {
return null;
}

@Override
public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) {}

@Override
public List<String> getMixins() {
public @Nullable List<String> getMixins() {
return null;
}

Expand Down
7 changes: 7 additions & 0 deletions common/src/main/resources/assets/noisium/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"yacl3.config.noisium:config.category.server": "Server",
"yacl3.config.noisium:config.category.server.group.serverWorldChunkManager": "Server World Chunk Manager (experimental)",
"yacl3.config.noisium:config.serverWorldChunkManagerEnabled": "Server World Chunk Manager",
"yacl3.config.noisium:config.serverWorldChunkManagerThreads": "Server World Chunk Manager Threads",
"yacl3.config.noisium:config.serverWorldChunkManagerLightingThreads": "Server World Chunk Manager Lighting Threads"
}
7 changes: 6 additions & 1 deletion fabric/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ dependencies {
processResources {
inputs.property "version", project.version

from(project(":common").sourceSets["main"].resources) {
include("assets", "data", "resourcepacks")
}

filesMatching("fabric.mod.json") {
expand "version": project.version,
"mod_id": rootProject.mod_id,
Expand All @@ -64,7 +68,8 @@ processResources {
"modrinth_project_id": rootProject.modrinth_project_id,
"fabric_loader_version": rootProject.fabric_loader_version,
"supported_minecraft_version": rootProject.supported_minecraft_version,
"architectury_api_version": rootProject.architectury_api_version
"architectury_api_version": rootProject.architectury_api_version,
"yet_another_config_lib_version": rootProject.yet_another_config_lib_version
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.steveplays28.noisium.fabric.mixin.compat.fabric.api.networking.v1;
package io.github.steveplays28.noisium.fabric.mixin.experimental.compat.fabric.api.networking.v1;

import com.google.common.collect.ImmutableMap;
import net.fabricmc.loader.api.FabricLoader;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.steveplays28.noisium.fabric.mixin.compat.fabric.api.networking.v1;
package io.github.steveplays28.noisium.fabric.mixin.experimental.compat.fabric.api.networking.v1;

import net.fabricmc.fabric.api.networking.v1.PlayerLookup;
import net.minecraft.entity.Entity;
Expand Down
3 changes: 2 additions & 1 deletion fabric/src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@
"depends": {
"fabricloader": ">=${fabric_loader_version}",
"minecraft": "${supported_minecraft_version}",
"architectury": ">=${architectury_api_version}"
"architectury": ">=${architectury_api_version}",
"yet_another_config_lib_v3": ">=${yet_another_config_lib_version}-fabric"
},
"suggests": {
"c2me": "*"
Expand Down
4 changes: 2 additions & 2 deletions fabric/src/main/resources/noisium-fabric.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
"minVersion": "0.8",
"package": "io.github.steveplays28.noisium.fabric.mixin",
"compatibilityLevel": "JAVA_17",
"plugin": "io.github.steveplays28.noisium.fabric.mixin.compat.fabric.api.networking.v1.NoisiumFabricMixinPlugin",
"plugin": "io.github.steveplays28.noisium.fabric.mixin.experimental.compat.fabric.api.networking.v1.NoisiumFabricMixinPlugin",
"mixins": [
"compat.fabric.api.networking.v1.PlayerLookupMixin"
"experimental.compat.fabric.api.networking.v1.PlayerLookupMixin"
],
"client": [],
"injectors": {
Expand Down
7 changes: 6 additions & 1 deletion forge/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ dependencies {
processResources {
inputs.property "version", "${project.version}-forge"

from(project(":common").sourceSets["main"].resources) {
include("assets", "data", "resourcepacks")
}

filesMatching("META-INF/mods.toml") {
expand "version": project.version,
"mod_id": rootProject.mod_id,
Expand All @@ -65,7 +69,8 @@ processResources {
"modrinth_project_id": rootProject.modrinth_project_id,
"forge_version": rootProject.neoforge_version,
"supported_minecraft_version": rootProject.supported_minecraft_version,
"architectury_api_version": rootProject.architectury_api_version
"architectury_api_version": rootProject.architectury_api_version,
"yet_another_config_lib_version": rootProject.yet_another_config_lib_version
}
}

Expand Down
7 changes: 7 additions & 0 deletions forge/src/main/resources/META-INF/mods.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,10 @@ mandatory = true
versionRange = ">=${architectury_api_version}"
ordering = "NONE"
side = "BOTH"

[[dependencies.noisium]]
modId = "yet_another_config_lib_v3"
mandatory = true
versionRange = ">=${yet_another_config_lib_version}"
ordering = "NONE"
side = "BOTH"
Binary file removed forge/src/main/resources/assets/noisium/icon.png
Binary file not shown.

0 comments on commit 0eb0cd5

Please sign in to comment.