Skip to content

Commit

Permalink
Merge pull request #12 from Astra-Interactive/forge-support
Browse files Browse the repository at this point in the history
Forge support
  • Loading branch information
makeevrserg authored Mar 28, 2024
2 parents 7e4f64f + 337b2cc commit 7666d9f
Show file tree
Hide file tree
Showing 18 changed files with 310 additions and 47 deletions.
19 changes: 13 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# AstraTemplate v7.0.0

### MultiPlatform (Plugin-first) Spigot/Velocity plugin
### MultiPlatform (Plugin-first) Spigot/Velocity/Fabric/Forge plugin

This is a Minecraft Multiplatform template that provides architecture and various tools you'll need to create new
Spigot/Velocity plugins as fast as possible
Expand Down Expand Up @@ -45,8 +45,8 @@ It contains powerful and scalable architecture template which will help you in y
│ ├── api-local # Local api with SQLite
│ ├── api-remote # Remote sample RickMorty API
│ └── core # Core multiplatform module
├── forge # Forge template mod[wip]
├── fabric # Fabric template mod[wip]
├── forge # Forge template mod
├── fabric # Fabric template mod
├── velocity # Velocity template plugin
└── plugin # Bukkit template mod

Expand Down Expand Up @@ -83,9 +83,9 @@ Sometimes you need to share models between other modules, so this module contain

Usually all instances(forge/bukkit) have the same logic, which can be located here without depending on platform

## 4. Velocity [wip]
## 4. Velocity/Fabric/Forge

I've not been working with velocity too much, but this module contains basic velocity functionality with plugin
I've not been working with velocity too much, but this modules contains basic functionality with plugin
information generation.

## 5. Quick overview
Expand Down Expand Up @@ -176,11 +176,17 @@ classDiagram
| `/rickmorty` | `-` | `Rick morty character println` |
| `/helloworld` | `-` | `Hello world println` |

## 7.2 Forge mod usage

| Command | Permission | Description |
|:--------------|:-----------|:----------------------|
| `/helloworld` | `-` | `Hello world println` |

### Platforms

- [x] Spigot/Paper
- [x] Fabric - Pre Alpha state
- [ ] Forge - Pre-Alpha state
- [x] Forge - Pre-Alpha state
- [x] Velocity

### Build jar executables
Expand All @@ -190,6 +196,7 @@ Firstly, change gradle/libs.versions.toml destination-xxx to your folder
$ ./gradlew :plugin:shadowJar # assemble the plugin .jar
$ ./gradlew :velocity:shadowJar # assemble the plugin .jar
$ ./gradlew :fabric:build # assemble the fabric .jar
$ ./gradlew :forge:shadowJar # assemble the forge .jar

### Forge and fabirc is on pause

Expand Down
1 change: 0 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ plugins {
alias(libs.plugins.kotlin.jvm) apply false
alias(libs.plugins.kotlin.serialization) apply false
alias(libs.plugins.minecraft.fabric.loom) apply false
alias(libs.plugins.minecraft.forge.net) apply false
alias(libs.plugins.gradle.buildconfig) apply false
alias(libs.plugins.gradle.shadow) apply false

Expand Down
2 changes: 1 addition & 1 deletion fabric/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ dependencies {
implementation(libs.bundles.kotlin)
// Driver
implementation(libs.driver.jdbc)
// Local
implementation(projects.modules.apiLocal)
implementation(projects.modules.apiRemote)
implementation(projects.modules.core)
Expand All @@ -47,7 +48,6 @@ val shadowJar by tasks.getting(ShadowJar::class) {
include(dependency("ru.astrainteractive.klibs:mikro-core-jvm"))
include(dependency(libs.driver.jdbc.get()))
}
println("Configurations: ${project.configurations.names}")
exclude("mappings/")
dependsOn(configurations)
from(sourceSets.main.get().allSource)
Expand Down
121 changes: 115 additions & 6 deletions forge/build.gradle.kts
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)
}
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())
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,21 @@ import net.minecraftforge.fml.common.Mod
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext
import org.apache.logging.log4j.LogManager
import ru.astrainteractive.astratemplate.di.RootModule
import javax.annotation.ParametersAreNonnullByDefault

@Mod("astratemplate")
@Mod(BuildKonfig.id)
@ParametersAreNonnullByDefault
class ForgeEntryPoint {
companion object {
val rootModule by lazy { RootModule.Default() }
}

private val logger = LogManager.getLogger()

private fun setup(event: FMLCommonSetupEvent) {
logger.info("ForgeEntryPoint.setup")
rootModule.coreModule.logger.value.info("ForgeEntryPoint", "setup")
CommandLoader.commonSetup(event)
}

init {
Expand Down
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!")
}
)
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>)
}
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)
}
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
}
)
}
}
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)
}
}
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)
}
)
}
}
}
14 changes: 6 additions & 8 deletions forge/src/main/resources/META-INF/mods.toml
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}"
Loading

0 comments on commit 7666d9f

Please sign in to comment.