Merge branch 'kotlin-1.10' into kotlin-1.11.2
This commit is contained in:
@@ -1,7 +1,11 @@
|
||||
@file:JvmName("Utils")
|
||||
package mods.octarinecore.client.gui
|
||||
|
||||
import net.minecraft.util.text.TextFormatting.*
|
||||
import net.minecraft.util.text.Style
|
||||
import net.minecraft.util.text.TextComponentString
|
||||
import net.minecraft.util.text.TextFormatting
|
||||
import net.minecraft.util.text.TextFormatting.AQUA
|
||||
import net.minecraft.util.text.TextFormatting.GRAY
|
||||
|
||||
fun stripTooltipDefaultText(tooltip: MutableList<String>) {
|
||||
var defaultRows = false
|
||||
@@ -10,4 +14,9 @@ fun stripTooltipDefaultText(tooltip: MutableList<String>) {
|
||||
if (iter.next().startsWith(AQUA.toString())) defaultRows = true
|
||||
if (defaultRows) iter.remove()
|
||||
}
|
||||
}
|
||||
|
||||
fun textComponent(msg: String, color: TextFormatting = GRAY): TextComponentString {
|
||||
val style = Style().apply { this.color = color }
|
||||
return TextComponentString(msg).apply { this.style = style }
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -102,19 +102,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 {
|
||||
@@ -123,5 +123,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
|
||||
|
||||
@@ -8,6 +8,8 @@ import org.objectweb.asm.ClassReader
|
||||
import org.objectweb.asm.ClassWriter
|
||||
import org.objectweb.asm.Opcodes
|
||||
import org.objectweb.asm.tree.*
|
||||
import java.io.File
|
||||
import java.io.FileOutputStream
|
||||
|
||||
@IFMLLoadingPlugin.TransformerExclusions(
|
||||
"mods.octarinecore.metaprog",
|
||||
@@ -55,6 +57,15 @@ open class Transformer : IClassTransformer {
|
||||
MCP -> log.info("Found method ${targetMethod.parentClass.name}.${targetMethod.name(MCP)} ${targetMethod.asmDescriptor(MCP)}")
|
||||
SRG -> log.info("Found method ${targetMethod.parentClass.name}.${targetMethod.name(namespace)} ${targetMethod.asmDescriptor(namespace)} (matching ${targetMethod.name(MCP)})")
|
||||
}
|
||||
|
||||
// write input bytecode for debugging - definitely not in production...
|
||||
//File("BF_debug").mkdir()
|
||||
//FileOutputStream(File("BF_debug/$transformedName.class")).apply {
|
||||
// write(classData)
|
||||
// close()
|
||||
//}
|
||||
|
||||
// transform
|
||||
MethodTransformContext(method, namespace).transform()
|
||||
workDone = true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user