[WIP] start 1.15 port
reorganize packages to match Fabric version use util classes from Fabric version
This commit is contained in:
26
src/main/kotlin/mods/betterfoliage/util/Resources.kt
Normal file
26
src/main/kotlin/mods/betterfoliage/util/Resources.kt
Normal file
@@ -0,0 +1,26 @@
|
||||
package mods.betterfoliage.util
|
||||
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.resources.IReloadableResourceManager
|
||||
import net.minecraft.resources.IResource
|
||||
import net.minecraft.resources.IResourceManager
|
||||
import net.minecraft.util.ResourceLocation
|
||||
|
||||
/** Concise getter for the Minecraft resource manager. */
|
||||
val resourceManager: IReloadableResourceManager
|
||||
get() = Minecraft.getInstance().resourceManager as IReloadableResourceManager
|
||||
|
||||
/** Append a string to the [ResourceLocation]'s path. */
|
||||
operator fun ResourceLocation.plus(str: String) = ResourceLocation(namespace, path + str)
|
||||
|
||||
/** Index operator to get a resource. */
|
||||
operator fun IResourceManager.get(domain: String, path: String): IResource? = get(ResourceLocation(domain, path))
|
||||
/** Index operator to get a resource. */
|
||||
operator fun IResourceManager.get(location: ResourceLocation): IResource? = tryDefault(null) { getResource(location) }
|
||||
|
||||
/** Get the lines of a text resource. */
|
||||
fun IResource.getLines(): List<String> {
|
||||
val result = arrayListOf<String>()
|
||||
inputStream.bufferedReader().useLines { it.forEach { result.add(it) } }
|
||||
return result
|
||||
}
|
||||
Reference in New Issue
Block a user