11package com.algorithmlx.dimore.init.resource
22
3+ import com.algorithmlx.dimore.LOGGER
34import com.algorithmlx.dimore.ModId
4- import net.minecraft.resources.Identifier
5+ import com.algorithmlx.dimore.util.ResLoc
56import net.minecraft.server.packs.AbstractPackResources
67import net.minecraft.server.packs.PackLocationInfo
78import net.minecraft.server.packs.PackResources
@@ -11,26 +12,40 @@ import java.io.File
1112import java.io.InputStream
1213
1314class DimOreResourcePack (location : PackLocationInfo ) : AbstractPackResources(location) {
15+ private val targetPath = File (" config/$ModId /custom/client/" )
16+
17+ init {
18+ if (! targetPath.exists()) {
19+ targetPath.parentFile.mkdirs()
20+ targetPath.mkdirs()
21+ LOGGER .info(" Created client directories" )
22+ }
23+ }
24+
1425 override fun getRootResource (vararg path : String ): IoSupplier <InputStream >? = null
1526
1627 override fun getResource (
1728 type : PackType ,
18- location : Identifier
29+ location : ResLoc
1930 ): IoSupplier <InputStream >? {
31+ LOGGER .info(" Loading custom resources" )
2032 if (location.namespace != ModId ) return null
2133
2234 val path = location.path
23- if (! path.contains(" generated." )) return null
2435
25- val relative = when {
36+ if (! path.contains(" custom." )) return null
37+
38+ var relative = when {
2639 path.startsWith(" models/" ) -> path.substring(" models/" .length)
2740 path.startsWith(" textures/" ) -> path.substring(" textures/" .length)
2841 path.startsWith(" model/" ) -> path.substring(" model/" .length)
2942 else -> path
3043 }
3144
32- val target = File (" config/$ModId /custom/client/$relative " )
33- if (target.exists()) {
45+ relative = relative.replace(" custom." , " " )
46+
47+ val target = targetPath.resolve(relative)
48+ if (target.exists() && target.isFile) {
3449 return IoSupplier { target.inputStream() }
3550 }
3651
@@ -42,7 +57,29 @@ class DimOreResourcePack(location: PackLocationInfo) : AbstractPackResources(loc
4257 namespace : String ,
4358 directory : String ,
4459 output : PackResources .ResourceOutput
45- ) {}
60+ ) {
61+ if (namespace != ModId ) return
62+
63+ val relative = when {
64+ directory.startsWith(" models/" ) -> directory.substring(" models/" .length)
65+ directory.startsWith(" textures/" ) -> directory.substring(" textures/" .length)
66+ directory.startsWith(" model/" ) -> directory.substring(" model/" .length)
67+ else -> directory
68+ }
69+
70+ val target = targetPath.resolve(relative)
71+
72+ if (target.exists() && target.isDirectory) {
73+ target.listFiles()
74+ .filter { it.isFile }
75+ .filter { ! it.name.startsWith(" _" ) }
76+ .forEach { file ->
77+ val path = " $directory /custom.${file.name} "
78+ val resLoc = ResLoc .parse(" $ModId :$path " )
79+ output.accept(resLoc) { file.inputStream() }
80+ }
81+ }
82+ }
4683
4784 override fun getNamespaces (type : PackType ): Set <String > = setOf (ModId )
4885
0 commit comments