Skip to content

Commit

Permalink
Update to 1.21
Browse files Browse the repository at this point in the history
  • Loading branch information
Spottedleaf committed Jun 14, 2024
1 parent fff73cf commit 188ddaa
Show file tree
Hide file tree
Showing 38 changed files with 563 additions and 293 deletions.
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ org.gradle.jvmargs=-Xmx2G
org.gradle.daemon=false
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.20.6
yarn_mappings=1.20.6+build.2
minecraft_version=1.21
yarn_mappings=1.21+build.1
loader_version=0.15.11
# Mod Properties
mod_version=1.0.0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,24 @@ public static final class ChunkLoading {
public static final class Basic {
@Serializable(
comment = """
The maximum number of chunks to send to any given player, per second.
The maximum rate of chunks to send to any given player, per second. If this value is <= 0,
then there is no rate limit.
"""
)
public double playerMaxSendRate = -1.0;

@Serializable(
comment = """
The maximum number of chunks to load from disk for any given player, per second.
The maximum rate of chunks to load from disk for any given player, per second. If this value is <= 0,
then there is no rate limit.
"""
)
public double playerMaxLoadRate = -1.0;

@Serializable(
comment = """
The maximum number of chunks to generate for any given player, per second.
The maximum rate of chunks to generate for given player, per second. If this value is <= 0,
then there is no rate limit.
"""
)
public double playerMaxGenRate = -1.0;
Expand Down Expand Up @@ -78,8 +81,8 @@ public static final class Advanced {
@Serializable(
comment = """
The maximum amount of pending chunk loads per player. If
this value is less-than 1, then the player chunk loader will
automatically determine a value.
this value is 0, then the player chunk loader will automatically determine a value. If
this value is less-than 0, then there is no limit.
This value should be used to tune the saturation of the chunk system.
"""
Expand All @@ -89,8 +92,8 @@ public static final class Advanced {
@Serializable(
comment = """
The maximum amount of pending chunk generations per player. If
this value is less-than 1, then the player chunk loader will
automatically determine a value.
this value is 0, then the player chunk loader will automatically determine a value. If
this value is less-than 0, then there is no limit.
This value should be used to tune the saturation of the chunk system.
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ public T deserialize(final TypeAdapterRegistry registry, final Object input, fin
final Object fieldValue = inputMap.get(field.serializedKey);

if (fieldValue == null) {
if (field.required) {
throw new IllegalArgumentException("Missing required field '" + field.serializedKey + "' in " + this.constructor.getDeclaringClass());
}
continue;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

/**
* Annotation used on a class to indicate that its type adapter may automatically be generated. The class must have
*
* a public no-args constructor.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

/**
* Annotation indicating that a field should be deserialized or serialized from the config.
* By default, this annotation is assumed
* By default, this annotation is not assumed.
*/
@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.FIELD)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@ public void load(final InputStream is) throws IOException {
}

public void save(final File file) throws IOException {
this.save(file, "");
}

public void save(final File file, final String header) throws IOException {
if (file.isDirectory()) {
throw new IOException("File is a directory");
}
Expand All @@ -76,7 +80,7 @@ public void save(final File file) throws IOException {
tmp.createNewFile();
try {
try (final OutputStream os = new BufferedOutputStream(new FileOutputStream(tmp))) {
this.save(os);
this.save(os, header);
}

try {
Expand All @@ -93,10 +97,30 @@ public void save(final OutputStream os) throws IOException {
os.write(this.saveToString().getBytes(StandardCharsets.UTF_8));
}

public void save(final OutputStream os, final String header) throws IOException {
os.write(this.saveToString(header).getBytes(StandardCharsets.UTF_8));
}

public String saveToString() {
return this.yaml.dump(this.typeAdapters.serialize(this.config, this.clazz));
}

public String saveToString(final String header) {
if (header.isBlank()) {
return this.saveToString();
}

final StringBuilder ret = new StringBuilder();

for (final String line : header.split("\n")) {
ret.append("# ").append(line).append('\n');
}

ret.append('\n');

return ret.append(this.saveToString()).toString();
}

private static final class YamlConstructor extends Constructor {

public YamlConstructor(final LoaderOptions loadingConfig) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public final class MoonriseCommon {

private static final Logger LOGGER = LoggerFactory.getLogger(MoonriseCommon.class);

private static final File CONFIG_FILE = new File("moonrise.yaml");
private static final File CONFIG_FILE = new File(System.getProperty("Moonrise.ConfigFile", "moonrise.yml"));
private static final YamlConfig<MoonriseConfig> CONFIG;
static {
try {
Expand All @@ -22,6 +22,17 @@ public final class MoonriseCommon {
throw new RuntimeException(ex);
}
}
private static final String CONFIG_HEADER = """
This is the configuration file for Moonrise.
Each configuration option is prefixed with a comment to explain what it does. Additional changes to this file
other than modifying the options, such as adding comments, will be overwritten when Moonrise loads the config.
Below are the Moonrise startup flags. Note that startup flags must be placed in the JVM arguments, not
program arguments.
-DMoonrise.ConfigFile=<file> - Override the config file location. Maybe useful for multiple game versions.
-DMoonrise.WorkerThreadCount=<number> - Override the auto configured worker thread counts (worker-threads).
""";

static {
reloadConfig();
Expand All @@ -31,25 +42,27 @@ public static MoonriseConfig getConfig() {
return CONFIG.config;
}

public static void reloadConfig() {
public static boolean reloadConfig() {
if (CONFIG_FILE.exists()) {
try {
CONFIG.load(CONFIG_FILE);
} catch (final Exception ex) {
LOGGER.error("Failed to load configuration, using defaults", ex);
return;
return false;
}
}

// write back any changes, or create if needed
saveConfig();
return saveConfig();
}

public static void saveConfig() {
public static boolean saveConfig() {
try {
CONFIG.save(CONFIG_FILE);
CONFIG.save(CONFIG_FILE, CONFIG_HEADER);
return true;
} catch (final Exception ex) {
LOGGER.error("Failed to save configuration", ex);
return false;
}
}

Expand All @@ -66,10 +79,8 @@ public static void saveConfig() {

int workerThreads = MoonriseCommon.getConfig().workerThreads;

if (workerThreads < 0) {
if (workerThreads <= 0) {
workerThreads = defaultWorkerThreads;
} else {
workerThreads = Math.max(1, workerThreads);
}

WORKER_POOL = new PrioritisedThreadPool(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
public abstract class ChunkGeneratorMixin {

/**
* @reason Use the provided executor, chunk system sets this to something specific
* @reason Use Runnable:run, as we schedule onto the moonrise common pool
* @author Spottedleaf
*/
@Redirect(
Expand All @@ -32,9 +32,8 @@ public abstract class ChunkGeneratorMixin {
target = "Ljava/util/concurrent/CompletableFuture;supplyAsync(Ljava/util/function/Supplier;Ljava/util/concurrent/Executor;)Ljava/util/concurrent/CompletableFuture;"
)
)
private <U> CompletableFuture<U> redirectBiomesExecutor(final Supplier<U> supplier, final Executor badExecutor,
@Local(ordinal = 0, argsOnly = true) final Executor executor) {
return CompletableFuture.supplyAsync(supplier, executor);
private <U> CompletableFuture<U> redirectBiomesExecutor(final Supplier<U> supplier, final Executor badExecutor) {
return CompletableFuture.supplyAsync(supplier, Runnable::run);
}

/**
Expand Down
Loading

0 comments on commit 188ddaa

Please sign in to comment.