rewrite model and texture detection
expose in mod configuration
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package mods.octarinecore.common.config
|
||||
|
||||
import mods.octarinecore.client.gui.NonVerboseArrayEntry
|
||||
import mods.octarinecore.client.resource.get
|
||||
import mods.octarinecore.client.resource.getLines
|
||||
import mods.octarinecore.client.resource.resourceManager
|
||||
import net.minecraftforge.common.config.Configuration
|
||||
import net.minecraftforge.common.config.Property
|
||||
|
||||
abstract class BlackWhiteListConfigOption<VALUE>(val domain: String, val path: String) : ConfigPropertyBase() {
|
||||
|
||||
val blackList = mutableListOf<VALUE>()
|
||||
val whiteList = mutableListOf<VALUE>()
|
||||
var blacklistProperty: Property? = null
|
||||
var whitelistProperty: Property? = null
|
||||
|
||||
override val hasChanged: Boolean
|
||||
get() = blacklistProperty?.hasChanged() ?: false || whitelistProperty?.hasChanged() ?: false
|
||||
|
||||
override val guiProperties: List<Property> get() = listOf(whitelistProperty!!, blacklistProperty!!)
|
||||
|
||||
override fun attach(target: Configuration, langPrefix: String, categoryName: String, propertyName: String) {
|
||||
lang = null
|
||||
val defaults = readDefaults(domain, path)
|
||||
blacklistProperty = target.get(categoryName, "${propertyName}Blacklist", defaults.first)
|
||||
whitelistProperty = target.get(categoryName, "${propertyName}Whitelist", defaults.second)
|
||||
listOf(blacklistProperty!!, whitelistProperty!!).forEach {
|
||||
it.configEntryClass = NonVerboseArrayEntry::class.java
|
||||
it.languageKey = "$langPrefix.$categoryName.${it.name}"
|
||||
}
|
||||
read()
|
||||
}
|
||||
|
||||
abstract fun convertValue(line: String): VALUE?
|
||||
|
||||
override fun read() {
|
||||
listOf(Pair(blackList, blacklistProperty!!), Pair(whiteList, whitelistProperty!!)).forEach {
|
||||
it.first.clear()
|
||||
it.second.stringList.forEach { line ->
|
||||
val value = convertValue(line)
|
||||
if (value != null) it.first.add(value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun readDefaults(domain: String, path: String): Pair<Array<String>, Array<String>> {
|
||||
val blackList = arrayListOf<String>()
|
||||
val whiteList = arrayListOf<String>()
|
||||
val defaults = resourceManager[domain, path]?.getLines()
|
||||
defaults?.map{ it.trim() }?.filter { !it.startsWith("//") && it.isNotEmpty() }?.forEach {
|
||||
if (it.startsWith("-")) { blackList.add(it.substring(1)) }
|
||||
else { whiteList.add(it) }
|
||||
}
|
||||
return (blackList.toTypedArray() to whiteList.toTypedArray())
|
||||
}
|
||||
}
|
||||
33
src/main/kotlin/mods/octarinecore/common/config/Matchers.kt
Normal file
33
src/main/kotlin/mods/octarinecore/common/config/Matchers.kt
Normal file
@@ -0,0 +1,33 @@
|
||||
package mods.octarinecore.common.config
|
||||
|
||||
import mods.octarinecore.metaprog.getJavaClass
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.util.ResourceLocation
|
||||
|
||||
class BlockMatcher(domain: String, path: String) : BlackWhiteListConfigOption<Class<*>>(domain, path) {
|
||||
override fun convertValue(line: String) = getJavaClass(line)
|
||||
|
||||
fun matchesClass(block: Block): Boolean {
|
||||
val blockClass = block.javaClass
|
||||
blackList.forEach { if (it.isAssignableFrom(blockClass)) return false }
|
||||
whiteList.forEach { if (it.isAssignableFrom(blockClass)) return true }
|
||||
return false
|
||||
}
|
||||
|
||||
fun matchingClass(block: Block): Class<*>? {
|
||||
val blockClass = block.javaClass
|
||||
blackList.forEach { if (it.isAssignableFrom(blockClass)) return null }
|
||||
whiteList.forEach { if (it.isAssignableFrom(blockClass)) return it }
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
data class ModelTextureList(val modelLocation: ResourceLocation, val textureNames: List<String>)
|
||||
|
||||
class ModelTextureListConfigOption(domain: String, path: String, val minTextures: Int) : StringListConfigOption<ModelTextureList>(domain, path) {
|
||||
override fun convertValue(line: String): ModelTextureList? {
|
||||
val elements = line.split(",")
|
||||
if (elements.size < minTextures + 1) return null
|
||||
return ModelTextureList(ResourceLocation(elements.first()), elements.drop(1))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
package mods.octarinecore.common.config
|
||||
|
||||
import mods.octarinecore.client.gui.NonVerboseArrayEntry
|
||||
import mods.octarinecore.client.resource.get
|
||||
import mods.octarinecore.client.resource.getLines
|
||||
import mods.octarinecore.client.resource.resourceManager
|
||||
import net.minecraftforge.common.config.Configuration
|
||||
import net.minecraftforge.common.config.Property
|
||||
|
||||
abstract class StringListConfigOption<VALUE>(val domain: String, val path: String) : ConfigPropertyBase() {
|
||||
|
||||
val list = mutableListOf<VALUE>()
|
||||
lateinit var listProperty: Property
|
||||
|
||||
override val hasChanged: Boolean get() = listProperty.hasChanged() ?: false
|
||||
override val guiProperties: List<Property> get() = listOf(listProperty)
|
||||
|
||||
override fun attach(target: Configuration, langPrefix: String, categoryName: String, propertyName: String) {
|
||||
lang = null
|
||||
val defaults = readDefaults(domain, path)
|
||||
listProperty = target.get(categoryName, "${propertyName}", defaults)
|
||||
listProperty.configEntryClass = NonVerboseArrayEntry::class.java
|
||||
listProperty.languageKey = "$langPrefix.$categoryName.${listProperty.name}"
|
||||
read()
|
||||
}
|
||||
|
||||
abstract fun convertValue(line: String): VALUE?
|
||||
|
||||
override fun read() {
|
||||
list.clear()
|
||||
listProperty.stringList.forEach { line ->
|
||||
val value = convertValue(line)
|
||||
if (value != null) list.add(value)
|
||||
}
|
||||
}
|
||||
|
||||
fun readDefaults(domain: String, path: String): Array<String> {
|
||||
val list = arrayListOf<String>()
|
||||
val defaults = resourceManager[domain, path]?.getLines()
|
||||
defaults?.map { it.trim() }?.filter { !it.startsWith("//") && it.isNotEmpty() }?.forEach { list.add(it) }
|
||||
return list.toTypedArray()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user