Skip to content

Commit

Permalink
feat: Support NeoForge modloader
Browse files Browse the repository at this point in the history
  • Loading branch information
Griefed committed Aug 11, 2023
1 parent d77762b commit 7ad2f66
Show file tree
Hide file tree
Showing 19 changed files with 1,047 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ configuration.log.error.checkcopydirs.read=No read-permission for {0}
configuration.log.error.checkcopydirs.checkforregex=Invalid regex entry: {0}
configuration.log.error.checkcopydirs.checkforregex.invalid=Entry must contain, or start with, ==
configuration.log.error.checkcopydirs.checkforregex.invalid.regex=Invalid regex specified: {0}. Error near regex-index {1}.
configuration.log.error.checkmodloader=Invalid modloader specified. Modloader must be either Forge, Fabric or Quilt.
configuration.log.error.checkmodloader=Invalid modloader specified. Modloader must be either Forge, NeoForge, Fabric, Quilt or LegacyFabric.
configuration.log.error.checkmodloaderversion=Specified incorrect modloader version. Please check your modpack for the correct version and enter again.
configuration.log.error.checkmodloaderandversion=Minecraft {0} and {1} {2} are not compatible.
configuration.log.error.isdir.copydir=There's something wrong with your setting of directories to include in your server pack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import mu.KotlinLogging
abstract class Configuration<F, P> {
protected val log = KotlinLogging.logger {}
protected val forge = "^forge$".toRegex()
protected val neoForge = "^neoforge$".toRegex()

Check notice on line 36 in serverpackcreator-api/src/commonMain/kotlin/de/griefed/serverpackcreator/api/Configuration.kt

View workflow job for this annotation

GitHub Actions / Qodana Community for JVM

Class member can have 'private' visibility

Property 'neoForge' could be private
protected val fabric = "^fabric$".toRegex()
protected val quilt = "^quilt$".toRegex()
protected val legacyFabric = "^legacyfabric$".toRegex()
Expand Down Expand Up @@ -160,6 +161,7 @@ abstract class Configuration<F, P> {
*/
fun checkModloader(modloader: String) =
if (modloader.lowercase().matches(forge)
|| modloader.lowercase().matches(neoForge)
|| modloader.lowercase().matches(fabric)
|| modloader.lowercase().matches(quilt)
|| modloader.lowercase().matches(legacyFabric)
Expand Down Expand Up @@ -223,9 +225,7 @@ abstract class Configuration<F, P> {
* @author Griefed
*/
fun printEncounteredErrors(encounteredErrors: List<String>) {
log.error(
"Encountered ${encounteredErrors.size} errors during the configuration check."
)
log.error("Encountered ${encounteredErrors.size} errors during the configuration check.")
var encounteredErrorNumber: Int
for (i in encounteredErrors.indices) {
encounteredErrorNumber = i + 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import de.griefed.serverpackcreator.api.utilities.CommentedConfig
@Suppress("MemberVisibilityCanBePrivate")
abstract class Pack<F, J, out P> {
protected val forge = "^forge$".toRegex()
protected val neoForge = "^neoforge$".toRegex()
protected val fabric = "^fabric$".toRegex()
protected val quilt = "^quilt$".toRegex()
protected val legacyFabric = "^legacyfabric$".toRegex()
Expand All @@ -49,6 +50,8 @@ abstract class Pack<F, J, out P> {
set(newModLoader) {
if (newModLoader.lowercase().matches(forge)) {
field = "Forge"
} else if (newModLoader.lowercase().matches(neoForge)) {
field = "NeoForge"
} else if (newModLoader.lowercase().matches(fabric)) {
field = "Fabric"
} else if (newModLoader.lowercase().matches(quilt)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@ enum class Type {
*/
FORGE,

/**
* Indicates this operation concerns NeoForge.
*/
NEO_FORGE,

/**
* Indicates this operation concerns Fabric.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package de.griefed.serverpackcreator.api.versionmeta
import de.griefed.serverpackcreator.api.utilities.URL
import de.griefed.serverpackcreator.api.versionmeta.fabric.FabricMeta
import de.griefed.serverpackcreator.api.versionmeta.forge.ForgeMeta
import de.griefed.serverpackcreator.api.versionmeta.neoforge.NeoForgeMeta
import de.griefed.serverpackcreator.api.versionmeta.legacyfabric.LegacyFabricMeta
import de.griefed.serverpackcreator.api.versionmeta.minecraft.MinecraftMeta
import de.griefed.serverpackcreator.api.versionmeta.quilt.QuiltMeta
Expand All @@ -48,6 +49,9 @@ expect class VersionMeta {
@Suppress("MemberVisibilityCanBePrivate")
val forgeUrlManifest: URL

@Suppress("MemberVisibilityCanBePrivate")
val neoForgeUrlManifest: URL

@Suppress("MemberVisibilityCanBePrivate")
val fabricUrlManifest: URL

Expand Down Expand Up @@ -81,6 +85,12 @@ expect class VersionMeta {
@Suppress("MemberVisibilityCanBePrivate")
val forge: ForgeMeta

/**
* The NeoForgeMeta-instance for working with NeoForge versions and information about them.
*/
@Suppress("MemberVisibilityCanBePrivate")
val neoForge: NeoForgeMeta

/**
* The QuiltMeta-instance for working with Quilt versions and information about them.
*/
Expand All @@ -92,5 +102,4 @@ expect class VersionMeta {
*/
@Suppress("MemberVisibilityCanBePrivate")
val legacyFabric: LegacyFabricMeta

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,220 @@
package de.griefed.serverpackcreator.api.versionmeta.neoforge

import de.griefed.serverpackcreator.api.utilities.common.Utilities
import java.io.File
import java.net.URL
import java.util.*

/**
* Forge meta containing information about available Forge releases.
*
* @param neoForgeManifest The manifest from which to acquire version information.
* @param utilities Commonly used utilities across ServerPackCreator.
*
* @author Griefed
*/
@Suppress("unused")
expect class NeoForgeMeta(
neoForgeManifest: File,
utilities: Utilities,
installerCacheDirectory: File
) {
/**
* Check whether the given Minecraft and Forge versions are valid/supported/available.
*
* @param minecraftVersion Minecraft version.
* @param neoForgeVersion Forge version.
* @return `true` if the given Minecraft and Forge versions are valid/supported/available.
* @author Griefed
*/
fun isNeoForgeAndMinecraftCombinationValid(
minecraftVersion: String,
neoForgeVersion: String
): Boolean

/**
* Check whether a given Minecraft version is valid/supported/available.
*
* @param minecraftVersion Minecraft version.
* @return `true` if the given Minecraft version is valid/supported/available.
* @author Griefed
*/
fun isMinecraftVersionSupported(minecraftVersion: String): Boolean

/**
* Check whether a given Forge version is valid/supported/available.
*
* @param neoForgeVersion Forge version.
* @return `true` if the given Forge version is valid/supported/available.
* @author Griefed
*/
fun isNeoForgeVersionValid(neoForgeVersion: String): Boolean

/**
* Check whether Forge is available for a given Forge- and Minecraft version.
*
* @param minecraftVersion Minecraft version.
* @param neoForgeVersion Forge version.
* @return `true` if Forge is available for the given Forge- and Minecraft version.
* @author Griefed
*/
fun isNeoForgeInstanceAvailable(minecraftVersion: String, neoForgeVersion: String): Boolean

/**
* Check whether Forge is available for a given Forge version
*
* @param neoForgeVersion Forge version.
* @return `true` if Forge is available for the given Forge version.
* @author Griefed
*/
fun isNeoForgeInstanceAvailable(neoForgeVersion: String): Boolean

/**
* Latest Forge version for a given Minecraft version, wrapped in [Optional]
*
* @param minecraftVersion Minecraft version.
* @return Latest Forge version for the given Minecraft version, wrapped in an [Optional]
* @author Griefed
*/
fun newestNeoForgeVersion(minecraftVersion: String): Optional<String>

/**
* Oldest Forge version for a given Minecraft version, wrapped in [Optional]
*
* @param minecraftVersion Minecraft version.
* @return Oldest Forge version for the given Minecraft version, wrapped in [Optional]
* @author Griefed
*/
fun oldestNeoForgeVersion(minecraftVersion: String): Optional<String>

/**
* Get the list of available Forge versions, in ascending order.
*
* @return List of available Forge versions.
* @author Griefed
*/
fun neoForgeVersionsAscending(): MutableList<String>

/**
* Get the list of available Forge versions, in descending order.
*
* @return List of available Forge versions.
* @author Griefed
*/
fun neoForgeVersionsDescending(): List<String>

/**
* Get the array of available Forge versions, in ascending order.
*
* @return Array of available Forge versions.
* @author Griefed
*/
fun neoForgeVersionsAscendingArray(): Array<String>

/**
* Get the array of available Forge versions, in descending order.
*
* @return Array of available Forge versions.
* @author Griefed
*/
fun neoForgeVersionsDescendingArray(): Array<String>

/**
* Get a list of available Forge version for a given Minecraft version in ascending order.
*
* @param minecraftVersion Minecraft version.
* @return List of available Forge versions for the given Minecraft version in ascending order.
* @author Griefed
*/
fun supportedNeoForgeVersionsAscending(minecraftVersion: String): Optional<List<String>>

/**
* Get a list of available Forge version for a given Minecraft version in descending order.
*
* @param minecraftVersion Minecraft version.
* @return List of available Forge versions for the given Minecraft version in descending order.
* @author Griefed
*/
fun supportedNeoForgeVersionsDescending(minecraftVersion: String): Optional<List<String>>

/**
* Get an array of available Forge version for a given Minecraft version, in ascending order,
* wrapped in an [Optional].
*
* @param minecraftVersion Minecraft version.
* @return Array of available Forge versions for the given Minecraft version, in ascending order,
* wrapped in an [Optional]
* @author Griefed
*/
fun supportedNeoForgeVersionsAscendingArray(minecraftVersion: String): Optional<Array<String>>

/**
* Get an array of available Forge version for a given Minecraft version, in descending order,
* wrapped in an [Optional].
*
* @param minecraftVersion Minecraft version.
* @return Array of available Forge versions for the given Minecraft version, in descending order,
* wrapped in an [Optional]
* @author Griefed
*/
fun supportedNeoForgeVersionsDescendingArray(minecraftVersion: String): Optional<Array<String>>

/**
* Get the Minecraft version for a given Forge version, wrapped in an [Optional].
*
* @param neoForgeVersion Forge version.
* @return Minecraft version for the given Forge version, wrapped in an [Optional].
* @author Griefed
*/
fun minecraftVersion(neoForgeVersion: String): Optional<String>

/**
* Get the list of Forge supported Minecraft versions, in ascending order.
*
* @return List of Forge supported Minecraft versions, in ascending order.
* @author Griefed
*/
fun supportedMinecraftVersionsAscending(): MutableList<String>

/**
* Get the list of Forge supported Minecraft versions, in descending order.
*
* @return List of Forge supported Minecraft versions, in descending order.
* @author Griefed
*/
fun supportedMinecraftVersionsDescending(): List<String>

/**
* Get the array of Forge supported Minecraft versions, in ascending order.
*
* @return Array of Forge supported Minecraft versions, in ascending order.
* @author Griefed
*/
fun supportedMinecraftVersionsAscendingArray(): Array<String>

/**
* Get the array of Forge supported Minecraft versions, in descending order.
*
* @return Array of Forge supported Minecraft versions, in descending order.
* @author Griefed
*/
fun supportedMinecraftVersionsDescendingArray(): Array<String>

/**
* Get the Forge server installer URL for a given Forge version, wrapped in an [Optional].
*
* @param neoForgeVersion Forge version.
* @return Forge server installer URL for the given Forge version, wrapped in an [Optional].
* @author Griefed
*/
fun installerUrl(neoForgeVersion: String): Optional<URL>

/**
* Installer file for the specified [neoForgeVersion] and [minecraftVersion] version, wrapped in an [Optional], so you
* can check whether it is available first.
* @author Griefed
*/
fun installerFor(neoForgeVersion: String, minecraftVersion: String): Optional<File>


}
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ actual class ApiProperties(
/**
* Modloaders supported by ServerPackCreator.
*/
val supportedModloaders = arrayOf("Fabric", "Forge", "Quilt", "LegacyFabric")
val supportedModloaders = arrayOf("Fabric", "Forge", "Quilt", "LegacyFabric", "NeoForge")

/**
* The folder containing the ServerPackCreator.exe or JAR-file.
Expand Down Expand Up @@ -1230,6 +1230,15 @@ actual class ApiProperties(
*/
val forgeVersionManifest: File = File(manifestsDirectory, "forge-manifest.json").absoluteFile

/**
* NeoForge version manifest containing information about available NeoForge loader versions.
*
*
* By default, the `neoforge-manifest.xml`-file resides in the `manifests`-directory
* inside ServerPackCreators home-directory.
*/
val neoForgeVersionManifest: File = File(manifestsDirectory, "neoforge-manifest.xml").absoluteFile

/**
* Fabric version manifest containing information about available Fabric loader versions.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ actual class ApiWrapper private constructor(
field = VersionMeta(
apiProperties.minecraftVersionManifest,
apiProperties.forgeVersionManifest,
apiProperties.neoForgeVersionManifest,
apiProperties.fabricVersionManifest,
apiProperties.fabricInstallerManifest,
apiProperties.fabricIntermediariesManifest,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,17 @@ actual class ConfigurationHandler(
false
}

"NeoForge" -> if (versionMeta.neoForge.isNeoForgeAndMinecraftCombinationValid(minecraftVersion, modloaderVersion)) {
true
} else {
encounteredErrors.add(
Api.configuration_log_error_checkmodloaderandversion(
minecraftVersion, modloader, modloaderVersion
)
)
false
}

"Fabric" -> if (versionMeta.fabric.isVersionValid(modloaderVersion) && versionMeta.fabric.getLoaderDetails(
minecraftVersion,
modloaderVersion
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ actual open class PackConfig actual constructor() : Pack<File, JsonNode, PackCon
conf.set<Any>("minecraftVersion", minecraftVersion)
conf.setComment(
"modLoader",
"\n Which modloader to install. Must be either \"Forge\", \"Fabric\", \"Quilt\" or \"LegacyFabric\".\n Automatically set when projectID,fileID for modpackDir has been specified.\n Only needed if includeServerInstallation is true."
"\n Which modloader to install. Must be either \"Forge\", \"NeoForge\", \"Fabric\", \"Quilt\" or \"LegacyFabric\".\n Automatically set when projectID,fileID for modpackDir has been specified.\n Only needed if includeServerInstallation is true."
)
conf.set<Any>("modLoader", modloader)
val plugins: Config = TomlFormat.newConfig()
Expand Down
Loading

0 comments on commit 7ad2f66

Please sign in to comment.