better block discovery logging
This commit is contained in:
@@ -16,6 +16,9 @@ import net.minecraft.client.render.model.ModelLoader
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture
|
||||
import net.minecraft.resource.ResourceManager
|
||||
import net.minecraft.util.Identifier
|
||||
import org.apache.logging.log4j.Level
|
||||
import org.apache.logging.log4j.Level.DEBUG
|
||||
import org.apache.logging.log4j.Level.WARN
|
||||
import java.lang.ref.WeakReference
|
||||
import java.util.*
|
||||
import java.util.concurrent.CompletableFuture
|
||||
@@ -63,7 +66,7 @@ class BakedModelReplacer : ModelLoadingCallback, ClientSpriteRegistryCallback, B
|
||||
keys.entries.forEach { (state, key) ->
|
||||
val oldKey = result[state]
|
||||
if (oldKey != null) log("Replacing $oldKey with $key for state $state")
|
||||
else log("Adding replacement $key for state $state")
|
||||
else log(DEBUG, "Adding replacement $key for state $state")
|
||||
result[state] = key
|
||||
}
|
||||
}
|
||||
@@ -77,14 +80,14 @@ class BakedModelReplacer : ModelLoadingCallback, ClientSpriteRegistryCallback, B
|
||||
val modelMap = blockModels[BlockModels_models] as MutableMap<BlockState, BakedModel>
|
||||
keys.forEach { (state, key) ->
|
||||
val oldModel = modelMap[state]
|
||||
if (oldModel == null) log("Cannot find model for state $state, ignoring")
|
||||
if (oldModel == null) log(WARN, "Cannot find model for state $state, ignoring")
|
||||
else {
|
||||
try {
|
||||
val newModel = key.replace(oldModel, state)
|
||||
modelMap[state] = newModel
|
||||
log("Replaced model for state $state with $key")
|
||||
log(DEBUG, "Replaced model for state $state with $key")
|
||||
} catch (e: Exception) {
|
||||
log("Error creating model for state $state with $key", e)
|
||||
log(WARN, "Error creating model for state $state with $key", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,8 +5,12 @@ import mods.betterfoliage.util.YarnHelper
|
||||
import mods.betterfoliage.util.get
|
||||
import mods.betterfoliage.util.stripStart
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.client.render.model.ModelLoader
|
||||
import net.minecraft.client.render.model.json.JsonUnbakedModel
|
||||
import net.minecraft.util.Identifier
|
||||
import org.apache.logging.log4j.Level
|
||||
import org.apache.logging.log4j.Level.DEBUG
|
||||
import org.apache.logging.log4j.Level.INFO
|
||||
import java.util.function.Consumer
|
||||
|
||||
// net.minecraft.client.render.model.json.JsonUnbakedModel.parent
|
||||
@@ -26,25 +30,36 @@ abstract class ConfigurableModelDiscovery : ModelDiscoveryBase() {
|
||||
abstract val matchClasses: IBlockMatcher
|
||||
abstract val modelTextures: List<ModelTextureList>
|
||||
|
||||
override fun discover(loader: ModelLoader, atlas: Consumer<Identifier>): Map<BlockState, BlockRenderKey> {
|
||||
log(INFO, "Starting model discovery: ${this::class.java.canonicalName}")
|
||||
matchClasses.describe(this)
|
||||
modelTextures.forEach { modelTex ->
|
||||
log(DEBUG, " model: ${modelTex.modelLocation} textures: ${modelTex.textureNames.joinToString(", ")}")
|
||||
}
|
||||
return super.discover(loader, atlas)
|
||||
}
|
||||
|
||||
abstract fun processModel(state: BlockState, textures: List<String>, atlas: Consumer<Identifier>): BlockRenderKey?
|
||||
|
||||
override fun processModel(ctx: ModelDiscoveryContext, atlas: Consumer<Identifier>): BlockRenderKey? {
|
||||
val matchClass = matchClasses.matchingClass(ctx.state.block) ?: return null
|
||||
log("block state ${ctx.state.toString()}")
|
||||
log(" class ${ctx.state.block.javaClass.name} matches ${matchClass.name}")
|
||||
log(DEBUG, "block state ${ctx.state.toString()}")
|
||||
log(DEBUG, " class ${ctx.state.block.javaClass.name} matches ${matchClass.name}")
|
||||
|
||||
(ctx.models.filter { it.first is JsonUnbakedModel } as List<Pair<JsonUnbakedModel, Identifier>>).forEach { (model, location) ->
|
||||
val modelMatch = modelTextures.firstOrNull { (model to location).derivesFrom(it.modelLocation) }
|
||||
if (modelMatch != null) {
|
||||
log(" model ${model} matches ${modelMatch.modelLocation}")
|
||||
log(DEBUG, " model ${model} matches ${modelMatch.modelLocation}")
|
||||
|
||||
val textures = modelMatch.textureNames.map { it to model.resolveTexture(it) }
|
||||
val texMapString = Joiner.on(", ").join(textures.map { "${it.first}=${it.second}" })
|
||||
log(" sprites [$texMapString]")
|
||||
log(DEBUG, " sprites [$texMapString]")
|
||||
|
||||
if (textures.all { it.second != "missingno" }) {
|
||||
// found a valid model (all required textures exist)
|
||||
return processModel(ctx.state, textures.map { it.second }, atlas)
|
||||
return processModel(ctx.state, textures.map { it.second }, atlas).also {
|
||||
log(DEBUG, " valid model discovered: $it")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package mods.betterfoliage.resource.discovery
|
||||
|
||||
import mods.betterfoliage.util.HasLogger
|
||||
import mods.betterfoliage.util.getLines
|
||||
import mods.betterfoliage.util.INTERMEDIARY
|
||||
import mods.betterfoliage.util.getJavaClass
|
||||
@@ -7,11 +8,14 @@ import net.fabricmc.loader.api.FabricLoader
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.resource.ResourceManager
|
||||
import net.minecraft.util.Identifier
|
||||
import org.apache.logging.log4j.Level
|
||||
import org.apache.logging.log4j.Logger
|
||||
|
||||
interface IBlockMatcher {
|
||||
fun matchesClass(block: Block): Boolean
|
||||
fun matchingClass(block: Block): Class<*>?
|
||||
|
||||
fun describe(logger: HasLogger)
|
||||
}
|
||||
|
||||
class SimpleBlockMatcher(vararg val classes: Class<*>) : IBlockMatcher {
|
||||
@@ -22,6 +26,12 @@ class SimpleBlockMatcher(vararg val classes: Class<*>) : IBlockMatcher {
|
||||
classes.forEach { if (it.isAssignableFrom(blockClass)) return it }
|
||||
return null
|
||||
}
|
||||
|
||||
override fun describe(logger: HasLogger) {
|
||||
classes.forEach { klass ->
|
||||
logger.log(Level.DEBUG, " class whitelist: ${klass.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class ConfigurableBlockMatcher(val logger: Logger, val location: Identifier) : IBlockMatcher {
|
||||
@@ -47,16 +57,33 @@ class ConfigurableBlockMatcher(val logger: Logger, val location: Identifier) : I
|
||||
blackList.clear()
|
||||
whiteList.clear()
|
||||
manager.getAllResources(location).forEach { resource ->
|
||||
logger.debug("Reading resource $location from pack ${resource.resourcePackName}")
|
||||
logger.info("Reading class list $location from pack ${resource.resourcePackName}")
|
||||
resource.getLines().map{ it.trim() }.filter { !it.startsWith("//") && it.isNotEmpty() }.forEach { line ->
|
||||
if (line.startsWith("-")) getBlockClass(line.substring(1))?.let { blackList.add(it) }
|
||||
else getBlockClass(line)?.let { whiteList.add(it) }
|
||||
val name = if (line.startsWith("-")) line.substring(1) else line
|
||||
val mappedName = FabricLoader.getInstance().mappingResolver.mapClassName(INTERMEDIARY, name)
|
||||
if (name != mappedName) logger.debug(" found yarn mapping for class: $name -> $mappedName")
|
||||
val klass = getJavaClass(mappedName)
|
||||
|
||||
val list = if (line.startsWith("-")) "blacklist" to blackList else "whitelist" to whiteList
|
||||
|
||||
if (klass != null) {
|
||||
logger.debug(" ${list.first} class $name found")
|
||||
list.second.add(klass)
|
||||
} else {
|
||||
logger.debug(" ${list.first} class $name not found")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun getBlockClass(name: String) = getJavaClass(FabricLoader.getInstance().mappingResolver.mapClassName(INTERMEDIARY, name))
|
||||
override fun describe(logger: HasLogger) {
|
||||
whiteList.forEach { klass ->
|
||||
logger.log(Level.DEBUG, " class whitelist: ${klass.name}")
|
||||
}
|
||||
blackList.forEach { klass ->
|
||||
logger.log(Level.DEBUG, " class blacklist: ${klass.name}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class ModelTextureList(val modelLocation: Identifier, val textureNames: List<String>) {
|
||||
@@ -67,7 +94,7 @@ class ModelTextureListConfiguration(val logger: Logger, val location: Identifier
|
||||
val modelList = mutableListOf<ModelTextureList>()
|
||||
fun readDefaults(manager: ResourceManager) {
|
||||
manager.getAllResources(location).forEach { resource ->
|
||||
logger.debug("Reading resource $location from pack ${resource.resourcePackName}")
|
||||
logger.info("Reading model configuration $location from pack ${resource.resourcePackName}")
|
||||
resource.getLines().map{ it.trim() }.filter { !it.startsWith("//") && it.isNotEmpty() }.forEach { line ->
|
||||
val elements = line.split(",")
|
||||
modelList.add(ModelTextureList(Identifier(elements.first()), elements.drop(1)))
|
||||
|
||||
Reference in New Issue
Block a user