Skip to content

Commit

Permalink
build: gradle多模块
Browse files Browse the repository at this point in the history
用于适配多个minecraft版本
  • Loading branch information
Itsusinn committed Jan 10, 2022
1 parent 81c208b commit be08219
Show file tree
Hide file tree
Showing 20 changed files with 208 additions and 145 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
packages/
extract/
run/

Expand Down
54 changes: 54 additions & 0 deletions 1_16_5/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import io.itsusinn.pkg.pkgIn

plugins {
java
id("fabric-loom")
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.serialization")
id("com.github.johnrengelman.shadow")
id("io.itsusinn.pkg")
}
pkg {
excludePath("mappings/*")
excludePath("META-INF/*.kotlin_module")
excludePath("*.md")
excludePath("DebugProbesKt.bin")
shadowJar {
tasks.remapJar {
val task = this@shadowJar
dependsOn(task)
mustRunAfter(task)
input.set(task.outputs.files.singleFile)
// 这里需要借助fabric-loom进行remap
}
minimize()
}
relocateKotlinxLib()
relocateKotlinStdlib()
}
tasks {
processResources {
inputs.property("version", project.version)
filesMatching("fabric.mod.json") {
expand(mutableMapOf("version" to project.version))
}
}
}

dependencies {
modImplementation("net.fabricmc:fabric-loader:0.12.2")
modImplementation("net.fabricmc.fabric-api:fabric-api:0.29.3+1.16")

minecraft("com.mojang:minecraft:1.16.5")
mappings("net.fabricmc:yarn:1.16.5+build.1:v2")

pkgIn(
project(":common").apply {
isTransitive = false
}
)
pkgIn("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt")
pkgIn("io.nats:jnats:${property("nats_version")}")
pkgIn("org.meowcat:mesagisto-client-jvm:${property("mesagisto_client_version")}")
pkgIn("com.charleskorn.kaml:kaml:0.38.0")
}
17 changes: 17 additions & 0 deletions 1_16_5/src/main/java/org/meowcat/mesagisto/farbic/impl/ChatImpl.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package org.meowcat.mesagisto.farbic.impl

import net.minecraft.network.MessageType
import net.minecraft.server.MinecraftServer
import net.minecraft.text.Text
import org.meowcat.mesagisto.farbic.api.IChat
import java.util.* // ktlint-disable no-wildcard-imports

class ChatImpl : IChat {
override fun setServer(server: MinecraftServer) {
TODO("Not yet implemented")
}

override fun broadcastMessage(message: Text, type: MessageType, senderUuid: UUID) {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.meowcat.mesagisto.farbic.mixin;

import net.minecraft.network.packet.c2s.play.ChatMessageC2SPacket;
import net.minecraft.server.network.ServerPlayNetworkHandler;
import net.minecraft.server.network.ServerPlayerEntity;
import org.jetbrains.annotations.NotNull;
import org.meowcat.mesagisto.farbic.Mod;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(ServerPlayNetworkHandler.class)
public class ServerChatMixin {
@Shadow
public ServerPlayerEntity player;

@Inject(at = @At("TAIL"), method = "onGameMessage(Lnet/minecraft/network/packet/c2s/play/ChatMessageC2SPacket;)V")
public void onChat(ChatMessageC2SPacket packet, CallbackInfo ci) {
ServerPlayerEntity player = this.player;
String message = packet.getChatMessage();
Mod.INSTANCE.onServerChat(player, message);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
org.meowcat.mesagisto.farbic.impl.ChatImpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"schemaVersion": 1,
"id": "mesagisto",
"version": "0.1.0",
"version": "${version}",

"name": "Mesagisto Mod",
"description": "Mesagisto: A message forwarding program connecting different instant-message platforms. 信使: 一款连接不同即时通讯平台的消息转发程序。 ",
Expand All @@ -14,17 +15,18 @@
"mixins": [
"mesagisto.mixins.json"
],
"environment": "*",
"license": "LGPLv2",
"entrypoints": {
"main": [
{
"adapter": "kotlin",
"value": "org.meowcat.mesagisto.farbic.Mod"
"value": "org.meowcat.mesagisto.farbic.ModAdapter"
}
]
},
"depends": {
"fabric-language-kotlin": ">=1.7.0+kotlin.1.6.0"
},
"schemaVersion": 1
"fabricloader": ">=0.11.3",
"fabric": "*",
"minecraft": "1.16.5"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@
],
"injectors": {
"defaultRequire": 1
}
},
"refmap": "1_16_5-refmap.json"
}
109 changes: 24 additions & 85 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,94 +1,33 @@
plugins {
id("fabric-loom") version "0.8-SNAPSHOT"
java
id("fabric-loom") version "0.10-SNAPSHOT"
id("org.jetbrains.kotlin.jvm") version ("1.6.0")
id("org.jetbrains.kotlin.plugin.serialization")version ("1.6.0")
id("com.github.johnrengelman.shadow")version ("7.1.0")
id("org.meowcat.kato") version "0.1.0-dev31"
id("io.itsusinn.pkg") version "1.2.0"
}

group = property("maven_group")!!
version = property("mod_version")!!

repositories {
mavenCentral()
maven("https://jitpack.io")
mavenLocal()
}
kato {
excludePath("kotlin/*")
excludePath("kotlinx/coroutines/*")
excludePath("kotlinx/serialization/*")
excludePath("mappings/*")
excludePath("META-INF/*.kotlin_module")
excludePath("*.md")
excludePath("DebugProbesKt.bin")
excludeGroups(
"org.lwjgl",
"net.fabricmc",
"org.ow2.asm",
"net.minecraft",
"com.mojang",
"net.java.dev.jna",
"com.google.jimfs",
"org.jetbrains.kotlinx",
"org.jetbrains.kotlin",
"org.apache.logging.log4j",
"net.java.jinput",
"net.java.jutils",
"org.apache.commons",
"org.apache.httpcomponents",
"commons-logging",
"com.ibm.icu",
"it.unimi.dsi",
"ca.weblite",
"net.minecrell",
"com.google.guava",
"commons-io",
"commons-codec",
"com.google.code.gson",
"oshi-project",
"io.netty",
"net.sf.jopt-simple",
"net_fabricmc_yarn_1_16_5_1_16_5_build_1_v2.net.fabricmc.fabric-api",
"net_fabricmc_yarn_1_16_5_1_16_5_build_1_v2.net.fabricmc",
)
shadowJar {
minimize()
}
}
java {
toolchain {
languageVersion.set(JavaLanguageVersion.of(16))
allprojects {
group = property("maven_group")!!
version = property("mod_version")!!
repositories {
mavenCentral()
maven("https://jitpack.io")
mavenLocal()
maven("https://maven.fabricmc.net/")
}
// java {
// sourceCompatibility = JavaVersion.VERSION_1_8
// targetCompatibility = JavaVersion.VERSION_1_8
// }
// tasks.compileKotlin {
// kotlinOptions {
// jvmTarget = "1.8"
// freeCompilerArgs = listOf("-Xinline-classes", "-Xopt-in=kotlin.RequiresOptIn")
// }
// sourceCompatibility = "1.8"
// }
}
dependencies {
minecraft("com.mojang:minecraft:${property("minecraft_version")}")
mappings("net.fabricmc:yarn:${property("yarn_mappings")}:v2")

modCompileClasspath("net.fabricmc:fabric-loader:${property("loader_version")}")

modImplementation("net.fabricmc:fabric-language-kotlin:${property("fabric_kotlin_version")}")
modImplementation("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_version")}")

compileOnly("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.0")
implementation("io.nats:jnats:2.13.1")
implementation("org.meowcat:mesagisto-client-jvm:1.1.0")
// implementation("org.meowcat:mesagisto-client:1.0.14-build")
implementation("io.arrow-kt:arrow-core:1.0.0")
implementation("com.charleskorn.kaml:kaml:0.37.0")
}
tasks {
processResources {
inputs.property("version", project.version)
filesMatching("fabric.mod.json") {
expand(mutableMapOf("version" to project.version))
}
}
compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xinline-classes", "-Xopt-in=kotlin.RequiresOptIn")
}
sourceCompatibility = "1.8"
}
minecraft("com.mojang:minecraft:1.16.5")
mappings("net.fabricmc:yarn:1.16.5+build.1:v2")
}
27 changes: 27 additions & 0 deletions common/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
plugins {
java
id("fabric-loom")
id("org.jetbrains.kotlin.jvm")
id("org.jetbrains.kotlin.plugin.serialization")
}
tasks.compileKotlin {
kotlinOptions {
jvmTarget = "1.8"
freeCompilerArgs = listOf("-Xinline-classes", "-Xopt-in=kotlin.RequiresOptIn")
}
sourceCompatibility = "1.8"
}

dependencies {
modCompileOnly("net.fabricmc:fabric-loader:${property("loader_version")}")
modCompileOnly("net.fabricmc.fabric-api:fabric-api:${property("fabric_api_version")}")

minecraft("com.mojang:minecraft:1.16.5")
mappings("net.fabricmc:yarn:1.16.5+build.1:v2")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0-native-mt")
implementation("io.nats:jnats:${property("nats_version")}")
implementation("org.meowcat:mesagisto-client-jvm:${property("mesagisto_client_version")}")
// implementation("org.meowcat:mesagisto-client:1.0.14-build")
implementation("com.charleskorn.kaml:kaml:0.38.0")
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,7 @@ package org.meowcat.mesagisto.farbic

import kotlinx.serialization.* // ktlint-disable no-wildcard-imports
import java.nio.file.Path
import kotlin.io.path.exists
import kotlin.io.path.readText
import kotlin.io.path.writeText
import kotlin.io.path.* // ktlint-disable no-wildcard-imports

val Yaml = com.charleskorn.kaml.Yaml.default
class ConfigKeeper<C : Any> (
Expand All @@ -20,7 +18,6 @@ class ConfigKeeper<C : Any> (
path.writeText(str)
}
companion object {

inline fun <reified T : Any> create(
path: Path,
defaultValue: () -> T
Expand All @@ -38,6 +35,8 @@ class ConfigKeeper<C : Any> (
} else {
val default = defaultValue()
val str = Yaml.encodeToString(T::class.serializer(), default)
path.parent.createDirectories()
path.createFile()
path.writeText(str)
default
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import net.minecraft.text.Text
import org.apache.logging.log4j.LogManager
import org.meowcat.mesagisto.client.Logger
import org.meowcat.mesagisto.client.MesagistoConfig
import org.meowcat.mesagisto.farbic.api.IChat
import org.meowcat.mesagisto.farbic.handlers.send
import java.util.* // ktlint-disable no-wildcard-imports
import kotlin.coroutines.EmptyCoroutineContext
Expand All @@ -23,7 +24,9 @@ object Mod : ModInitializer, CoroutineScope {
override val coroutineContext = EmptyCoroutineContext

private val configKeeper =
ConfigKeeper.create(Path("config/mesagisto.yml")) { Config() }
ConfigKeeper.create(Path("mods/mesagisto/config.yml")) { Config() }

private val chat = ServiceLoader.load(IChat::class.java).first()

val CONFIG = configKeeper.value

Expand All @@ -42,7 +45,7 @@ object Mod : ModInitializer, CoroutineScope {
configKeeper.save()
}
MesagistoConfig.builder {
name = "farbic"
name = "fabric"
natsAddress = CONFIG.nats
cipherEnable = CONFIG.cipher.enable
cipherKey = CONFIG.cipher.key
Expand All @@ -69,4 +72,6 @@ fun Mod.broadcastMessage(
message: String,
type: MessageType = MessageType.CHAT,
senderUuid: UUID = UUID.randomUUID()
) = broadcastMessage(LiteralText(message), type, senderUuid)
) {
broadcastMessage(LiteralText(message), type, senderUuid)
}
10 changes: 10 additions & 0 deletions common/src/main/java/org/meowcat/mesagisto/farbic/ModAdapter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.meowcat.mesagisto.farbic;

import net.fabricmc.api.ModInitializer;

public class ModAdapter implements ModInitializer {
@Override
public void onInitialize() {
Mod.INSTANCE.onInitialize();
}
}
15 changes: 15 additions & 0 deletions common/src/main/java/org/meowcat/mesagisto/farbic/api/IChat.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.meowcat.mesagisto.farbic.api

import net.minecraft.network.MessageType
import net.minecraft.server.MinecraftServer
import net.minecraft.text.Text
import java.util.* // ktlint-disable no-wildcard-imports

interface IChat {
fun setServer(server: MinecraftServer)
fun broadcastMessage(
message: Text,
type: MessageType = MessageType.CHAT,
senderUuid: UUID = UUID.randomUUID()
)
}
Loading

0 comments on commit be08219

Please sign in to comment.