Skip to content

Commit

Permalink
Fix resource packs on kotlin
Browse files Browse the repository at this point in the history
  • Loading branch information
nea89o committed Aug 22, 2023
1 parent 5fd69bc commit 081b1b0
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,14 @@ loom {
}
}

tasks.compileJava {
dependsOn(tasks.processResources)
}

sourceSets.main {
kotlin.destinationDirectory.set(java.destinationDirectory)
java.srcDir(file("$projectDir/src/main/kotlin"))
output.setResourcesDir(file("$buildDir/classes/java/main"))
output.setResourcesDir(java.destinationDirectory)
}

// Dependencies:
Expand Down
9 changes: 9 additions & 0 deletions src/main/kotlin/com/example/ExampleMod.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
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
Expand All @@ -8,6 +9,14 @@ import net.minecraftforge.fml.common.event.FMLInitializationEvent
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 081b1b0

Please sign in to comment.