Skip to content

Commit

Permalink
add minecraft module
Browse files Browse the repository at this point in the history
  • Loading branch information
DeDiamondPro committed Feb 10, 2024
1 parent 5773d35 commit 8fceb85
Show file tree
Hide file tree
Showing 39 changed files with 1,649 additions and 6 deletions.
15 changes: 15 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,21 @@ dependencies {
compileOnly(libs.jetbrains.annotations)
}

tasks {
build {
dependsOn(gradle.includedBuild("minecraft").task(":buildAll"))
}
clean {
dependsOn(gradle.includedBuild("minecraft").task(":cleanAll"))
}
publish {
dependsOn(gradle.includedBuild("minecraft").task(":publishAll"))
}
publishToMavenLocal {
dependsOn(gradle.includedBuild("minecraft").task(":publishToMavenLocalAll"))
}
}

allprojects {
apply(plugin = "java-library")
apply(plugin = "maven-publish")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import dev.dediamondpro.minemark.MineMarkCoreBuilder
import dev.dediamondpro.minemark.elementa.elements.*
import dev.dediamondpro.minemark.elementa.style.MarkdownStyle
import dev.dediamondpro.minemark.elements.Elements
import dev.dediamondpro.minemark.elements.MineMarkElement
import dev.dediamondpro.minemark.utils.MouseButton
import gg.essential.elementa.UIComponent
import gg.essential.elementa.dsl.constrain
Expand All @@ -39,8 +40,7 @@ class MineMarkComponent(
style: MarkdownStyle = MarkdownStyle(),
core: MineMarkCore<MarkdownStyle, UMatrixStack> = defaultCore
) : UIComponent() {

private val parsedMarkdown = core.parse(style, markdown).apply {
val parsedMarkdown: MineMarkElement<MarkdownStyle, UMatrixStack> = core.parse(style, markdown).apply {
addLayoutCallback(this@MineMarkComponent::layoutCallback)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ data class MarkdownStyle @JvmOverloads constructor(
override fun getTableStyle(): TableStyleConfig = tableStyle

companion object {
private val LINE_COLOR = Color(80, 80, 80);
private val LINE_COLOR = Color(80, 80, 80)
}
}

Expand Down
8 changes: 8 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
version_test = 1.0.1

# Gradle Configuration
org.gradle.daemon=true
org.gradle.parallel=true
org.gradle.configureoncommand=true6
org.gradle.workers.max=6
org.gradle.jvmargs=-Xmx5G
3 changes: 1 addition & 2 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
#Sun Aug 20 09:30:36 CEST 2023
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
48 changes: 48 additions & 0 deletions minecraft/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
.gradle
build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**/build/
!**/src/test/**/build/

### IntelliJ IDEA ###
.idea/modules.xml
.idea/jarRepositories.xml
.idea/compiler.xml
.idea/libraries/
*.iws
*.iml
*.ipr
out/
!**/src/main/**/out/
!**/src/test/**/out/

### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
bin/
!**/src/main/**/bin/
!**/src/test/**/bin/

### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/

### VS Code ###
.vscode/

### Mac OS ###
.DS_Store

# Other
.idea/
run/
.gradle/
/jars/
265 changes: 265 additions & 0 deletions minecraft/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,265 @@
/*
* This file is part of MineMark
* Copyright (C) 2024 DeDiamondPro
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License Version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import org.jetbrains.kotlin.com.intellij.lang.java.JavaLanguage

/*
* This file is part of MineMark
* Copyright (C) 2024 DeDiamondPro
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License Version 3 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

plugins {
java
alias(libs.plugins.architecturyPlugin)
alias(libs.plugins.blossom)
alias(libs.plugins.shadow)
id(libs.plugins.loom.get().pluginId)
id(libs.plugins.preprocessor.get().pluginId)
`maven-publish`
}

val modPlatform = Platform.of(project)
buildscript {
// Set loom to the correct platform
project.extra.set("loom.platform", project.name.substringAfter("-"))
}

architectury {
platformSetupLoomIde()
when (modPlatform.loader) {
Platform.Loader.Fabric -> fabric()
Platform.Loader.Forge -> forge()
Platform.Loader.NeoForge -> neoForge()
}
}

val loadExampleMod = project.findProperty("loadExampleMod")?.toString()?.toBoolean() ?: false

val mod_name: String by project
val mod_version: String by project
val mod_id: String by project
val mod_description: String by project
val mod_license: String by project

version = mod_version
group = "dev.dediamondpro"

blossom {
replaceToken("@NAME@", mod_name)
replaceToken("@ID@", mod_id)
replaceToken("@VERSION@", mod_version)
}

preprocess {
vars.put("MC", modPlatform.mcVersion)
vars.put("FABRIC", if (modPlatform.isFabric) 1 else 0)
vars.put("FORGE", if (modPlatform.isForge) 1 else 0)
vars.put("NEOFORGE", if (modPlatform.isNeoForge) 1 else 0)
vars.put("FORGELIKE", if (modPlatform.isForgeLike) 1 else 0)
}

repositories {
maven("https://maven.neoforged.net/releases")
}

dependencies {
minecraft("com.mojang:minecraft:${modPlatform.mcVersionStr}")
val yarnVersion = when (modPlatform.mcVersion) {
12004 -> "1.20.4+build.3"
11904 -> "1.19.4+build.2"
else -> error("No mappings defined for ${modPlatform.mcVersion}")
}
mappings("net.fabricmc:yarn:${yarnVersion}:v2")

if (modPlatform.isFabric) {
modImplementation("net.fabricmc:fabric-loader:0.15.6")
val fabricApiVersion = when (modPlatform.mcVersion) {
12004 -> "0.92.1+1.20.4"
11904 -> "0.87.2+1.19.4"
else -> error("No fabric API version defined for ${modPlatform.mcVersion}")
}
// Only required for example mod
modImplementation("net.fabricmc.fabric-api:fabric-api:$fabricApiVersion")
} else if (modPlatform.isForge) {
val forgeVersion = when (modPlatform.mcVersion) {
12004 -> "49.0.26"
11904 -> "45.2.0"
else -> error("No forge version defined for ${modPlatform.mcVersion}")
}
"forge"("net.minecraftforge:forge:${modPlatform.mcVersionStr}-$forgeVersion")
} else if (modPlatform.isNeoForge) {
val neoforgeVersion = when (modPlatform.mcVersion) {
12004 -> "20.4.148-beta"
else -> error("No neoforge version defined for ${modPlatform.mcVersion}")
}
"neoForge"("net.neoforged:neoforge:$neoforgeVersion")
}

api("dev.dediamondpro:MineMark")
implementation(libs.commonmark.ext.striketrough)
implementation(libs.commonmark.ext.tables)
}

val shade: Configuration by configurations.creating {
configurations.implementation.get().extendsFrom(this)
}

base.archivesName = "$mod_name (${modPlatform.mcVersionStr}-${modPlatform.loaderStr})"

java {
toolchain {
languageVersion = JavaLanguageVersion.of(
if (modPlatform.mcVersion >= 11800) 17 else if (modPlatform.mcVersion >= 11700) 16 else 8
)
}
withSourcesJar()
withJavadocJar()
}

tasks {
listOf("sourcesJar", "javadocJar").forEach {
named<Jar>(it) {
exclude("com/example/examplemod/**", "META-INF/mods.toml", "fabric.mod.json")
}
}
processResources {
outputs.upToDateWhen { false }
val properties = mapOf(
"id" to mod_id,
"name" to mod_name,
"version" to mod_version,
"description" to mod_description,
"license" to mod_license,
)
inputs.properties(properties)
filesMatching(listOf("fabric.mod.json", "META-INF/mods.toml")) {
expand(properties)
if (!loadExampleMod) filter {
it.replace("\"com.example.examplemod.ExampleMod\"", "")
}
}
if (modPlatform.isFabric || !loadExampleMod) {
exclude("META-INF/mods.toml", "pack.mcmeta")
}
if (modPlatform.isForgeLike) {
exclude("fabric.mod.json")
}
}
shadowJar {
archiveClassifier.set("dev")
configurations = listOf(shade)

if (modPlatform.isForgeLike) {
manifest.attributes(mapOf("FMLModType" to "LIBRARY"))
}
if (!loadExampleMod) {
exclude("com/example/examplemod/**")
}
}
remapJar {
input.set(shadowJar.get().archiveFile)
archiveClassifier.set("")
}
withType<JavaCompile> {
options.encoding = "UTF-8"
}
withType<Javadoc> {
options.encoding = "UTF-8"
}
}

publishing {
publications {
register<MavenPublication>("minemark-minecraft-$modPlatform") {
version = mod_version
groupId = "dev.dediamondpro"
artifactId = "minemark-minecraft-$modPlatform"

from(components["java"])
}
}
repositories {
maven {
name = "diamond"

url = uri("https://maven.dediamondpro.dev/releases")

credentials {
username = System.getenv("MAVEN_DIAMOND_USER")
password = System.getenv("MAVEN_DIAMOND_PASSWORD")
}

version = rootProject.version
}
}
}

if (modPlatform.isForge) {
sourceSets.forEach {
val dir = layout.buildDirectory.dir("sourcesSets/$it.name")
it.output.setResourcesDir(dir)
it.java.destinationDirectory = dir
}
}

data class Platform(
val mcMajor: Int,
val mcMinor: Int,
val mcPatch: Int,
val loader: Loader
) {
val mcVersion = mcMajor * 10000 + mcMinor * 100 + mcPatch
val mcVersionStr = listOf(mcMajor, mcMinor, mcPatch).dropLastWhile { it == 0 }.joinToString(".")
val loaderStr = loader.toString().lowercase()

val isFabric = loader == Loader.Fabric
val isForge = loader == Loader.Forge
val isNeoForge = loader == Loader.NeoForge
val isForgeLike = loader == Loader.Forge || loader == Loader.NeoForge
val isLegacy = mcVersion <= 11202

override fun toString(): String {
return "$mcVersionStr-$loaderStr"
}

enum class Loader {
Fabric,
Forge,
NeoForge
}

companion object {
fun of(project: Project): Platform {
val (versionStr, loaderStr) = project.name.split("-", limit = 2)
val (major, minor, patch) = versionStr.split('.').map { it.toInt() } + listOf(0)
val loader = Loader.values().first { it.name.lowercase() == loaderStr.lowercase() }
return Platform(major, minor, patch, loader)
}
}
}
6 changes: 6 additions & 0 deletions minecraft/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Mod Configuration
mod_name=MineMark
mod_id=minemark
mod_version=1.0.1
mod_description=Markdown rendering library
mod_license=LGPL
Loading

0 comments on commit 8fceb85

Please sign in to comment.