-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from Astra-Interactive/forge-support
Forge support
- Loading branch information
Showing
18 changed files
with
310 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,122 @@ | ||
@file:Suppress("UnusedPrivateMember") | ||
|
||
import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar | ||
import ru.astrainteractive.gradleplugin.models.Developer | ||
import ru.astrainteractive.gradleplugin.util.ProjectProperties.projectInfo | ||
|
||
plugins { | ||
id("net.minecraftforge.gradle") | ||
id("forge-resource-processor") | ||
id("basic-java") | ||
id("forge-shadow") | ||
kotlin("jvm") | ||
alias(klibs.plugins.klibs.gradle.java.core) | ||
id("net.minecraftforge.gradle") version ("[6.0,6.2)") | ||
id("com.github.johnrengelman.shadow") | ||
} | ||
|
||
minecraft { | ||
mappings("official", "1.19") | ||
mappings("official", "1.20.1") | ||
runs { | ||
val runProperties = mapOf( | ||
// Recommended logging data for a userdev environment. | ||
Pair("forge.logging.markers", "SCAN,REGISTRIES,REGISTRYDUMP"), | ||
// Recommended logging level for the console. | ||
Pair("forge.logging.console.level", "debug") | ||
) | ||
val server by creating { | ||
properties(runProperties) | ||
workingDirectory(File("./build${File.separator}run")) | ||
mods { | ||
create(projectInfo.name) { | ||
source(sourceSets.getByName("main")) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
dependencies { | ||
minecraft("net.minecraftforge:forge:${libs.versions.minecrft.forge.version.get()}") | ||
minecraft("net.minecraftforge:forge:1.20.1-47.1.46") | ||
// AstraLibs | ||
implementation(libs.minecraft.astralibs.core) | ||
implementation(libs.minecraft.astralibs.command) | ||
implementation(klibs.klibs.kdi) | ||
// Kotlin | ||
implementation(libs.bundles.kotlin) | ||
// Local | ||
implementation(projects.modules.apiLocal) | ||
implementation(projects.modules.apiRemote) | ||
implementation(projects.modules.core) | ||
implementation(projects.modules.buildKonfig) | ||
} | ||
|
||
configurations { | ||
apiElements { | ||
artifacts.clear() | ||
} | ||
runtimeElements { | ||
setExtendsFrom(emptySet()) | ||
// Publish the jarJar | ||
artifacts.clear() | ||
outgoing.artifact(tasks.jarJar) | ||
} | ||
} | ||
|
||
val processResources = project.tasks.withType<org.gradle.language.jvm.tasks.ProcessResources>() { | ||
filteringCharset = "UTF-8" | ||
duplicatesStrategy = DuplicatesStrategy.INCLUDE | ||
|
||
from(sourceSets.main.get().resources.srcDirs) { | ||
include("META-INF/mods.toml") | ||
include("mods.toml") | ||
expand( | ||
"modId" to projectInfo.name.lowercase(), | ||
"version" to projectInfo.versionString, | ||
"description" to projectInfo.description, | ||
"displayName" to projectInfo.name, | ||
"authors" to projectInfo.developersList.map(Developer::id).joinToString(",") | ||
) | ||
} | ||
} | ||
|
||
val destination = File("C:\\Users\\Roman\\Desktop\\EsmpModded\\server\\mods") | ||
.takeIf(File::exists) | ||
?: File(rootDir, "jars") | ||
|
||
val reobfShadowJar = reobf.create("shadowJar") | ||
|
||
val shadowJar by tasks.getting(ShadowJar::class) { | ||
mustRunAfter(processResources) | ||
dependsOn(processResources) | ||
dependencies { | ||
// Kotlin | ||
include(dependency("ru.astrainteractive.klibs:kdi-jvm")) | ||
include(dependency(libs.minecraft.astralibs.core.asProvider().get())) | ||
include(dependency(libs.minecraft.astralibs.command.asProvider().get())) | ||
include(dependency(projects.modules.core)) | ||
include(dependency(projects.modules.apiRemote)) | ||
include(dependency(projects.modules.apiLocal)) | ||
// TODO somehow fix the multiplatform libraries | ||
include(dependency("ru.astrainteractive.klibs:kdi-jvm")) | ||
include(dependency("ru.astrainteractive.klibs:kdi-jvm")) | ||
include(dependency("org.jetbrains.kotlin:kotlin-stdlib")) | ||
include(dependency("org.jetbrains.kotlinx:kotlinx-coroutines-core-jvm")) | ||
include(dependency(libs.driver.jdbc.get())) | ||
} | ||
relocate("kotlin", "${projectInfo.group}.kotlin") | ||
relocate("kotlinx", "${projectInfo.group}.kotlinx") | ||
relocate("org.jetbrains", "${projectInfo.group}.org.jetbrains") | ||
mergeServiceFiles() | ||
manifest { | ||
attributes( | ||
"Specification-Title" to project.name, | ||
"Specification-Vendor" to projectInfo.developersList.first().id, | ||
"Specification-Version" to project.version, | ||
"Implementation-Title" to project.name, | ||
"Implementation-Version" to project.version, | ||
"Implementation-Vendor" to projectInfo.developersList.first().id | ||
) | ||
} | ||
isReproducibleFileOrder = true | ||
archiveClassifier.set(null as String?) | ||
archiveBaseName.set("${projectInfo.name}-forge-shadow") | ||
destinationDirectory.set(destination) | ||
finalizedBy(reobfShadowJar) | ||
} |
23 changes: 23 additions & 0 deletions
23
forge/src/main/java/ru/astrainteractive/astratemplate/CommandLoader.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ru.astrainteractive.astratemplate | ||
|
||
import net.minecraftforge.event.RegisterCommandsEvent | ||
import net.minecraftforge.eventbus.api.SubscribeEvent | ||
import net.minecraftforge.fml.common.Mod | ||
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent | ||
import ru.astrainteractive.astratemplate.command.HelloWorldCommand | ||
import ru.astrainteractive.astratemplate.command.core.DefaultCommandRegistry | ||
|
||
@Mod.EventBusSubscriber(modid = BuildKonfig.id) | ||
object CommandLoader { | ||
|
||
@Suppress("UnusedPrivateMember") | ||
fun commonSetup(event: FMLCommonSetupEvent) = Unit | ||
|
||
@SubscribeEvent | ||
@JvmStatic | ||
fun registerCommands(event: RegisterCommandsEvent) { | ||
ForgeEntryPoint.rootModule.coreModule.logger.value.info("ForgeEntryPoint", "registerCommands") | ||
val registry = DefaultCommandRegistry(event.dispatcher) | ||
registry.register(HelloWorldCommand()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
forge/src/main/java/ru/astrainteractive/astratemplate/command/HelloWorldCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package ru.astrainteractive.astratemplate.command | ||
|
||
import ru.astrainteractive.astratemplate.command.core.Command | ||
import ru.astrainteractive.astratemplate.command.core.DslCommand | ||
|
||
class HelloWorldCommand : Command by DslCommand( | ||
alias = "helloworld", | ||
block = { | ||
println("Hello from HelloWorldCommand!") | ||
} | ||
) |
9 changes: 9 additions & 0 deletions
9
forge/src/main/java/ru/astrainteractive/astratemplate/command/core/Command.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package ru.astrainteractive.astratemplate.command.core | ||
|
||
import com.mojang.brigadier.context.CommandContext | ||
import net.minecraft.commands.CommandSourceStack | ||
|
||
interface Command { | ||
val alias: String | ||
fun onCommand(commandContext: CommandContext<CommandSourceStack>) | ||
} |
5 changes: 5 additions & 0 deletions
5
forge/src/main/java/ru/astrainteractive/astratemplate/command/core/CommandRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package ru.astrainteractive.astratemplate.command.core | ||
|
||
interface CommandRegistry { | ||
fun register(command: Command) | ||
} |
19 changes: 19 additions & 0 deletions
19
forge/src/main/java/ru/astrainteractive/astratemplate/command/core/DefaultCommandRegistry.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package ru.astrainteractive.astratemplate.command.core | ||
|
||
import com.mojang.brigadier.CommandDispatcher | ||
import net.minecraft.commands.CommandSourceStack | ||
import net.minecraft.commands.Commands | ||
|
||
class DefaultCommandRegistry( | ||
private val dispatcher: CommandDispatcher<CommandSourceStack> | ||
) : CommandRegistry { | ||
|
||
override fun register(command: Command) { | ||
dispatcher.register( | ||
Commands.literal(command.alias).executes { commandContext -> | ||
command.onCommand(commandContext) | ||
com.mojang.brigadier.Command.SINGLE_SUCCESS | ||
} | ||
) | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
forge/src/main/java/ru/astrainteractive/astratemplate/command/core/DslCommand.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package ru.astrainteractive.astratemplate.command.core | ||
|
||
import com.mojang.brigadier.context.CommandContext | ||
import net.minecraft.commands.CommandSourceStack | ||
|
||
class DslCommand( | ||
override val alias: String, | ||
private val block: (commandContext: CommandContext<CommandSourceStack>) -> Unit | ||
) : Command { | ||
override fun onCommand(commandContext: CommandContext<CommandSourceStack>) { | ||
block.invoke(commandContext) | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
forge/src/main/java/ru/astrainteractive/astratemplate/di/RootModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package ru.astrainteractive.astratemplate.di | ||
|
||
import ru.astrainteractive.astralibs.lifecycle.Lifecycle | ||
import ru.astrainteractive.astratemplate.api.local.di.ApiLocalModule | ||
import ru.astrainteractive.astratemplate.api.remote.di.ApiRemoteModule | ||
import ru.astrainteractive.astratemplate.core.di.CoreModule | ||
import java.io.File | ||
|
||
interface RootModule { | ||
val lifecycle: Lifecycle | ||
|
||
val coreModule: CoreModule | ||
|
||
val apiLocalModule: ApiLocalModule | ||
|
||
val apiRemoteModule: ApiRemoteModule | ||
|
||
class Default : RootModule { | ||
|
||
override val coreModule: CoreModule by lazy { | ||
CoreModule.Default( | ||
dataFolder = File("./") | ||
) | ||
} | ||
|
||
override val apiLocalModule: ApiLocalModule by lazy { | ||
ApiLocalModule.Default( | ||
databasePath = File("data.db").path | ||
) | ||
} | ||
|
||
override val apiRemoteModule: ApiRemoteModule by lazy { | ||
ApiRemoteModule.Default() | ||
} | ||
|
||
private val lifecycles: List<Lifecycle> | ||
get() = listOf() | ||
|
||
override val lifecycle: Lifecycle by lazy { | ||
Lifecycle.Lambda( | ||
onEnable = { | ||
lifecycles.forEach(Lifecycle::onEnable) | ||
}, | ||
onDisable = { | ||
lifecycles.forEach(Lifecycle::onDisable) | ||
}, | ||
onReload = { | ||
lifecycles.forEach(Lifecycle::onReload) | ||
} | ||
) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,10 @@ | ||
license="MIT" | ||
modLoader="javafml" | ||
loaderVersion="[31,)" | ||
loaderVersion="[34,)" | ||
[[mods]] | ||
modId="astratemplate" | ||
version="0.0.1" | ||
displayName="AstraTemplate" | ||
authors="makeevrserg" | ||
modId="${modId}" | ||
version="${version}" | ||
displayName="${displayName}" | ||
authors="${authors}" | ||
logoFile="icon.png" | ||
description=''' | ||
Astra Template Forge module | ||
''' | ||
description="${description}" |
Oops, something went wrong.