forked from CubeSugarCheese/architectury-template-kotlin-dsl
-
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.
- Loading branch information
1 parent
4bc5096
commit 0e19f94
Showing
33 changed files
with
1,137 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import net.fabricmc.loom.api.LoomGradleExtensionAPI | ||
|
||
plugins { | ||
java | ||
`kotlin-dsl` | ||
id("architectury-plugin") version "3.4-SNAPSHOT" | ||
id("dev.architectury.loom") version "0.11.0-SNAPSHOT" apply false | ||
} | ||
|
||
architectury { | ||
minecraft = project.property("minecraft_version").toString() | ||
} | ||
|
||
subprojects { | ||
apply(plugin = "dev.architectury.loom") | ||
|
||
val loom = project.extensions.getByName<LoomGradleExtensionAPI>("loom") | ||
|
||
|
||
dependencies { | ||
"minecraft"("com.mojang:minecraft:${project.property("minecraft_version")}") | ||
// The following line declares the mojmap mappings, you may use other mappings as well | ||
"mappings"( | ||
loom.layered { | ||
officialMojangMappings() | ||
} | ||
) | ||
// The following line declares the yarn mappings you may select this one as well. | ||
// "mappings"("net.fabricmc:yarn:1.18.2+build.3:v2") | ||
} | ||
} | ||
|
||
allprojects { | ||
apply(plugin = "java") | ||
apply(plugin = "architectury-plugin") | ||
apply(plugin = "maven-publish") | ||
|
||
version = project.property("mod_version").toString() | ||
group = project.property("maven_group").toString() | ||
|
||
repositories { | ||
// Add repositories to retrieve artifacts from in here. | ||
// You should only use this when depending on other mods because | ||
// Loom adds the essential maven repositories to download Minecraft and libraries from automatically. | ||
// See https://docs.gradle.org/current/userguide/declaring_repositories.html | ||
// for more information about repositories. | ||
} | ||
|
||
tasks.withType<JavaCompile> { | ||
options.encoding = "UTF-8" | ||
options.release.set(17) | ||
} | ||
|
||
java { | ||
withSourcesJar() | ||
} | ||
} |
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,34 @@ | ||
plugins { | ||
`maven-publish` | ||
} | ||
|
||
architectury { | ||
val enabled_platforms: String by rootProject | ||
common(enabled_platforms.split(",")) | ||
} | ||
|
||
loom { | ||
accessWidenerPath.set(file("src/main/resources/examplemod.accesswidener")) | ||
} | ||
|
||
dependencies { | ||
// We depend on fabric loader here to use the fabric @Environment annotations and get the mixin dependencies | ||
// Do NOT use other classes from fabric loader | ||
modImplementation("net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}") | ||
// Remove the next line if you don't want to depend on the API | ||
modApi("dev.architectury:architectury:${rootProject.property("architectury_version")}") | ||
} | ||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("maven") { | ||
artifactId = rootProject.property("archives_base_name").toString() | ||
from(components.getByName("java")) | ||
} | ||
} | ||
|
||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. | ||
repositories { | ||
// Add repositories to publish to here. | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
common/src/main/java/net/examplemod/ExampleExpectPlatform.java
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,27 @@ | ||
package net.examplemod; | ||
|
||
import dev.architectury.injectables.annotations.ExpectPlatform; | ||
import dev.architectury.platform.Platform; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class ExampleExpectPlatform { | ||
/** | ||
* We can use {@link Platform#getConfigFolder()} but this is just an example of {@link ExpectPlatform}. | ||
* <p> | ||
* This must be a <b>public static</b> method. The platform-implemented solution must be placed under a | ||
* platform sub-package, with its class suffixed with {@code Impl}. | ||
* <p> | ||
* Example: | ||
* Expect: net.examplemod.ExampleExpectPlatform#getConfigDirectory() | ||
* Actual Fabric: net.examplemod.fabric.ExampleExpectPlatformImpl#getConfigDirectory() | ||
* Actual Forge: net.examplemod.forge.ExampleExpectPlatformImpl#getConfigDirectory() | ||
* <p> | ||
* <a href="https://plugins.jetbrains.com/plugin/16210-architectury">You should also get the IntelliJ plugin to help with @ExpectPlatform.</a> | ||
*/ | ||
@ExpectPlatform | ||
public static Path getConfigDirectory() { | ||
// Just throw an error, the content should get replaced at runtime. | ||
throw new AssertionError(); | ||
} | ||
} |
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,33 @@ | ||
package net.examplemod; | ||
|
||
import com.google.common.base.Suppliers; | ||
import dev.architectury.registry.CreativeTabRegistry; | ||
import dev.architectury.registry.registries.DeferredRegister; | ||
import dev.architectury.registry.registries.Registries; | ||
import dev.architectury.registry.registries.RegistrySupplier; | ||
import net.minecraft.core.Registry; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.CreativeModeTab; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class ExampleMod { | ||
public static final String MOD_ID = "examplemod"; | ||
// We can use this if we don't want to use DeferredRegister | ||
public static final Supplier<Registries> REGISTRIES = Suppliers.memoize(() -> Registries.get(MOD_ID)); | ||
// Registering a new creative tab | ||
public static final CreativeModeTab EXAMPLE_TAB = CreativeTabRegistry.create(new ResourceLocation(MOD_ID, "example_tab"), () -> | ||
new ItemStack(ExampleMod.EXAMPLE_ITEM.get())); | ||
|
||
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(MOD_ID, Registry.ITEM_REGISTRY); | ||
public static final RegistrySupplier<Item> EXAMPLE_ITEM = ITEMS.register("example_item", () -> | ||
new Item(new Item.Properties().tab(ExampleMod.EXAMPLE_TAB))); | ||
|
||
public static void init() { | ||
ITEMS.register(); | ||
|
||
System.out.println(ExampleExpectPlatform.getConfigDirectory().toAbsolutePath().normalize().toString()); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
common/src/main/java/net/examplemod/mixin/MixinTitleScreen.java
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,15 @@ | ||
package net.examplemod.mixin; | ||
|
||
import net.minecraft.client.gui.screens.TitleScreen; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(TitleScreen.class) | ||
public class MixinTitleScreen { | ||
@Inject(at = @At("HEAD"), method = "init()V") | ||
private void init(CallbackInfo info) { | ||
System.out.println("Hello from example architectury common mixin!"); | ||
} | ||
} |
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,3 @@ | ||
{ | ||
"accessWidener": "examplemod.accesswidener" | ||
} |
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,3 @@ | ||
{ | ||
"item.examplemod.example_item": "Example Item" | ||
} |
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 @@ | ||
{ | ||
"required": true, | ||
"package": "net.examplemod.mixin", | ||
"compatibilityLevel": "JAVA_16", | ||
"client": [ | ||
"MixinTitleScreen" | ||
], | ||
"mixins": [ | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |
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 @@ | ||
accessWidener v2 named |
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,112 @@ | ||
plugins { | ||
id("com.github.johnrengelman.shadow") version "7.1.2" | ||
} | ||
|
||
architectury { | ||
platformSetupLoomIde() | ||
fabric() | ||
} | ||
|
||
loom { | ||
accessWidenerPath.set(project(":common").loom.accessWidenerPath) | ||
} | ||
|
||
/** | ||
* @see: https://docs.gradle.org/current/userguide/migrating_from_groovy_to_kotlin_dsl.html | ||
* */ | ||
val common: Configuration by configurations.creating | ||
val shadowCommon: Configuration by configurations.creating // Don't use shadow from the shadow plugin because we don't want IDEA to index this. | ||
/** | ||
* Error: Cannot add a configuration with name 'developmentFabric' as a configuration with that name already exists. | ||
* TODO: fix bug | ||
* */ | ||
// val developmentFabric: Configuration by configurations.creating { extendsFrom(configurations["common"]) } | ||
configurations { | ||
compileClasspath.get().extendsFrom(configurations["common"]) | ||
runtimeClasspath.get().extendsFrom(configurations["common"]) | ||
} | ||
|
||
dependencies { | ||
modImplementation("net.fabricmc:fabric-loader:${rootProject.property("fabric_loader_version")}") | ||
modApi("net.fabricmc.fabric-api:fabric-api:${rootProject.property("fabric_api_version")}") | ||
// Remove the next line if you don't want to depend on the API | ||
modApi("dev.architectury:architectury-fabric:${rootProject.property("architectury_version")}") | ||
|
||
common(project(":common", configuration = "namedElements")) { isTransitive = false } | ||
shadowCommon(project(":common", configuration = "transformProductionFabric")) { isTransitive = false } | ||
} | ||
|
||
val javaComponent = components["java"] as AdhocComponentWithVariants | ||
javaComponent.withVariantsFromConfiguration(configurations["sourcesElements"]) { | ||
skip() | ||
} | ||
|
||
tasks { | ||
processResources { | ||
inputs.property("version", project.version) | ||
|
||
filesMatching("fabric.mod.json") { | ||
expand("version" to project.version) | ||
} | ||
} | ||
|
||
shadowJar { | ||
exclude("architectury.common.json") | ||
/** | ||
* magic! | ||
* groovy -> kotlin dsl | ||
* [project.configurations.shadowCommon] -> listOf(project.configurations["shadowCommon"]) | ||
* */ | ||
configurations = listOf(project.configurations["shadowCommon"]) | ||
archiveClassifier.set("dev-shadow") | ||
} | ||
|
||
remapJar { | ||
injectAccessWidener.set(true) | ||
/** | ||
* magic! | ||
* groovy -> kotlin dsl | ||
* shadowJar.archiveFile -> shadowJar.flatMap { it.archiveFile } | ||
* */ | ||
inputFile.set(shadowJar.flatMap { it.archiveFile }) | ||
dependsOn(shadowJar) | ||
/** | ||
* Uncertain change | ||
* groovy -> kotlin dsl | ||
* classifier null -> archiveClassifier.set("quilt") | ||
*/ | ||
archiveClassifier.set("quilt") | ||
} | ||
|
||
jar { | ||
archiveClassifier.set("dev") | ||
} | ||
|
||
sourcesJar { | ||
val commonSources = project(":common").getTasksByName("sourcesJar", false) | ||
dependsOn(commonSources) | ||
/** | ||
* Uncertain change | ||
* groovy -> kotlin dsl | ||
* commonSources.archiveFile.map { zipTree(it) } -> project(":common").sourceSets["main"].allSource | ||
*/ | ||
from(project(":common").sourceSets["main"].allSource) | ||
} | ||
|
||
|
||
|
||
publishing { | ||
publications { | ||
create<MavenPublication>("mavenFabric") { | ||
artifactId = "${rootProject.property("archives_base_name")}-${project.name}" | ||
from(javaComponent) | ||
} | ||
} | ||
|
||
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing. | ||
repositories { | ||
// Add repositories to publish to here. | ||
} | ||
} | ||
} | ||
|
15 changes: 15 additions & 0 deletions
15
fabric/src/main/java/net/examplemod/fabric/ExampleExpectPlatformImpl.java
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,15 @@ | ||
package net.examplemod.fabric; | ||
|
||
import net.examplemod.ExampleExpectPlatform; | ||
import net.fabricmc.loader.api.FabricLoader; | ||
|
||
import java.nio.file.Path; | ||
|
||
public class ExampleExpectPlatformImpl { | ||
/** | ||
* This is our actual method to {@link ExampleExpectPlatform#getConfigDirectory()}. | ||
*/ | ||
public static Path getConfigDirectory() { | ||
return FabricLoader.getInstance().getConfigDir(); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
fabric/src/main/java/net/examplemod/fabric/ExampleModFabric.java
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 net.examplemod.fabric; | ||
|
||
import net.examplemod.ExampleMod; | ||
import net.fabricmc.api.ModInitializer; | ||
|
||
public class ExampleModFabric implements ModInitializer { | ||
@Override | ||
public void onInitialize() { | ||
ExampleMod.init(); | ||
} | ||
} |
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,12 @@ | ||
{ | ||
"required": true, | ||
"package": "net.examplemod.mixin.fabric", | ||
"compatibilityLevel": "JAVA_16", | ||
"client": [ | ||
], | ||
"mixins": [ | ||
], | ||
"injectors": { | ||
"defaultRequire": 1 | ||
} | ||
} |
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,31 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "examplemod", | ||
"version": "${version}", | ||
"name": "Example Mod", | ||
"description": "This is an example description! Tell everyone what your mod is about!", | ||
"authors": [ | ||
"Me!" | ||
], | ||
"contact": { | ||
"homepage": "https://fabricmc.net/", | ||
"sources": "https://github.com/FabricMC/fabric-example-mod" | ||
}, | ||
"license": "Insert License Here", | ||
"icon": "assets/examplemod/icon.png", | ||
"environment": "*", | ||
"entrypoints": { | ||
"main": [ | ||
"net.examplemod.fabric.ExampleModFabric" | ||
] | ||
}, | ||
"mixins": [ | ||
"examplemod.mixins.json", | ||
"examplemod-common.mixins.json" | ||
], | ||
"depends": { | ||
"fabric": "*", | ||
"minecraft": ">=1.18.2", | ||
"architectury": ">=4.2.50" | ||
} | ||
} |
Oops, something went wrong.