add support for multipart models

This commit is contained in:
octarine-noise
2017-05-06 09:36:32 +02:00
parent 674d22fdbb
commit 81ef954524
4 changed files with 25 additions and 27 deletions

View File

@@ -75,23 +75,24 @@ interface TextureListModelProcessor<T2> : ModelProcessor<List<String>, T2> {
logger?.log(Level.DEBUG, "$logName: block state ${state.toString()}")
logger?.log(Level.DEBUG, "$logName: class ${state.block.javaClass.name} matches ${matchClass.name}")
val blockLoc = model.modelBlockAndLoc
if (blockLoc == null) {
val allModels = model.modelBlockAndLoc
if (allModels.isEmpty()) {
logger?.log(Level.DEBUG, "$logName: no models found")
return null
}
val modelMatch = modelTextures.firstOrNull { blockLoc.derivesFrom(it.modelLocation) }
if (modelMatch == null) {
logger?.log(Level.DEBUG, "$logName: no matching models found")
return null
allModels.forEach { blockLoc ->
modelTextures.firstOrNull { blockLoc.derivesFrom(it.modelLocation) }?.let{ modelMatch ->
logger?.log(Level.DEBUG, "$logName: model ${blockLoc.second} matches ${modelMatch.modelLocation.toString()}")
val textures = modelMatch.textureNames.map { it to blockLoc.first.resolveTextureName(it) }
val texMapString = Joiner.on(", ").join(textures.map { "${it.first}=${it.second}" })
logger?.log(Level.DEBUG, "$logName: textures [$texMapString]")
return if (textures.all { it.second != "missingno" }) textures.map { it.second } else null
}
}
logger?.log(Level.DEBUG, "$logName: model ${blockLoc.second} matches ${modelMatch.modelLocation.toString()}")
val textures = modelMatch.textureNames.map { it to blockLoc.first.resolveTextureName(it) }
val texMapString = Joiner.on(", ").join(textures.map { "${it.first}=${it.second}" })
logger?.log(Level.DEBUG, "$logName: textures [$texMapString]")
return if (textures.all { it.second != "missingno" }) textures.map { it.second } else null
logger?.log(Level.DEBUG, "$logName: no matching models found")
return null
}
}

View File

@@ -100,19 +100,19 @@ fun textureLocation(iconName: String) = ResourceLocation(iconName).let {
}
@Suppress("UNCHECKED_CAST")
val IModel.modelBlockAndLoc: Pair<ModelBlock, ResourceLocation>? get() {
val IModel.modelBlockAndLoc: List<Pair<ModelBlock, ResourceLocation>> get() {
if (Refs.VanillaModelWrapper.isInstance(this))
return Pair(Refs.model_VMW.get(this) as ModelBlock, Refs.location_VMW.get(this) as ResourceLocation)
return listOf(Pair(Refs.model_VMW.get(this) as ModelBlock, Refs.location_VMW.get(this) as ResourceLocation))
else if (Refs.WeightedRandomModel.isInstance(this)) Refs.models_WRM.get(this)?.let {
(it as List<IModel>).forEach {
it.modelBlockAndLoc.let { if (it != null) return it }
}
return (it as List<IModel>).flatMap(IModel::modelBlockAndLoc)
}
else if (Refs.MultiModel.isInstance(this)) Refs.base_MM.get(this)?.let {
return (it as IModel).modelBlockAndLoc
}
// TODO support net.minecraftforge.client.model.ModelLoader.MultipartModel
return null
else if (Refs.MultipartModel.isInstance(this)) Refs.partModels_MPM.get(this)?.let {
return (it as Map<Any, IModel>).flatMap { it.value.modelBlockAndLoc }
}
return listOf()
}
fun Pair<ModelBlock, ResourceLocation>.derivesFrom(targetLocation: ResourceLocation): Boolean {
@@ -121,5 +121,3 @@ fun Pair<ModelBlock, ResourceLocation>.derivesFrom(targetLocation: ResourceLocat
return Pair(first.parent, first.parentLocation!!).derivesFrom(targetLocation)
return false
}
fun IModel.derivesFromModel(modelLoc: String) = modelBlockAndLoc?.derivesFrom(ResourceLocation(modelLoc)) ?: false