Refactor source layout

Introduce compat source sets and move all kotlin sources to the main directory

[no changelog]
This commit is contained in:
Linnea Gräf
2024-08-28 19:04:24 +02:00
parent a690630816
commit d2f240ff0c
251 changed files with 295 additions and 38 deletions

View File

@@ -8,21 +8,24 @@
import moe.nea.licenseextractificator.LicenseDiscoveryTask import moe.nea.licenseextractificator.LicenseDiscoveryTask
import net.fabricmc.loom.LoomGradleExtension import net.fabricmc.loom.LoomGradleExtension
import org.jetbrains.kotlin.gradle.dsl.JvmTarget
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins { plugins {
java java
`maven-publish` `maven-publish`
id("com.google.devtools.ksp") version "1.9.23-1.0.20" alias(libs.plugins.kotlin.jvm)
kotlin("jvm") version "1.9.23" alias(libs.plugins.kotlin.plugin.serialization)
kotlin("plugin.serialization") version "1.9.23" alias(libs.plugins.kotlin.plugin.powerassert)
// id("com.bnorm.power.kotlin-power-assert") version "0.13.0" alias(libs.plugins.kotlin.plugin.ksp)
id("dev.architectury.loom") version "1.6.397" alias(libs.plugins.loom)
id("com.github.johnrengelman.shadow") version "8.1.1" id("com.github.johnrengelman.shadow") version "8.1.1"
id("moe.nea.licenseextractificator") id("moe.nea.licenseextractificator")
// id("io.github.juuxel.loom-vineflower") version "1.11.0"
} }
version = getGitTagInfo()
group = rootProject.property("maven_group").toString()
java { java {
withSourcesJar() withSourcesJar()
toolchain { toolchain {
@@ -30,13 +33,11 @@ java {
} }
} }
val compileKotlin: KotlinCompile by tasks
compileKotlin.kotlinOptions { tasks.withType(KotlinCompile::class) {
jvmTarget = "21" compilerOptions {
} jvmTarget.set(JvmTarget.JVM_21)
val compileTestKotlin: KotlinCompile by tasks }
compileTestKotlin.kotlinOptions {
jvmTarget = "21"
} }
allprojects { allprojects {
@@ -80,17 +81,54 @@ allprojects {
maven("https://repo.hypixel.net/repository/Hypixel/") maven("https://repo.hypixel.net/repository/Hypixel/")
maven("https://maven.azureaaron.net/snapshots") maven("https://maven.azureaaron.net/snapshots")
maven("https://maven.azureaaron.net/releases") maven("https://maven.azureaaron.net/releases")
maven("https://www.cursemaven.com")
mavenLocal() mavenLocal()
} }
} }
kotlin { kotlin {
sourceSets.all { sourceSets.all {
languageSettings { languageSettings {
// languageVersion = "2.0"
enableLanguageFeature("BreakContinueInInlineLambdas") enableLanguageFeature("BreakContinueInInlineLambdas")
} }
} }
} }
val compatSourceSets: MutableSet<SourceSet> = mutableSetOf()
fun createIsolatedSourceSet(name: String, path: String = "compat/$name"): SourceSet {
val ss = sourceSets.create(name) {
this.java.setSrcDirs(listOf(layout.projectDirectory.dir("src/$path/java")))
this.kotlin.setSrcDirs(listOf(layout.projectDirectory.dir("src/$path/kotlin")))
}
compatSourceSets.add(ss)
loom.createRemapConfigurations(ss)
val mainSS = sourceSets.main.get()
configurations {
(ss.implementationConfigurationName) {
extendsFrom(getByName(mainSS.compileClasspathConfigurationName))
}
(ss.annotationProcessorConfigurationName) {
extendsFrom(getByName(mainSS.annotationProcessorConfigurationName))
}
(mainSS.runtimeOnlyConfigurationName) {
extendsFrom(getByName(ss.runtimeClasspathConfigurationName))
}
}
dependencies {
runtimeOnly(ss.output)
(ss.implementationConfigurationName)(sourceSets.main.get().output)
}
tasks.jar {
from(ss.output)
}
return ss
}
val SourceSet.modImplementationConfigurationName
get() =
loom.remapConfigurations.find {
it.targetConfigurationName.get() == this.implementationConfigurationName
}!!.sourceConfiguration
val configuredSourceSet = createIsolatedSourceSet("configured")
val sodiumSourceSet = createIsolatedSourceSet("sodium")
val shadowMe by configurations.creating { val shadowMe by configurations.creating {
exclude(group = "org.jetbrains.kotlin") exclude(group = "org.jetbrains.kotlin")
@@ -148,10 +186,11 @@ dependencies {
modRuntimeOnly(libs.fabric.api.deprecated) modRuntimeOnly(libs.fabric.api.deprecated)
modApi(libs.architectury) modApi(libs.architectury)
modCompileOnly(libs.jarvis.api) modCompileOnly(libs.jarvis.api)
modCompileOnly(libs.sodium)
include(libs.jarvis.fabric) include(libs.jarvis.fabric)
modCompileOnly(libs.femalegender) modCompileOnly(libs.femalegender)
(configuredSourceSet.modImplementationConfigurationName)(libs.configured)
(sodiumSourceSet.modImplementationConfigurationName)(libs.sodium)
// Actual dependencies // Actual dependencies
modCompileOnly(libs.rei.api) { modCompileOnly(libs.rei.api) {
@@ -189,9 +228,6 @@ tasks.test {
useJUnitPlatform() useJUnitPlatform()
} }
version = getGitTagInfo()
group = rootProject.property("maven_group").toString()
loom { loom {
clientOnlyMinecraftJar() clientOnlyMinecraftJar()
accessWidenerPath.set(project.file("src/main/resources/firmament.accesswidener")) accessWidenerPath.set(project.file("src/main/resources/firmament.accesswidener"))
@@ -201,6 +237,10 @@ loom {
property("devauth.enabled", "true") property("devauth.enabled", "true")
property("fabric.log.level", "info") property("fabric.log.level", "info")
property("firmament.debug", "true") property("firmament.debug", "true")
property("firmament.classroots",
compatSourceSets.joinToString(File.pathSeparator) {
File(it.output.classesDirs.asPath).absolutePath
})
property("mixin.debug", "true") property("mixin.debug", "true")
parseEnvFile(file(".env")).forEach { (t, u) -> parseEnvFile(file(".env")).forEach { (t, u) ->

View File

@@ -4,7 +4,14 @@
[versions] [versions]
minecraft = "1.21" minecraft = "1.21"
fabric_loader = "0.15.11"
# Update from https://kotlinlang.org/
kotlin = "2.0.20"
# Update from https://github.com/google/ksp/releases
kotlin_ksp = "2.0.20-1.0.24"
# Update from https://linkie.shedaniel.me/dependencies?loader=fabric
fabric_loader = "0.16.3"
fabric_api = "0.100.4+1.21" fabric_api = "0.100.4+1.21"
fabric_kotlin = "1.11.0+kotlin.2.0.0" fabric_kotlin = "1.11.0+kotlin.2.0.0"
yarn = "1.21+build.7" yarn = "1.21+build.7"
@@ -12,25 +19,58 @@ rei = "16.0.729"
modmenu = "11.0.1" modmenu = "11.0.1"
architectury = "13.0.3" architectury = "13.0.3"
qolify = "1.3.0-1.20.2" # Update from https://maven.architectury.dev/dev/architectury/loom/dev.architectury.loom.gradle.plugin/
citresewn = "1.1.3+1.20" loom = "1.7.412"
# Update from https://modrinth.com/mod/qolify/versions?l=fabric
qolify = "1.6.0-1.21.1"
# Update from https://modrinth.com/mod/sodium/versions?l=fabric
sodium = "mc1.21-0.5.11" sodium = "mc1.21-0.5.11"
freecammod = "U5eR0FyR"
# Update from https://modrinth.com/mod/freecam/versions?l=fabric
freecammod = "vomskVK3"
# Update from https://modrinth.com/mod/no-chat-reports/versions?l=fabric
ncr = "Fabric-1.21-v2.8.0" ncr = "Fabric-1.21-v2.8.0"
# Update from https://modrinth.com/mod/female-gender/versions?l=fabric
femalegender = "kJmjQvAS" femalegender = "kJmjQvAS"
# Update from https://modrinth.com/mod/explosive-enhancement/versions?l=fabric
explosiveenhancement = "1.2.3-1.21.0" explosiveenhancement = "1.2.3-1.21.0"
notenoughanimations = "WaI2x21x"
# Update from https://modrinth.com/mod/not-enough-animations/versions?l=fabric
notenoughanimations = "BQ8qstAV"
devauth = "1.2.0" devauth = "1.2.0"
ktor = "2.3.0"
# Update from https://ktor.io/
ktor = "2.3.12"
# Update from https://repo.nea.moe/#/releases/moe/nea/neurepoparser
neurepoparser = "1.5.0" neurepoparser = "1.5.0"
# Update from https://github.com/HotswapProjects/HotswapAgent/releases
hotswap_agent = "1.4.2-SNAPSHOT" hotswap_agent = "1.4.2-SNAPSHOT"
# Update from https://github.com/LlamaLad7/MixinExtras/tags
mixinextras = "0.3.5" mixinextras = "0.3.5"
jarvis = "1.1.3" jarvis = "1.1.3"
nealisp = "1.0.0" nealisp = "1.0.0"
# Update from https://github.com/NotEnoughUpdates/MoulConfig/tags
moulconfig = "3.0.0-beta.15" moulconfig = "3.0.0-beta.15"
# Update from https://www.curseforge.com/minecraft/mc-mods/configured/files/all?page=1&pageSize=20
configured = "5441234"
# Update from https://modrinth.com/mod/hypixel-mod-api/versions
hypixelmodapi = "1.0.1" hypixelmodapi = "1.0.1"
hypixelmodapi_fabric = "1.0.1+build.1+mc1.21" hypixelmodapi_fabric = "1.0.1+build.1+mc1.21"
# Update from https://github.com/shedaniel/fabric-asm or https://maven.shedaniel.me/me/shedaniel/mm/
manninghamMills = "2.4.1" manninghamMills = "2.4.1"
[libraries] [libraries]
@@ -52,6 +92,7 @@ manninghamMills = { module = "me.shedaniel:mm", version.ref = "manninghamMills"
aaronhmapi = { module = "net.azureaaron:hm-api", version = "1.0.0+1.21" } aaronhmapi = { module = "net.azureaaron:hm-api", version = "1.0.0+1.21" }
hypixelmodapi = { module = "net.hypixel:mod-api", version.ref = "hypixelmodapi" } hypixelmodapi = { module = "net.hypixel:mod-api", version.ref = "hypixelmodapi" }
hypixelmodapi_fabric = { module = "maven.modrinth:hypixel-mod-api", version.ref = "hypixelmodapi_fabric" } hypixelmodapi_fabric = { module = "maven.modrinth:hypixel-mod-api", version.ref = "hypixelmodapi_fabric" }
configured = { module = "curse.maven:configured-457570", version.ref = "configured" }
# Runtime: # Runtime:
notenoughanimations = { module = "maven.modrinth:not-enough-animations", version.ref = "notenoughanimations" } notenoughanimations = { module = "maven.modrinth:not-enough-animations", version.ref = "notenoughanimations" }
hotswap = { module = "virtual.github.hotswapagent:hotswap-agent", version.ref = "hotswap_agent" } hotswap = { module = "virtual.github.hotswapagent:hotswap-agent", version.ref = "hotswap_agent" }
@@ -60,7 +101,6 @@ rei_fabric = { module = "me.shedaniel:RoughlyEnoughItems-fabric", version.ref =
devauth = { module = "me.djtheredstoner:DevAuth-fabric", version.ref = "devauth" } devauth = { module = "me.djtheredstoner:DevAuth-fabric", version.ref = "devauth" }
modmenu = { module = "maven.modrinth:modmenu", version.ref = "modmenu" } modmenu = { module = "maven.modrinth:modmenu", version.ref = "modmenu" }
qolify = { module = "maven.modrinth:qolify", version.ref = "qolify" } qolify = { module = "maven.modrinth:qolify", version.ref = "qolify" }
citresewn = { module = "maven.modrinth:cit-resewn", version.ref = "citresewn" }
ncr = { module = "maven.modrinth:no-chat-reports", version.ref = "ncr" } ncr = { module = "maven.modrinth:no-chat-reports", version.ref = "ncr" }
sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" } sodium = { module = "maven.modrinth:sodium", version.ref = "sodium" }
freecammod = { module = "maven.modrinth:freecam", version.ref = "freecammod" } freecammod = { module = "maven.modrinth:freecam", version.ref = "freecammod" }
@@ -78,9 +118,13 @@ runtime_optional = [
"devauth", "devauth",
"freecammod", "freecammod",
"sodium", "sodium",
# "qolify", # "qolify",
# "citresewn", "ncr",
# "ncr",
] ]
[plugins]
kotlin_jvm = { id = "org.jetbrains.kotlin.jvm", version.ref = "kotlin" }
kotlin_plugin_serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin_plugin_powerassert = { id = "org.jetbrains.kotlin.plugin.power-assert", version.ref = "kotlin" }
kotlin_plugin_ksp = { id = "com.google.devtools.ksp", version.ref = "kotlin_ksp" }
loom = { id = "dev.architectury.loom", version.ref = "loom" }

View File

@@ -1,12 +1,10 @@
package moe.nea.firmament.compat
import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer import me.jellysquid.mods.sodium.client.render.SodiumWorldRenderer
import moe.nea.firmament.mixins.accessor.sodium.AccessorSodiumWorldRenderer import moe.nea.firmament.mixins.accessor.sodium.AccessorSodiumWorldRenderer
class SodiumChunkReloader : Runnable { class SodiumChunkReloader : Runnable {
override fun run() { override fun run() {
(SodiumWorldRenderer.instanceNullable() as AccessorSodiumWorldRenderer) (SodiumWorldRenderer.instanceNullable() as? AccessorSodiumWorldRenderer)
.renderSectionManager_firmament ?.renderSectionManager_firmament
.updateChunks(false) ?.markGraphDirty()
} }
} }

View File

@@ -9,6 +9,6 @@ import org.spongepowered.asm.mixin.gen.Accessor;
@Mixin(SodiumWorldRenderer.class) @Mixin(SodiumWorldRenderer.class)
@Pseudo @Pseudo
public interface AccessorSodiumWorldRenderer { public interface AccessorSodiumWorldRenderer {
@Accessor("renderSectionManager") @Accessor(value = "renderSectionManager", remap = false)
RenderSectionManager getRenderSectionManager_firmament(); RenderSectionManager getRenderSectionManager_firmament();
} }

View File

@@ -0,0 +1,173 @@
package moe.nea.firmament.init;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
public class AutoDiscoveryPlugin {
private static final List<AutoDiscoveryPlugin> mixinPlugins = new ArrayList<>();
public static List<AutoDiscoveryPlugin> getMixinPlugins() {
return mixinPlugins;
}
private String mixinPackage;
public void setMixinPackage(String mixinPackage) {
this.mixinPackage = mixinPackage;
mixinPlugins.add(this);
}
/**
* Resolves the base class root for a given class URL. This resolves either the JAR root, or the class file root.
* In either case the return value of this + the class name will resolve back to the original class url, or to other
* class urls for other classes.
*/
public URL getBaseUrlForClassUrl(URL classUrl) {
String string = classUrl.toString();
if (classUrl.getProtocol().equals("jar")) {
try {
return new URL(string.substring(4).split("!")[0]);
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
if (string.endsWith(".class")) {
try {
return new URL(string.replace("\\", "/")
.replace(getClass().getCanonicalName()
.replace(".", "/") + ".class", ""));
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
return classUrl;
}
/**
* Get the package that contains all the mixins. This value is set using {@link #setMixinPackage}.
*/
public String getMixinPackage() {
return mixinPackage;
}
/**
* Get the path inside the class root to the mixin package
*/
public String getMixinBaseDir() {
return mixinPackage.replace(".", "/");
}
/**
* A list of all discovered mixins.
*/
private List<String> mixins = null;
/**
* Try to add mixin class ot the mixins based on the filepath inside of the class root.
* Removes the {@code .class} file suffix, as well as the base mixin package.
* <p><b>This method cannot be called after mixin initialization.</p>
*
* @param className the name or path of a class to be registered as a mixin.
*/
public void tryAddMixinClass(String className) {
if (!className.endsWith(".class")) return;
String norm = (className.substring(0, className.length() - ".class".length()))
.replace("\\", "/")
.replace("/", ".");
if (norm.startsWith(getMixinPackage() + ".") && !norm.endsWith(".")) {
mixins.add(norm.substring(getMixinPackage().length() + 1));
}
}
private void tryDiscoverFromContentFile(URL url) {
Path file;
try {
file = Paths.get(getBaseUrlForClassUrl(url).toURI());
} catch (URISyntaxException e) {
throw new RuntimeException(e);
}
System.out.println("Base directory found at " + file);
if (!Files.exists(file)) {
System.out.println("Skipping non-existing mixin root: " + file);
return;
}
if (Files.isDirectory(file)) {
walkDir(file);
} else {
walkJar(file);
}
System.out.println("Found mixins: " + mixins);
}
/**
* Search through the JAR or class directory to find mixins contained in {@link #getMixinPackage()}
*/
public List<String> getMixins() {
if (mixins != null) return mixins;
System.out.println("Trying to discover mixins");
mixins = new ArrayList<>();
URL classUrl = getClass().getProtectionDomain().getCodeSource().getLocation();
System.out.println("Found classes at " + classUrl);
tryDiscoverFromContentFile(classUrl);
var classRoots = System.getProperty("firmament.classroots");
if (classRoots != null && !classRoots.isBlank()) {
System.out.println("Found firmament class roots: " + classRoots);
for (String s : classRoots.split(File.pathSeparator)) {
if (s.isBlank()) {
continue;
}
try {
tryDiscoverFromContentFile(new File(s).toURI().toURL());
} catch (MalformedURLException e) {
throw new RuntimeException(e);
}
}
}
return mixins;
}
/**
* Search through directory for mixin classes based on {@link #getMixinBaseDir}.
*
* @param classRoot The root directory in which classes are stored for the default package.
*/
private void walkDir(Path classRoot) {
System.out.println("Trying to find mixins from directory");
try (Stream<Path> classes = Files.walk(classRoot.resolve(getMixinBaseDir()))) {
classes.map(it -> classRoot.relativize(it).toString())
.forEach(this::tryAddMixinClass);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
/**
* Read through a JAR file, trying to find all mixins inside.
*/
private void walkJar(Path file) {
System.out.println("Trying to find mixins from jar file");
try (ZipInputStream zis = new ZipInputStream(Files.newInputStream(file))) {
ZipEntry next;
while ((next = zis.getNextEntry()) != null) {
tryAddMixinClass(next.getName());
zis.closeEntry();
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@@ -12,9 +12,12 @@ import java.util.Set;
public class MixinPlugin implements IMixinConfigPlugin { public class MixinPlugin implements IMixinConfigPlugin {
AutoDiscoveryPlugin autoDiscoveryPlugin = new AutoDiscoveryPlugin();
@Override @Override
public void onLoad(String mixinPackage) { public void onLoad(String mixinPackage) {
MixinExtrasBootstrap.init(); MixinExtrasBootstrap.init();
autoDiscoveryPlugin.setMixinPackage(mixinPackage);
} }
@Override @Override
@@ -37,7 +40,7 @@ public class MixinPlugin implements IMixinConfigPlugin {
@Override @Override
public List<String> getMixins() { public List<String> getMixins() {
return null; return autoDiscoveryPlugin.getMixins();
} }
@Override @Override

Some files were not shown because too many files have changed in this diff Show More