From 80ef02479b4119a5a4b5e99bf05bd948170bd5b3 Mon Sep 17 00:00:00 2001 From: nea Date: Thu, 6 Oct 2022 20:40:09 +0200 Subject: Add kotlin to template --- README.md | 5 ++++- build.gradle.kts | 9 ++++++++ src/main/java/com/example/ExampleMod.java | 16 -------------- .../java/com/example/mixin/MixinGuiMainMenu.java | 16 -------------- src/main/kotlin/com/example/ExampleMod.kt | 25 ++++++++++++++++++++++ .../kotlin/com/example/mixin/MixinGuiMainMenu.java | 16 ++++++++++++++ src/main/resources/assets/test/test.txt | 3 +++ 7 files changed, 57 insertions(+), 33 deletions(-) delete mode 100644 src/main/java/com/example/ExampleMod.java delete mode 100644 src/main/java/com/example/mixin/MixinGuiMainMenu.java create mode 100644 src/main/kotlin/com/example/ExampleMod.kt create mode 100644 src/main/kotlin/com/example/mixin/MixinGuiMainMenu.java create mode 100644 src/main/resources/assets/test/test.txt diff --git a/README.md b/README.md index 8566930..ce76fde 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Architectury Loom based template for 1.8.9 forge mods + Architectury Loom based template for 1.8.9 kotlin forge mods **For other templates, do check out the [other branches of this repository](https://github.com/romangraef/Forge1.8.9Template/branches/all)** @@ -13,6 +13,9 @@ To get started, [Use this template](https://github.com/new?template_name=Forge1. > [!WARNING] > Do not Fork or Clone or Download ZIP this template. If you "use" this template a custom mod id will be generated. You can do that manually using the `make-my-own` script, if you are on linux. If not, just click the use this template button. If you want to use kotlin or make a 1.12 mod check the "Include all branches" and change the default branch in https://github.com/yourname/yourreponame/branches +Please note that Mixins should be kept in their own package, and should exclusively be written in Java, since older versions +of Mixin don't play well with Kotlin. + This project uses [DevAuth](https://github.com/DJtheRedstoner/DevAuth) per default, so you can log in using your real minecraft account. If you don't need that, you can remove it from the buildscript. diff --git a/build.gradle.kts b/build.gradle.kts index 686fe0f..963e8df 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -6,6 +6,7 @@ plugins { id("gg.essential.loom") version "0.10.0.+" id("dev.architectury.architectury-pack200") version "0.1.3" id("com.github.johnrengelman.shadow") version "8.1.1" + kotlin("jvm") version "2.0.0" } //Constants: @@ -56,8 +57,14 @@ loom { } } +tasks.compileJava { + dependsOn(tasks.processResources) +} + sourceSets.main { output.setResourcesDir(sourceSets.main.flatMap { it.java.classesDirectory }) + java.srcDir(layout.projectDirectory.dir("src/main/kotlin")) + kotlin.destinationDirectory.set(java.destinationDirectory) } // Dependencies: @@ -78,6 +85,8 @@ dependencies { mappings("de.oceanlabs.mcp:mcp_stable:22-1.8.9") forge("net.minecraftforge:forge:1.8.9-11.15.1.2318-1.8.9") + shadowImpl(kotlin("stdlib-jdk8")) + // If you don't want mixins, remove these lines shadowImpl("org.spongepowered:mixin:0.7.11-SNAPSHOT") { isTransitive = false diff --git a/src/main/java/com/example/ExampleMod.java b/src/main/java/com/example/ExampleMod.java deleted file mode 100644 index 2ce1671..0000000 --- a/src/main/java/com/example/ExampleMod.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.example; - -import net.minecraft.client.renderer.GlStateManager; -import net.minecraft.init.Blocks; -import net.minecraftforge.fml.common.Mod; -import net.minecraftforge.fml.common.event.FMLInitializationEvent; - -@Mod(modid = "examplemod", useMetadata=true) -public class ExampleMod { - @Mod.EventHandler - public void init(FMLInitializationEvent event) { - System.out.println("Dirt: " + Blocks.dirt.getUnlocalizedName()); - // Below is a demonstration of an access-transformed class access. - System.out.println("Color State: " + new GlStateManager.Color()); - } -} diff --git a/src/main/java/com/example/mixin/MixinGuiMainMenu.java b/src/main/java/com/example/mixin/MixinGuiMainMenu.java deleted file mode 100644 index 47eee87..0000000 --- a/src/main/java/com/example/mixin/MixinGuiMainMenu.java +++ /dev/null @@ -1,16 +0,0 @@ -package com.example.mixin; - -import net.minecraft.client.gui.GuiMainMenu; -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(GuiMainMenu.class) -public class MixinGuiMainMenu { - - @Inject(method = "initGui", at = @At("HEAD")) - public void onInitGui(CallbackInfo ci) { - System.out.println("Hello from Main Menu!"); - } -} diff --git a/src/main/kotlin/com/example/ExampleMod.kt b/src/main/kotlin/com/example/ExampleMod.kt new file mode 100644 index 0000000..ad0feff --- /dev/null +++ b/src/main/kotlin/com/example/ExampleMod.kt @@ -0,0 +1,25 @@ +package com.example + +import net.minecraft.client.Minecraft +import net.minecraft.init.Blocks +import net.minecraftforge.fml.common.Mod +import net.minecraftforge.fml.common.event.FMLInitializationEvent +import net.minecraft.client.renderer.GlStateManager + +@Mod(modid = "examplemod", useMetadata = true) +class ExampleMod { + @Mod.EventHandler + fun init(event: FMLInitializationEvent) { + try { + val resource: net.minecraft.client.resources.IResource = Minecraft.getMinecraft().getResourceManager() + .getResource(net.minecraft.util.ResourceLocation("test:test.txt")) + org.apache.commons.io.IOUtils.copy(resource.getInputStream(), java.lang.System.out) + } catch (e: java.io.IOException) { + throw java.lang.RuntimeException(e) + } + + println("Dirt: ${Blocks.dirt.unlocalizedName}") + // Below is a demonstration of an access-transformed class access. + println("Color State: " + GlStateManager.Color()); + } +} diff --git a/src/main/kotlin/com/example/mixin/MixinGuiMainMenu.java b/src/main/kotlin/com/example/mixin/MixinGuiMainMenu.java new file mode 100644 index 0000000..47eee87 --- /dev/null +++ b/src/main/kotlin/com/example/mixin/MixinGuiMainMenu.java @@ -0,0 +1,16 @@ +package com.example.mixin; + +import net.minecraft.client.gui.GuiMainMenu; +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(GuiMainMenu.class) +public class MixinGuiMainMenu { + + @Inject(method = "initGui", at = @At("HEAD")) + public void onInitGui(CallbackInfo ci) { + System.out.println("Hello from Main Menu!"); + } +} diff --git a/src/main/resources/assets/test/test.txt b/src/main/resources/assets/test/test.txt new file mode 100644 index 0000000..ea839e2 --- /dev/null +++ b/src/main/resources/assets/test/test.txt @@ -0,0 +1,3 @@ +test +from resource pack + -- cgit