add support for multipart models
This commit is contained in:
@@ -21,6 +21,7 @@ import mods.octarinecore.common.rotate
|
|||||||
import mods.octarinecore.metaprog.ClassRef
|
import mods.octarinecore.metaprog.ClassRef
|
||||||
import mods.octarinecore.metaprog.MethodRef
|
import mods.octarinecore.metaprog.MethodRef
|
||||||
import mods.octarinecore.metaprog.allAvailable
|
import mods.octarinecore.metaprog.allAvailable
|
||||||
|
import mods.octarinecore.tryDefault
|
||||||
import net.minecraft.block.properties.PropertyDirection
|
import net.minecraft.block.properties.PropertyDirection
|
||||||
import net.minecraft.block.state.IBlockState
|
import net.minecraft.block.state.IBlockState
|
||||||
import net.minecraft.client.renderer.block.model.ModelResourceLocation
|
import net.minecraft.client.renderer.block.model.ModelResourceLocation
|
||||||
@@ -133,7 +134,7 @@ object IC2LogSupport : RubberLogSupportBase() {
|
|||||||
override fun processModelLoad(state: IBlockState, modelLoc: ModelResourceLocation, model: IModel): RubberLogModelInfo? {
|
override fun processModelLoad(state: IBlockState, modelLoc: ModelResourceLocation, model: IModel): RubberLogModelInfo? {
|
||||||
// check for proper block class, existence of ModelBlock, and "state" blockstate property
|
// check for proper block class, existence of ModelBlock, and "state" blockstate property
|
||||||
if (!IC2Integration.BlockRubWood.isInstance(state.block)) return null
|
if (!IC2Integration.BlockRubWood.isInstance(state.block)) return null
|
||||||
val blockLoc = model.modelBlockAndLoc ?: return null
|
val blockLoc = model.modelBlockAndLoc.firstOrNull() ?: return null
|
||||||
val type = state.properties.entries.find { it.key.getName() == "state" }?.value?.toString() ?: return null
|
val type = state.properties.entries.find { it.key.getName() == "state" }?.value?.toString() ?: return null
|
||||||
|
|
||||||
// logs with no rubber spot
|
// logs with no rubber spot
|
||||||
|
|||||||
@@ -63,14 +63,12 @@ object Refs {
|
|||||||
val VanillaModelWrapper = ClassRef("net.minecraftforge.client.model.ModelLoader\$VanillaModelWrapper")
|
val VanillaModelWrapper = ClassRef("net.minecraftforge.client.model.ModelLoader\$VanillaModelWrapper")
|
||||||
val model_VMW = FieldRef(VanillaModelWrapper, "model", ModelBlock)
|
val model_VMW = FieldRef(VanillaModelWrapper, "model", ModelBlock)
|
||||||
val location_VMW = FieldRef(VanillaModelWrapper, "location", ModelBlock)
|
val location_VMW = FieldRef(VanillaModelWrapper, "location", ModelBlock)
|
||||||
// val WeightedPartWrapper = ClassRef("net.minecraftforge.client.model.ModelLoader\$WeightedPartWrapper")
|
|
||||||
// val model_WPW = FieldRef(WeightedPartWrapper, "model", IModel)
|
|
||||||
val WeightedRandomModel = ClassRef("net.minecraftforge.client.model.ModelLoader\$WeightedRandomModel")
|
val WeightedRandomModel = ClassRef("net.minecraftforge.client.model.ModelLoader\$WeightedRandomModel")
|
||||||
val models_WRM = FieldRef(WeightedRandomModel, "models", List)
|
val models_WRM = FieldRef(WeightedRandomModel, "models", List)
|
||||||
val MultiModel = ClassRef("net.minecraftforge.client.model.MultiModel")
|
val MultiModel = ClassRef("net.minecraftforge.client.model.MultiModel")
|
||||||
val base_MM = FieldRef(MultiModel, "base", IModel)
|
val base_MM = FieldRef(MultiModel, "base", IModel)
|
||||||
val WeightedBakedModel = ClassRef("net.minecraft.client.renderer.block.model.WeightedBakedModel")
|
val MultipartModel = ClassRef("net.minecraftforge.client.model.ModelLoader\$MultipartModel")
|
||||||
val models_WBM = FieldRef(WeightedBakedModel, "models", List)
|
val partModels_MPM = FieldRef(MultipartModel, "partModels", List)
|
||||||
|
|
||||||
val resetChangedState = MethodRef(ClassRef("net.minecraftforge.common.config.Configuration"), "resetChangedState", ClassRef.void)
|
val resetChangedState = MethodRef(ClassRef("net.minecraftforge.common.config.Configuration"), "resetChangedState", ClassRef.void)
|
||||||
|
|
||||||
|
|||||||
@@ -75,16 +75,13 @@ interface TextureListModelProcessor<T2> : ModelProcessor<List<String>, T2> {
|
|||||||
logger?.log(Level.DEBUG, "$logName: block state ${state.toString()}")
|
logger?.log(Level.DEBUG, "$logName: block state ${state.toString()}")
|
||||||
logger?.log(Level.DEBUG, "$logName: class ${state.block.javaClass.name} matches ${matchClass.name}")
|
logger?.log(Level.DEBUG, "$logName: class ${state.block.javaClass.name} matches ${matchClass.name}")
|
||||||
|
|
||||||
val blockLoc = model.modelBlockAndLoc
|
val allModels = model.modelBlockAndLoc
|
||||||
if (blockLoc == null) {
|
if (allModels.isEmpty()) {
|
||||||
logger?.log(Level.DEBUG, "$logName: no models found")
|
logger?.log(Level.DEBUG, "$logName: no models found")
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
val modelMatch = modelTextures.firstOrNull { blockLoc.derivesFrom(it.modelLocation) }
|
allModels.forEach { blockLoc ->
|
||||||
if (modelMatch == null) {
|
modelTextures.firstOrNull { blockLoc.derivesFrom(it.modelLocation) }?.let{ modelMatch ->
|
||||||
logger?.log(Level.DEBUG, "$logName: no matching models found")
|
|
||||||
return null
|
|
||||||
}
|
|
||||||
logger?.log(Level.DEBUG, "$logName: model ${blockLoc.second} matches ${modelMatch.modelLocation.toString()}")
|
logger?.log(Level.DEBUG, "$logName: model ${blockLoc.second} matches ${modelMatch.modelLocation.toString()}")
|
||||||
|
|
||||||
val textures = modelMatch.textureNames.map { it to blockLoc.first.resolveTextureName(it) }
|
val textures = modelMatch.textureNames.map { it to blockLoc.first.resolveTextureName(it) }
|
||||||
@@ -94,6 +91,10 @@ interface TextureListModelProcessor<T2> : ModelProcessor<List<String>, T2> {
|
|||||||
return if (textures.all { it.second != "missingno" }) textures.map { it.second } else null
|
return if (textures.all { it.second != "missingno" }) textures.map { it.second } else null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
logger?.log(Level.DEBUG, "$logName: no matching models found")
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
interface TextureMediatedRegistry<T1, T3> : ModelProcessor<T1, TextureAtlasSprite> {
|
interface TextureMediatedRegistry<T1, T3> : ModelProcessor<T1, TextureAtlasSprite> {
|
||||||
|
|
||||||
|
|||||||
@@ -100,19 +100,19 @@ fun textureLocation(iconName: String) = ResourceLocation(iconName).let {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val IModel.modelBlockAndLoc: Pair<ModelBlock, ResourceLocation>? get() {
|
val IModel.modelBlockAndLoc: List<Pair<ModelBlock, ResourceLocation>> get() {
|
||||||
if (Refs.VanillaModelWrapper.isInstance(this))
|
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 {
|
else if (Refs.WeightedRandomModel.isInstance(this)) Refs.models_WRM.get(this)?.let {
|
||||||
(it as List<IModel>).forEach {
|
return (it as List<IModel>).flatMap(IModel::modelBlockAndLoc)
|
||||||
it.modelBlockAndLoc.let { if (it != null) return it }
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else if (Refs.MultiModel.isInstance(this)) Refs.base_MM.get(this)?.let {
|
else if (Refs.MultiModel.isInstance(this)) Refs.base_MM.get(this)?.let {
|
||||||
return (it as IModel).modelBlockAndLoc
|
return (it as IModel).modelBlockAndLoc
|
||||||
}
|
}
|
||||||
// TODO support net.minecraftforge.client.model.ModelLoader.MultipartModel
|
else if (Refs.MultipartModel.isInstance(this)) Refs.partModels_MPM.get(this)?.let {
|
||||||
return null
|
return (it as Map<Any, IModel>).flatMap { it.value.modelBlockAndLoc }
|
||||||
|
}
|
||||||
|
return listOf()
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Pair<ModelBlock, ResourceLocation>.derivesFrom(targetLocation: ResourceLocation): Boolean {
|
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 Pair(first.parent, first.parentLocation!!).derivesFrom(targetLocation)
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
fun IModel.derivesFromModel(modelLoc: String) = modelBlockAndLoc?.derivesFrom(ResourceLocation(modelLoc)) ?: false
|
|
||||||
|
|||||||
Reference in New Issue
Block a user