mirror of
https://github.com/TeamMidnightDust/MidnightLib.git
synced 2025-12-16 09:15:10 +01:00
stonecutter: improve backwards-compatibility
Builds targetting Minecraft versions below 1.21.6 will now once again contain the `getScreen` method with `Screen` as their return value instead of `MidnightConfigScreen`. This ensures that mods compiled for older MidnightLib versions continue working as expected. The return value has to be changed to `MidnightConfigScreen` in 1.21.6 and up due to NeoForge removing support for the `@OnlyIn` annotation – thus breaking server-only installations when referencing client-only classes like `Screen`.
This commit is contained in:
@@ -7,7 +7,7 @@ org.gradle.parallel=false
|
|||||||
#org.gradle.configureondemand=true
|
#org.gradle.configureondemand=true
|
||||||
|
|
||||||
# Mod properties
|
# Mod properties
|
||||||
mod.version=1.9.0-beta.1
|
mod.version=1.9.0-beta.2
|
||||||
mod.group=eu.midnightdust
|
mod.group=eu.midnightdust
|
||||||
mod.id=midnightlib
|
mod.id=midnightlib
|
||||||
mod.name=MidnightLib
|
mod.name=MidnightLib
|
||||||
|
|||||||
@@ -29,9 +29,17 @@ import java.util.function.Function;
|
|||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
//? if < 1.21.6 {
|
||||||
|
/*//? fabric
|
||||||
|
import net.fabricmc.api.*;
|
||||||
|
//? neoforge
|
||||||
|
/^import net.neoforged.api.distmarker.*;^/
|
||||||
|
//? forge
|
||||||
|
/^import net.minecraftforge.api.distmarker.*;^/
|
||||||
|
*///?}
|
||||||
|
|
||||||
/** MidnightConfig is an incredibly lightweight, but still fully-featured config library for Minecraft mods.<br>
|
/** MidnightConfig is an incredibly lightweight, but still fully-featured config library for Minecraft mods.<br>
|
||||||
* Originally based on <a href="https://github.com/Minenash/TinyConfig">TinyConfig</a> by Minenash.*/
|
* Originally based on <a href="https://github.com/Minenash/TinyConfig">TinyConfig</a> by Minenash.*/
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
public abstract class MidnightConfig {
|
public abstract class MidnightConfig {
|
||||||
private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)");
|
private static final Pattern INTEGER_ONLY = Pattern.compile("(-?[0-9]*)");
|
||||||
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?(\\d+\\.?\\d*|\\d*\\.?\\d+|\\.)");
|
private static final Pattern DECIMAL_ONLY = Pattern.compile("-?(\\d+\\.?\\d*|\\d*\\.?\\d+|\\.)");
|
||||||
@@ -67,6 +75,7 @@ public abstract class MidnightConfig {
|
|||||||
* */
|
* */
|
||||||
protected static <T extends MidnightConfig> T createInstance(String modid, Class<? extends MidnightConfig> configClass) {
|
protected static <T extends MidnightConfig> T createInstance(String modid, Class<? extends MidnightConfig> configClass) {
|
||||||
try {
|
try {
|
||||||
|
//noinspection unchecked
|
||||||
T instance = (T) configClass.getDeclaredConstructor().newInstance();
|
T instance = (T) configClass.getDeclaredConstructor().newInstance();
|
||||||
instance.modid = modid;
|
instance.modid = modid;
|
||||||
instance.configClass = configClass;
|
instance.configClass = configClass;
|
||||||
@@ -280,10 +289,16 @@ public abstract class MidnightConfig {
|
|||||||
* @param parent The parent screen, which will be returned to when exiting the config
|
* @param parent The parent screen, which will be returned to when exiting the config
|
||||||
* @param modid The mod of which to load the config screen
|
* @param modid The mod of which to load the config screen
|
||||||
* */
|
* */
|
||||||
|
//? if < 1.21.6 {
|
||||||
|
/*/^? fabric {^/ @Environment(EnvType.CLIENT) /^?} else {^/ /^@OnlyIn(Dist.CLIENT) ^//^?}^/
|
||||||
|
public static Screen getScreen(Screen parent, String modid) {
|
||||||
|
*///?} else {
|
||||||
public static MidnightConfigScreen getScreen(Screen parent, String modid) {
|
public static MidnightConfigScreen getScreen(Screen parent, String modid) {
|
||||||
|
//?}
|
||||||
return configInstances.get(modid).getScreen(parent);
|
return configInstances.get(modid).getScreen(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of the config screen.
|
* Creates an instance of the config screen.
|
||||||
* This can be overridden to return a fully custom config screen.
|
* This can be overridden to return a fully custom config screen.
|
||||||
|
|||||||
Reference in New Issue
Block a user