Skip to content

Commit

Permalink
Add kotlin to template
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o committed Feb 29, 2024
1 parent 9566edf commit 97a1180
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 14 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)**

Expand All @@ -17,6 +17,9 @@ The `com.example` package needs to be renamed to match the value of `baseGroup`.
If you don't want mixins (which allow for modifying vanilla code), then you can remove the references to mixins from
the `build.gradle.kts` at the lines specified with comments and the `com.example.mixin` package.

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.

Expand Down
9 changes: 9 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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 "1.8.21"
}

//Constants:
Expand Down Expand Up @@ -52,8 +53,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:
Expand All @@ -74,6 +81,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
Expand Down
13 changes: 0 additions & 13 deletions src/main/java/com/example/ExampleMod.java

This file was deleted.

22 changes: 22 additions & 0 deletions src/main/kotlin/com/example/ExampleMod.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
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

@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}")
}
}
3 changes: 3 additions & 0 deletions src/main/resources/assets/test/test.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test
from resource pack

0 comments on commit 97a1180

Please sign in to comment.