get tint index directly from model
This commit is contained in:
@@ -99,4 +99,7 @@ Node.Value matchValue() : {
|
|||||||
|
|
|
|
||||||
"model.texture" <parenStart> t = <stringLiteral> <parenEnd>
|
"model.texture" <parenStart> t = <stringLiteral> <parenEnd>
|
||||||
{ return new Node.Value.Texture(t.image); }
|
{ return new Node.Value.Texture(t.image); }
|
||||||
|
|
|
||||||
|
"model.tint" <parenStart> t = <stringLiteral> <parenEnd>
|
||||||
|
{ return new Node.Value.Tint(t.image); }
|
||||||
}
|
}
|
||||||
@@ -2,6 +2,7 @@ package mods.betterfoliage.config.match
|
|||||||
|
|
||||||
import mods.betterfoliage.resource.discovery.RuleProcessingContext
|
import mods.betterfoliage.resource.discovery.RuleProcessingContext
|
||||||
import mods.betterfoliage.resource.discovery.getAncestry
|
import mods.betterfoliage.resource.discovery.getAncestry
|
||||||
|
import mods.betterfoliage.util.findFirst
|
||||||
import mods.betterfoliage.util.tryDefault
|
import mods.betterfoliage.util.tryDefault
|
||||||
import net.minecraft.block.Block
|
import net.minecraft.block.Block
|
||||||
import net.minecraft.client.renderer.model.BlockModel
|
import net.minecraft.client.renderer.model.BlockModel
|
||||||
@@ -29,7 +30,7 @@ object MatchRuleList {
|
|||||||
when (node.matchSource) {
|
when (node.matchSource) {
|
||||||
Node.MatchSource.BLOCK_CLASS -> BlockMatchRules.visitClass(ctx, node, value)
|
Node.MatchSource.BLOCK_CLASS -> BlockMatchRules.visitClass(ctx, node, value)
|
||||||
Node.MatchSource.BLOCK_NAME -> BlockMatchRules.visitName(ctx, node, value)
|
Node.MatchSource.BLOCK_NAME -> BlockMatchRules.visitName(ctx, node, value)
|
||||||
Node.MatchSource.MODEL_LOCATION -> ModelMatchRules.visit(ctx, node, value)
|
Node.MatchSource.MODEL_LOCATION -> ModelMatchRules.visitModel(ctx, node, value)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
MatchResult.Error(node.configSource, e.message ?: "")
|
MatchResult.Error(node.configSource, e.message ?: "")
|
||||||
@@ -85,7 +86,7 @@ object BlockMatchRules {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object ModelMatchRules {
|
object ModelMatchRules {
|
||||||
fun visit(ctx: RuleProcessingContext, node: Node.MatchValueList, value: Node.Value): MatchResult {
|
fun visitModel(ctx: RuleProcessingContext, node: Node.MatchValueList, value: Node.Value): MatchResult {
|
||||||
val source = ctx.discovery.modelLocation.let { MatchValue.Found("model \"$it\"", it) }
|
val source = ctx.discovery.modelLocation.let { MatchValue.Found("model \"$it\"", it) }
|
||||||
if (value !is Node.Value.Literal) return node.invalidValueType("model", value)
|
if (value !is Node.Value.Literal) return node.invalidValueType("model", value)
|
||||||
val (namespace, path) = value.value.splitLocation()
|
val (namespace, path) = value.value.splitLocation()
|
||||||
@@ -137,14 +138,29 @@ object ParamMatchRules {
|
|||||||
val target = when(node.value) {
|
val target = when(node.value) {
|
||||||
is Node.Value.Literal -> node.value.value.let { MatchValue.Found("\"$it\"", it) }
|
is Node.Value.Literal -> node.value.value.let { MatchValue.Found("\"$it\"", it) }
|
||||||
is Node.Value.Texture -> when(val model = ctx.discovery.getUnbaked()) {
|
is Node.Value.Texture -> when(val model = ctx.discovery.getUnbaked()) {
|
||||||
is BlockModel -> model.getMaterial(node.value.value).texture().toString().let {
|
is BlockModel -> getModelTexture(model, node.value.value)
|
||||||
MatchValue.Found("texture \"${node.value.value}\" = \"$it\"", it)
|
|
||||||
}
|
|
||||||
else -> return node.error("cannot get texture from ${model::class.java.name}")
|
else -> return node.error("cannot get texture from ${model::class.java.name}")
|
||||||
}
|
}
|
||||||
|
is Node.Value.Tint -> when(val model = ctx.discovery.getUnbaked()) {
|
||||||
|
is BlockModel -> getModelTint(ctx.discovery.loadHierarchy(model), node.value.value)
|
||||||
|
else -> return node.error("cannot get tint index from ${model::class.java.name}")
|
||||||
|
}
|
||||||
else -> return node.invalidValueType("parameter", node.value)
|
else -> return node.invalidValueType("parameter", node.value)
|
||||||
}
|
}
|
||||||
ctx.params[node.name] = target.value
|
ctx.params[node.name] = target.value
|
||||||
return node.action("parameter \"${node.name}\" set to ${target.description}")
|
return node.action("parameter \"${node.name}\" set to ${target.description}")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getModelTexture(model: BlockModel, spriteName: String) =
|
||||||
|
model.getMaterial(spriteName).texture().toString().let {
|
||||||
|
MatchValue.Found("texture \"${spriteName}\" = \"$it\"", it)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun getModelTint(model: BlockModel, spriteName: String) =
|
||||||
|
model.elements.findFirst { element ->
|
||||||
|
element.faces.entries.firstOrNull { (_, face) ->
|
||||||
|
face.texture == "#$spriteName"
|
||||||
|
}?.value?.tintIndex ?: -1
|
||||||
|
}?.let { MatchValue.Found("tint index \"$it\" for sprite \"${spriteName}\"", it.toString()) }
|
||||||
|
?: MatchValue.Found("tint index \"-1\" for unused sprite \"${spriteName}\"", "-1")
|
||||||
}
|
}
|
||||||
@@ -33,5 +33,6 @@ sealed class Node {
|
|||||||
class Literal(value: String) : Value(value)
|
class Literal(value: String) : Value(value)
|
||||||
class ClassOf(value: String) : Value(value)
|
class ClassOf(value: String) : Value(value)
|
||||||
class Texture(value: String) : Value(value)
|
class Texture(value: String) : Value(value)
|
||||||
|
class Tint(value: String) : Value(value)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,13 +49,13 @@ fun tuftQuadSingle(size: Double, height: Double, flipU: Boolean) =
|
|||||||
)
|
)
|
||||||
.mirrorUV(flipU, false)
|
.mirrorUV(flipU, false)
|
||||||
|
|
||||||
fun tuftModelSet(shapes: Array<TuftShapeKey>, overrideColor: Color?, spriteGetter: (Int) -> TextureAtlasSprite) =
|
fun tuftModelSet(shapes: Array<TuftShapeKey>, color: Color, tint: Int, spriteGetter: (Int) -> TextureAtlasSprite) =
|
||||||
shapes.mapIndexed { idx, shape ->
|
shapes.mapIndexed { idx, shape ->
|
||||||
listOf(
|
listOf(
|
||||||
tuftQuadSingle(shape.size, shape.height, shape.flipU1),
|
tuftQuadSingle(shape.size, shape.height, shape.flipU1),
|
||||||
tuftQuadSingle(shape.size, shape.height, shape.flipU2).rotate(rot(UP))
|
tuftQuadSingle(shape.size, shape.height, shape.flipU2).rotate(rot(UP))
|
||||||
).map { it.move(shape.offset) }
|
).map { it.move(shape.offset) }
|
||||||
.map { it.colorAndIndex(overrideColor) }
|
.map { it.color(color).colorIndex(tint) }
|
||||||
.map { it.sprite(spriteGetter(idx)) }
|
.map { it.sprite(spriteGetter(idx)) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ class StandardCactusModel(
|
|||||||
}
|
}
|
||||||
val cactusArmModels by BetterFoliage.modelManager.lazy {
|
val cactusArmModels by BetterFoliage.modelManager.lazy {
|
||||||
val shapes = Config.cactus.let { tuftShapeSet(0.8, 0.8, 0.8, 0.2) }
|
val shapes = Config.cactus.let { tuftShapeSet(0.8, 0.8, 0.8, 0.2) }
|
||||||
val models = tuftModelSet(shapes, Color.white) { cactusArmSprites[randomI()] }
|
val models = tuftModelSet(shapes, Color.white, -1) { cactusArmSprites[randomI()] }
|
||||||
horizontalDirections.map { side ->
|
horizontalDirections.map { side ->
|
||||||
models.transform { move(0.0625 to DOWN).rotate(Rotation.fromUp[side.ordinal]) }.buildTufts()
|
models.transform { move(0.0625 to DOWN).rotate(Rotation.fromUp[side.ordinal]) }.buildTufts()
|
||||||
}.toTypedArray()
|
}.toTypedArray()
|
||||||
|
|||||||
@@ -125,11 +125,11 @@ class StandardDirtModel(
|
|||||||
)
|
)
|
||||||
val algaeModels by BetterFoliage.modelManager.lazy {
|
val algaeModels by BetterFoliage.modelManager.lazy {
|
||||||
val shapes = Config.algae.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
val shapes = Config.algae.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
||||||
tuftModelSet(shapes, Color.white) { algaeSprites[randomI()] }.buildTufts()
|
tuftModelSet(shapes, Color.white, -1) { algaeSprites[randomI()] }.buildTufts()
|
||||||
}
|
}
|
||||||
val reedModels by BetterFoliage.modelManager.lazy {
|
val reedModels by BetterFoliage.modelManager.lazy {
|
||||||
val shapes = Config.reed.let { tuftShapeSet(2.0, it.heightMin, it.heightMax, it.hOffset) }
|
val shapes = Config.reed.let { tuftShapeSet(2.0, it.heightMin, it.heightMax, it.hOffset) }
|
||||||
tuftModelSet(shapes, Color.white) { reedSprites[randomI()] }.buildTufts()
|
tuftModelSet(shapes, Color.white, -1) { reedSprites[randomI()] }.buildTufts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -24,12 +24,11 @@ import mods.betterfoliage.resource.discovery.ModelBakingContext
|
|||||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
||||||
import mods.betterfoliage.resource.discovery.ParametrizedModelDiscovery
|
import mods.betterfoliage.resource.discovery.ParametrizedModelDiscovery
|
||||||
import mods.betterfoliage.util.Atlas
|
import mods.betterfoliage.util.Atlas
|
||||||
import mods.betterfoliage.util.averageColor
|
import mods.betterfoliage.util.averageHSB
|
||||||
import mods.betterfoliage.util.colorOverride
|
|
||||||
import mods.betterfoliage.util.idxOrNull
|
import mods.betterfoliage.util.idxOrNull
|
||||||
import mods.betterfoliage.util.lazy
|
import mods.betterfoliage.util.lazy
|
||||||
import mods.betterfoliage.util.lazyMap
|
import mods.betterfoliage.util.lazyMap
|
||||||
import mods.betterfoliage.util.logColorOverride
|
import mods.betterfoliage.util.lighten
|
||||||
import mods.betterfoliage.util.randomI
|
import mods.betterfoliage.util.randomI
|
||||||
import net.minecraft.client.renderer.RenderType
|
import net.minecraft.client.renderer.RenderType
|
||||||
import net.minecraft.util.Direction.DOWN
|
import net.minecraft.util.Direction.DOWN
|
||||||
@@ -39,8 +38,10 @@ import java.util.Random
|
|||||||
|
|
||||||
object StandardGrassDiscovery : ParametrizedModelDiscovery() {
|
object StandardGrassDiscovery : ParametrizedModelDiscovery() {
|
||||||
override fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>) {
|
override fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>) {
|
||||||
val textureGrass = params.texture("texture-grass") ?: return
|
val texture = params.location("texture") ?: return
|
||||||
ctx.addReplacement(StandardGrassKey(textureGrass, null))
|
val tint = params.int("tint") ?: -1
|
||||||
|
val color = Atlas.BLOCKS.file(texture).averageHSB.lighten()
|
||||||
|
ctx.addReplacement(StandardGrassKey(texture, tint, color))
|
||||||
BetterFoliage.blockTypes.grass.add(ctx.blockState)
|
BetterFoliage.blockTypes.grass.add(ctx.blockState)
|
||||||
ctx.blockState.block.extendLayers()
|
ctx.blockState.block.extendLayers()
|
||||||
}
|
}
|
||||||
@@ -48,16 +49,11 @@ object StandardGrassDiscovery : ParametrizedModelDiscovery() {
|
|||||||
|
|
||||||
data class StandardGrassKey(
|
data class StandardGrassKey(
|
||||||
val sprite: ResourceLocation,
|
val sprite: ResourceLocation,
|
||||||
val overrideColor: Color?
|
val tintIndex: Int,
|
||||||
|
val avgColor: Color,
|
||||||
) : HalfBakedWrapperKey() {
|
) : HalfBakedWrapperKey() {
|
||||||
val tintIndex: Int get() = if (overrideColor == null) 0 else -1
|
|
||||||
|
|
||||||
override fun bake(ctx: ModelBakingContext, wrapped: SpecialRenderModel): SpecialRenderModel {
|
override fun bake(ctx: ModelBakingContext, wrapped: SpecialRenderModel): SpecialRenderModel {
|
||||||
val grassColor = Atlas.BLOCKS[sprite].averageColor.let { hsb ->
|
return StandardGrassModel(wrapped, this)
|
||||||
logColorOverride(BetterFoliageMod.detailLogger(this), Config.shortGrass.saturationThreshold, hsb)
|
|
||||||
hsb.colorOverride(Config.shortGrass.saturationThreshold)
|
|
||||||
}
|
|
||||||
return StandardGrassModel(wrapped, this.copy(overrideColor = grassColor))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -130,10 +126,10 @@ class StandardGrassModel(
|
|||||||
Config.shortGrass.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
Config.shortGrass.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
||||||
}
|
}
|
||||||
val grassTuftMeshesNormal = BetterFoliage.modelManager.lazyMap { key: StandardGrassKey ->
|
val grassTuftMeshesNormal = BetterFoliage.modelManager.lazyMap { key: StandardGrassKey ->
|
||||||
tuftModelSet(grassTuftShapes, key.overrideColor) { idx -> grassTuftSprites[randomI()] }.buildTufts()
|
tuftModelSet(grassTuftShapes, key.avgColor, key.tintIndex) { idx -> grassTuftSprites[randomI()] }.buildTufts()
|
||||||
}
|
}
|
||||||
val grassTuftMeshesSnowed = BetterFoliage.modelManager.lazyMap { key: StandardGrassKey ->
|
val grassTuftMeshesSnowed = BetterFoliage.modelManager.lazyMap { key: StandardGrassKey ->
|
||||||
tuftModelSet(grassTuftShapes, Color.white) { idx -> grassTuftSprites[randomI()] }.buildTufts()
|
tuftModelSet(grassTuftShapes, Color.white, -1) { idx -> grassTuftSprites[randomI()] }.buildTufts()
|
||||||
}
|
}
|
||||||
val grassFullBlockMeshes = BetterFoliage.modelManager.lazyMap { key: StandardGrassKey ->
|
val grassFullBlockMeshes = BetterFoliage.modelManager.lazyMap { key: StandardGrassKey ->
|
||||||
Array(64) { fullCubeTextured(key.sprite, key.tintIndex) }
|
Array(64) { fullCubeTextured(key.sprite, key.tintIndex) }
|
||||||
|
|||||||
@@ -22,8 +22,6 @@ import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
|||||||
import mods.betterfoliage.resource.discovery.ParametrizedModelDiscovery
|
import mods.betterfoliage.resource.discovery.ParametrizedModelDiscovery
|
||||||
import mods.betterfoliage.resource.generated.GeneratedLeafSprite
|
import mods.betterfoliage.resource.generated.GeneratedLeafSprite
|
||||||
import mods.betterfoliage.util.Atlas
|
import mods.betterfoliage.util.Atlas
|
||||||
import mods.betterfoliage.util.averageColor
|
|
||||||
import mods.betterfoliage.util.colorOverride
|
|
||||||
import mods.betterfoliage.util.lazyMap
|
import mods.betterfoliage.util.lazyMap
|
||||||
import mods.betterfoliage.util.logColorOverride
|
import mods.betterfoliage.util.logColorOverride
|
||||||
import net.minecraft.client.renderer.RenderType
|
import net.minecraft.client.renderer.RenderType
|
||||||
@@ -33,7 +31,7 @@ import org.apache.logging.log4j.Level.INFO
|
|||||||
|
|
||||||
object StandardLeafDiscovery : ParametrizedModelDiscovery() {
|
object StandardLeafDiscovery : ParametrizedModelDiscovery() {
|
||||||
override fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>) {
|
override fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>) {
|
||||||
val leafSprite = params.texture("texture-leaf") ?: return
|
val leafSprite = params.location("texture-leaf") ?: return
|
||||||
val leafType = LeafParticleRegistry.typeMappings.getType(leafSprite) ?: "default"
|
val leafType = LeafParticleRegistry.typeMappings.getType(leafSprite) ?: "default"
|
||||||
val generated = GeneratedLeafSprite(leafSprite, leafType)
|
val generated = GeneratedLeafSprite(leafSprite, leafType)
|
||||||
.register(BetterFoliage.generatedPack)
|
.register(BetterFoliage.generatedPack)
|
||||||
@@ -52,11 +50,7 @@ data class StandardLeafKey(
|
|||||||
val tintIndex: Int get() = if (overrideColor == null) 0 else -1
|
val tintIndex: Int get() = if (overrideColor == null) 0 else -1
|
||||||
|
|
||||||
override fun bake(ctx: ModelBakingContext, wrapped: SpecialRenderModel): SpecialRenderModel {
|
override fun bake(ctx: ModelBakingContext, wrapped: SpecialRenderModel): SpecialRenderModel {
|
||||||
val leafSpriteColor = Atlas.BLOCKS[roundLeafTexture].averageColor.let { hsb ->
|
return StandardLeafModel(wrapped, this)
|
||||||
logColorOverride(BetterFoliageMod.detailLogger(this), Config.leaves.saturationThreshold, hsb)
|
|
||||||
hsb.colorOverride(Config.leaves.saturationThreshold)
|
|
||||||
}
|
|
||||||
return StandardLeafModel(wrapped, this.copy(overrideColor = leafSpriteColor))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,13 +74,13 @@ class StandardLilypadModel(
|
|||||||
}
|
}
|
||||||
val lilypadRootModels by BetterFoliage.modelManager.lazy {
|
val lilypadRootModels by BetterFoliage.modelManager.lazy {
|
||||||
val shapes = tuftShapeSet(1.0, 1.0, 1.0, Config.lilypad.hOffset)
|
val shapes = tuftShapeSet(1.0, 1.0, 1.0, Config.lilypad.hOffset)
|
||||||
tuftModelSet(shapes, Color.white) { lilypadRootSprites[it] }
|
tuftModelSet(shapes, Color.white, -1) { lilypadRootSprites[it] }
|
||||||
.transform { move(2.0 to DOWN) }
|
.transform { move(2.0 to DOWN) }
|
||||||
.buildTufts()
|
.buildTufts()
|
||||||
}
|
}
|
||||||
val lilypadFlowerModels by BetterFoliage.modelManager.lazy {
|
val lilypadFlowerModels by BetterFoliage.modelManager.lazy {
|
||||||
val shapes = tuftShapeSet(0.5, 0.5, 0.5, Config.lilypad.hOffset)
|
val shapes = tuftShapeSet(0.5, 0.5, 0.5, Config.lilypad.hOffset)
|
||||||
tuftModelSet(shapes, Color.white) { lilypadFlowerSprites[it] }
|
tuftModelSet(shapes, Color.white, -1) { lilypadFlowerSprites[it] }
|
||||||
.transform { move(1.0 to DOWN) }
|
.transform { move(1.0 to DOWN) }
|
||||||
.buildTufts()
|
.buildTufts()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,12 +21,11 @@ import mods.betterfoliage.resource.discovery.ModelBakingContext
|
|||||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
||||||
import mods.betterfoliage.resource.discovery.ParametrizedModelDiscovery
|
import mods.betterfoliage.resource.discovery.ParametrizedModelDiscovery
|
||||||
import mods.betterfoliage.util.Atlas
|
import mods.betterfoliage.util.Atlas
|
||||||
import mods.betterfoliage.util.averageColor
|
import mods.betterfoliage.util.averageHSB
|
||||||
import mods.betterfoliage.util.colorOverride
|
|
||||||
import mods.betterfoliage.util.idxOrNull
|
import mods.betterfoliage.util.idxOrNull
|
||||||
import mods.betterfoliage.util.lazy
|
import mods.betterfoliage.util.lazy
|
||||||
import mods.betterfoliage.util.lazyMap
|
import mods.betterfoliage.util.lazyMap
|
||||||
import mods.betterfoliage.util.logColorOverride
|
import mods.betterfoliage.util.lighten
|
||||||
import mods.betterfoliage.util.randomI
|
import mods.betterfoliage.util.randomI
|
||||||
import net.minecraft.client.renderer.RenderType
|
import net.minecraft.client.renderer.RenderType
|
||||||
import net.minecraft.util.Direction
|
import net.minecraft.util.Direction
|
||||||
@@ -35,22 +34,21 @@ import java.util.Random
|
|||||||
|
|
||||||
object StandardMyceliumDiscovery : ParametrizedModelDiscovery() {
|
object StandardMyceliumDiscovery : ParametrizedModelDiscovery() {
|
||||||
override fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>) {
|
override fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>) {
|
||||||
val textureMycelium = params.texture("texture-mycelium") ?: return
|
val texture = params.location("texture") ?: return
|
||||||
ctx.addReplacement(StandardMyceliumKey(textureMycelium, null))
|
val tint = params.int("tint") ?: -1
|
||||||
|
val color = Atlas.BLOCKS.file(texture).averageHSB.lighten(multiplier = 1.5f)
|
||||||
|
ctx.addReplacement(StandardMyceliumKey(texture, tint, color))
|
||||||
ctx.blockState.block.extendLayers()
|
ctx.blockState.block.extendLayers()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class StandardMyceliumKey(
|
data class StandardMyceliumKey(
|
||||||
val sprite: ResourceLocation,
|
val sprite: ResourceLocation,
|
||||||
val overrideColor: Color?
|
val tintIndex: Int,
|
||||||
|
val avgColor: Color,
|
||||||
) : HalfBakedWrapperKey() {
|
) : HalfBakedWrapperKey() {
|
||||||
override fun bake(ctx: ModelBakingContext, wrapped: SpecialRenderModel): SpecialRenderModel {
|
override fun bake(ctx: ModelBakingContext, wrapped: SpecialRenderModel): SpecialRenderModel {
|
||||||
val myceliumColor = Atlas.BLOCKS[sprite].averageColor.let { hsb ->
|
return StandardMyceliumModel(wrapped, this)
|
||||||
logColorOverride(BetterFoliageMod.detailLogger(this), Config.shortGrass.saturationThreshold, hsb)
|
|
||||||
hsb.colorOverride(Config.shortGrass.saturationThreshold)
|
|
||||||
}
|
|
||||||
return StandardMyceliumModel(wrapped, copy(overrideColor = myceliumColor))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,7 +93,7 @@ class StandardMyceliumModel(
|
|||||||
Config.shortGrass.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
Config.shortGrass.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
||||||
}
|
}
|
||||||
val myceliumTuftModels = BetterFoliage.modelManager.lazyMap { key: StandardMyceliumKey ->
|
val myceliumTuftModels = BetterFoliage.modelManager.lazyMap { key: StandardMyceliumKey ->
|
||||||
tuftModelSet(myceliumTuftShapes, key.overrideColor) { idx -> myceliumTuftSprites[randomI()] }.buildTufts()
|
tuftModelSet(myceliumTuftShapes, key.avgColor, key.tintIndex) { idx -> myceliumTuftSprites[randomI()] }.buildTufts()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +78,7 @@ class StandardNetherrackModel(
|
|||||||
}
|
}
|
||||||
val netherrackTuftModels by BetterFoliage.modelManager.lazy {
|
val netherrackTuftModels by BetterFoliage.modelManager.lazy {
|
||||||
val shapes = Config.netherrack.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
val shapes = Config.netherrack.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
||||||
tuftModelSet(shapes, Color.white) { netherrackTuftSprites[randomI()] }
|
tuftModelSet(shapes, Color.white, -1) { netherrackTuftSprites[randomI()] }
|
||||||
.transform { rotate(Rotation.fromUp[DOWN.ordinal]).rotateUV(2) }
|
.transform { rotate(Rotation.fromUp[DOWN.ordinal]).rotateUV(2) }
|
||||||
.buildTufts()
|
.buildTufts()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,8 +36,8 @@ object RoundLogOverlayLayer : ColumnRenderLayer() {
|
|||||||
|
|
||||||
object StandardRoundLogDiscovery : ParametrizedModelDiscovery() {
|
object StandardRoundLogDiscovery : ParametrizedModelDiscovery() {
|
||||||
override fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>) {
|
override fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>) {
|
||||||
val barkSprite = params.texture("texture-side") ?: return
|
val barkSprite = params.location("texture-side") ?: return
|
||||||
val endSprite = params.texture("texture-end") ?: return
|
val endSprite = params.location("texture-end") ?: return
|
||||||
val axis = getAxis(ctx.blockState)
|
val axis = getAxis(ctx.blockState)
|
||||||
|
|
||||||
detailLogger.log(INFO, " axis $axis, material ${ctx.blockState.material}")
|
detailLogger.log(INFO, " axis $axis, material ${ctx.blockState.material}")
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ class StandardSandModel(
|
|||||||
val coralTuftModels by BetterFoliage.modelManager.lazy {
|
val coralTuftModels by BetterFoliage.modelManager.lazy {
|
||||||
val shapes = Config.coral.let { tuftShapeSet(it.size, 1.0, 1.0, it.hOffset) }
|
val shapes = Config.coral.let { tuftShapeSet(it.size, 1.0, 1.0, it.hOffset) }
|
||||||
allDirections.mapArray { face ->
|
allDirections.mapArray { face ->
|
||||||
tuftModelSet(shapes, Color.white) { coralTuftSprites[randomI()] }
|
tuftModelSet(shapes, Color.white, -1) { coralTuftSprites[randomI()] }
|
||||||
.transform { rotate(Rotation.fromUp[face]) }
|
.transform { rotate(Rotation.fromUp[face]) }
|
||||||
.buildTufts()
|
.buildTufts()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ data class ModelDiscoveryContext(
|
|||||||
if (addToStateKeys) BetterFoliage.blockTypes.stateKeys[blockState] = key
|
if (addToStateKeys) BetterFoliage.blockTypes.stateKeys[blockState] = key
|
||||||
logger.log(INFO, "Adding model replacement $modelLocation -> $key")
|
logger.log(INFO, "Adding model replacement $modelLocation -> $key")
|
||||||
}
|
}
|
||||||
|
fun <T: IUnbakedModel> loadHierarchy(model: T) = model.apply {
|
||||||
|
getMaterials(this@ModelDiscoveryContext::getUnbaked, mutableSetOf())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
data class ModelBakingContext(
|
data class ModelBakingContext(
|
||||||
|
|||||||
@@ -13,11 +13,17 @@ import org.apache.logging.log4j.Level
|
|||||||
abstract class ParametrizedModelDiscovery : HasLogger() {
|
abstract class ParametrizedModelDiscovery : HasLogger() {
|
||||||
abstract fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>)
|
abstract fun processModel(ctx: ModelDiscoveryContext, params: Map<String, String>)
|
||||||
|
|
||||||
fun Map<String, String>.texture(key: String): ResourceLocation? {
|
fun Map<String, String>.location(key: String): ResourceLocation? {
|
||||||
val result = get(key)?.let { ResourceLocation(it) }
|
val result = get(key)?.let { ResourceLocation(it) }
|
||||||
if (result == null) detailLogger.log(Level.WARN, "Cannot find texture parameter \"$key\"")
|
if (result == null) detailLogger.log(Level.WARN, "Cannot find texture parameter \"$key\"")
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun Map<String, String>.int(key: String): Int? {
|
||||||
|
val result = get(key)?.toInt()
|
||||||
|
if (result == null) detailLogger.log(Level.WARN, "Cannot find integer parameter \"$key\"")
|
||||||
|
return result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RuleProcessingContext(
|
class RuleProcessingContext(
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ match block.class.extends(classOf("minecraft:oak_leaves")) setParam("type", "lea
|
|||||||
match isParam("type", "leaf")
|
match isParam("type", "leaf")
|
||||||
model.extends("minecraft:block/leaves", "minecraft:block/cube_all")
|
model.extends("minecraft:block/leaves", "minecraft:block/cube_all")
|
||||||
setParam("texture-leaf", model.texture("all"))
|
setParam("texture-leaf", model.texture("all"))
|
||||||
|
setParam("tint-leaf", model.tint("all"))
|
||||||
end
|
end
|
||||||
|
|
||||||
// Podzol
|
// Podzol
|
||||||
@@ -14,7 +15,8 @@ match block.class.extends(classOf("minecraft:grass_block")) setParam("type", "gr
|
|||||||
|
|
||||||
match isParam("type", "grass")
|
match isParam("type", "grass")
|
||||||
model.extends("minecraft:block/grass_block", "minecraft:block/cube_bottom_top")
|
model.extends("minecraft:block/grass_block", "minecraft:block/cube_bottom_top")
|
||||||
setParam("texture-grass", model.texture("top"))
|
setParam("texture", model.texture("top"))
|
||||||
|
setParam("tint", model.tint("top"))
|
||||||
end
|
end
|
||||||
|
|
||||||
// Mycelium & Nylium
|
// Mycelium & Nylium
|
||||||
@@ -22,7 +24,8 @@ match block.name.matches("minecraft:mycelium", "minecraft:crimson_nylium", "mine
|
|||||||
|
|
||||||
match isParam("type", "mycelium")
|
match isParam("type", "mycelium")
|
||||||
model.extends("minecraft:block/cube_bottom_top")
|
model.extends("minecraft:block/cube_bottom_top")
|
||||||
setParam("texture-mycelium", model.texture("top"))
|
setParam("texture", model.texture("top"))
|
||||||
|
setParam("tint", model.tint("top"))
|
||||||
end
|
end
|
||||||
|
|
||||||
// Dirt
|
// Dirt
|
||||||
|
|||||||
Reference in New Issue
Block a user