[WIP] initial Fabric port
major package refactoring
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.render.lighting.withLighting
|
||||
import mods.betterfoliage.render.lighting.grassTuftLighting
|
||||
import mods.betterfoliage.render.lighting.roundLeafLighting
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.*
|
||||
import mods.betterfoliage.resource.model.*
|
||||
import mods.betterfoliage.util.*
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.CactusBlock
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction.DOWN
|
||||
import net.minecraft.world.ExtendedBlockView
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
|
||||
|
||||
interface CactusKey : BlockRenderKey {
|
||||
val cactusTop: Identifier
|
||||
val cactusBottom: Identifier
|
||||
val cactusSide: Identifier
|
||||
}
|
||||
|
||||
object StandardCactusDiscovery : ConfigurableModelDiscovery() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
override val matchClasses = SimpleBlockMatcher(CactusBlock::class.java)
|
||||
override val modelTextures = listOf(ModelTextureList("block/cactus", "top", "bottom", "side"))
|
||||
|
||||
override fun processModel(state: BlockState, textures: List<String>, atlas: Consumer<Identifier>): BlockRenderKey? {
|
||||
val sprites = textures.map { Identifier(it) }
|
||||
return CactusModel.Key(sprites[0], sprites[1], sprites[2])
|
||||
}
|
||||
}
|
||||
|
||||
class CactusModel(val key: Key, wrapped: BakedModel) : WrappedBakedModel(wrapped), FabricBakedModel {
|
||||
|
||||
val crossModels by cactusCrossModels.delegate(key)
|
||||
val armModels by cactusArmModels.delegate(key)
|
||||
val armLighting = horizontalDirections.map { grassTuftLighting(it) }
|
||||
val crossLighting = roundLeafLighting()
|
||||
|
||||
override fun emitBlockQuads(blockView: ExtendedBlockView, state: BlockState, pos: BlockPos, randomSupplier: Supplier<Random>, context: RenderContext) {
|
||||
(wrapped as FabricBakedModel).emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
if (!BetterFoliage.config.enabled || !BetterFoliage.config.cactus.enabled) return
|
||||
|
||||
val random = randomSupplier.get()
|
||||
val armSide = random.nextInt() and 3
|
||||
|
||||
context.withLighting(armLighting[armSide]) {
|
||||
it.accept(armModels[armSide][random])
|
||||
}
|
||||
context.withLighting(crossLighting) {
|
||||
it.accept(crossModels[random])
|
||||
}
|
||||
}
|
||||
|
||||
data class Key(
|
||||
override val cactusTop: Identifier,
|
||||
override val cactusBottom: Identifier,
|
||||
override val cactusSide: Identifier
|
||||
) : CactusKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = CactusModel(this, meshifyStandard(model, state))
|
||||
}
|
||||
|
||||
companion object {
|
||||
val cactusCrossSprite by SpriteDelegate(Atlas.BLOCKS) {
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_cactus")
|
||||
}
|
||||
val cactusArmSprites by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_cactus_arm_$idx")
|
||||
}
|
||||
val cactusArmModels = LazyMap(BetterFoliage.modelReplacer) { key: CactusKey ->
|
||||
val shapes = BetterFoliage.config.cactus.let { tuftShapeSet(0.8, 0.8, 0.8, 0.2) }
|
||||
val models = tuftModelSet(shapes, Color.white.asInt) { cactusArmSprites[randomI()] }
|
||||
horizontalDirections.map { side ->
|
||||
models.transform { move(0.0625 to DOWN).rotate(Rotation.fromUp[side.ordinal]) }.buildTufts()
|
||||
}.toTypedArray()
|
||||
}
|
||||
val cactusCrossModels = LazyMap(BetterFoliage.modelReplacer) { key: CactusKey ->
|
||||
val models = BetterFoliage.config.cactus.let { config ->
|
||||
crossModelsRaw(64, config.size, 0.0, 0.0)
|
||||
.transform { rotateZ(randomD(-config.sizeVariation, config.sizeVariation)) }
|
||||
}
|
||||
crossModelsTextured(models, Color.white.asInt, true) { cactusCrossSprite }
|
||||
}
|
||||
}
|
||||
}
|
||||
101
src/main/kotlin/mods/betterfoliage/render/block/vanilla/Dirt.kt
Normal file
101
src/main/kotlin/mods/betterfoliage/render/block/vanilla/Dirt.kt
Normal file
@@ -0,0 +1,101 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.chunk.BasicBlockCtx
|
||||
import mods.betterfoliage.render.DIRT_BLOCKS
|
||||
import mods.betterfoliage.render.SALTWATER_BIOMES
|
||||
import mods.betterfoliage.render.lighting.withLighting
|
||||
import mods.betterfoliage.render.lighting.grassTuftLighting
|
||||
import mods.betterfoliage.render.lighting.reedLighting
|
||||
import mods.betterfoliage.render.lighting.renderMasquerade
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.BlockRenderKey
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryBase
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
||||
import mods.betterfoliage.resource.generated.CenteredSprite
|
||||
import mods.betterfoliage.resource.model.*
|
||||
import mods.betterfoliage.util.*
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext
|
||||
import net.minecraft.block.BlockRenderLayer
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.Material
|
||||
import net.minecraft.client.MinecraftClient
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction.UP
|
||||
import net.minecraft.world.ExtendedBlockView
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
|
||||
object DirtKey : BlockRenderKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = DirtModel(meshifyStandard(model, state))
|
||||
}
|
||||
|
||||
object DirtDiscovery : ModelDiscoveryBase() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
|
||||
override fun processModel(ctx: ModelDiscoveryContext, atlas: Consumer<Identifier>) =
|
||||
if (ctx.state.block in DIRT_BLOCKS) DirtKey else null
|
||||
}
|
||||
|
||||
class DirtModel(wrapped: BakedModel) : WrappedBakedModel(wrapped) {
|
||||
|
||||
val algaeLighting = grassTuftLighting(UP)
|
||||
val reedLighting = reedLighting()
|
||||
|
||||
override fun emitBlockQuads(blockView: ExtendedBlockView, state: BlockState, pos: BlockPos, randomSupplier: Supplier<Random>, context: RenderContext) {
|
||||
if (!BetterFoliage.config.enabled) return super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
|
||||
val ctx = BasicBlockCtx(blockView, pos)
|
||||
val stateUp = ctx.offset(UP).state
|
||||
val keyUp = BetterFoliage.modelReplacer[stateUp]
|
||||
|
||||
val isWater = stateUp.material == Material.WATER
|
||||
val isDeepWater = isWater && ctx.offset(Int3(2 to UP)).state.material == Material.WATER
|
||||
val isShallowWater = isWater && ctx.offset(Int3(2 to UP)).state.isAir
|
||||
val isSaltWater = isWater && ctx.biome.category in SALTWATER_BIOMES
|
||||
|
||||
if (BetterFoliage.config.connectedGrass.enabled && keyUp is GrassKey) {
|
||||
val grassBaseModel = (ctx.model(UP) as WrappedBakedModel).wrapped
|
||||
context.renderMasquerade(grassBaseModel, blockView, stateUp, pos, randomSupplier, context)
|
||||
} else {
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
}
|
||||
|
||||
val random = randomSupplier.get()
|
||||
if (BetterFoliage.config.algae.enabled(random) && isDeepWater) {
|
||||
context.withLighting(algaeLighting) {
|
||||
it.accept(algaeModels[random])
|
||||
}
|
||||
} else if (BetterFoliage.config.reed.enabled(random) && isShallowWater && !isSaltWater) {
|
||||
context.withLighting(reedLighting) {
|
||||
it.accept(reedModels[random])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val algaeSprites by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_algae_$idx")
|
||||
}
|
||||
val reedSprites by SpriteSetDelegate(Atlas.BLOCKS,
|
||||
idFunc = { idx -> Identifier(BetterFoliage.MOD_ID, "blocks/better_reed_$idx") },
|
||||
idRegister = { id -> CenteredSprite(id, aspectHeight = 2).register(BetterFoliage.generatedPack) }
|
||||
)
|
||||
val algaeModels by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
val shapes = BetterFoliage.config.algae.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
||||
tuftModelSet(shapes, Color.white.asInt) { algaeSprites[randomI()] }
|
||||
.withOpposites()
|
||||
.build(BlockRenderLayer.CUTOUT_MIPPED, flatLighting = false)
|
||||
|
||||
}
|
||||
val reedModels by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
val shapes = BetterFoliage.config.reed.let { tuftShapeSet(2.0, it.heightMin, it.heightMax, it.hOffset) }
|
||||
tuftModelSet(shapes, Color.white.asInt) { reedSprites[randomI()] }
|
||||
.withOpposites()
|
||||
.build(BlockRenderLayer.CUTOUT_MIPPED, flatLighting = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
121
src/main/kotlin/mods/betterfoliage/render/block/vanilla/Grass.kt
Normal file
121
src/main/kotlin/mods/betterfoliage/render/block/vanilla/Grass.kt
Normal file
@@ -0,0 +1,121 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.chunk.BasicBlockCtx
|
||||
import mods.betterfoliage.render.SNOW_MATERIALS
|
||||
import mods.betterfoliage.render.lighting.withLighting
|
||||
import mods.betterfoliage.render.lighting.grassTuftLighting
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.*
|
||||
import mods.betterfoliage.resource.model.*
|
||||
import mods.betterfoliage.util.*
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext
|
||||
import net.minecraft.block.BlockRenderLayer
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.tag.BlockTags
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction.*
|
||||
import net.minecraft.world.ExtendedBlockView
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
|
||||
interface GrassKey : BlockRenderKey {
|
||||
val grassTopTexture: Identifier
|
||||
|
||||
/**
|
||||
* Color to use for Short Grass rendering instead of the biome color.
|
||||
*
|
||||
* Value is null if the texture is mostly grey (the saturation of its average color is under a configurable limit),
|
||||
* the average color of the texture otherwise.
|
||||
*/
|
||||
val overrideColor: Int?
|
||||
}
|
||||
|
||||
object StandardGrassDiscovery : ConfigurableModelDiscovery() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
override val matchClasses: ConfigurableBlockMatcher get() = BetterFoliage.blockConfig.grassBlocks
|
||||
override val modelTextures: List<ModelTextureList> get() = BetterFoliage.blockConfig.grassModels.modelList
|
||||
|
||||
override fun processModel(state: BlockState, textures: List<String>, atlas: Consumer<Identifier>): BlockRenderKey? {
|
||||
val grassId = Identifier(textures[0])
|
||||
log(" block state $state")
|
||||
log(" texture $grassId")
|
||||
return GrassBlockModel.Key(grassId, getAndLogColorOverride(grassId, Atlas.BLOCKS, BetterFoliage.config.shortGrass.saturationThreshold))
|
||||
}
|
||||
}
|
||||
|
||||
class GrassBlockModel(val key: Key, wrapped: BakedModel) : WrappedBakedModel(wrapped), FabricBakedModel {
|
||||
|
||||
val tuftNormal by grassTuftMeshesNormal.delegate(key)
|
||||
val tuftSnowed by grassTuftMeshesSnowed.delegate(key)
|
||||
val fullBlock by grassFullBlockMeshes.delegate(key)
|
||||
|
||||
val tuftLighting = grassTuftLighting(UP)
|
||||
|
||||
override fun emitBlockQuads(blockView: ExtendedBlockView, state: BlockState, pos: BlockPos, randomSupplier: Supplier<Random>, context: RenderContext) {
|
||||
if (!BetterFoliage.config.enabled) return super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
|
||||
val ctx = BasicBlockCtx(blockView, pos)
|
||||
val stateBelow = ctx.state(DOWN)
|
||||
val stateAbove = ctx.state(UP)
|
||||
|
||||
val isSnowed = stateAbove.material in SNOW_MATERIALS
|
||||
val connected = BetterFoliage.config.connectedGrass.enabled &&
|
||||
(!isSnowed || BetterFoliage.config.connectedGrass.snowEnabled) && (
|
||||
BlockTags.DIRT_LIKE.contains(stateBelow.block) ||
|
||||
BetterFoliage.modelReplacer.getTyped<GrassKey>(stateBelow) != null
|
||||
)
|
||||
|
||||
val random = randomSupplier.get()
|
||||
if (connected) {
|
||||
context.meshConsumer().accept(if (isSnowed) snowFullBlockMeshes[random] else fullBlock[random])
|
||||
} else {
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
}
|
||||
|
||||
if (BetterFoliage.config.shortGrass.enabled(random) && !ctx.isNeighborSolid(UP)) {
|
||||
context.withLighting(tuftLighting) {
|
||||
it.accept(if (isSnowed) tuftSnowed[random] else tuftNormal[random])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
data class Key(
|
||||
override val grassTopTexture: Identifier,
|
||||
override val overrideColor: Int?
|
||||
) : GrassKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = GrassBlockModel(this, meshifyStandard(model, state))
|
||||
}
|
||||
|
||||
companion object {
|
||||
val grassTuftSpritesNormal by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_grass_long_$idx")
|
||||
}
|
||||
val grassTuftSpritesSnowed by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_grass_long_$idx")
|
||||
}
|
||||
val grassTuftShapes = LazyMap(BetterFoliage.modelReplacer) { key: GrassKey ->
|
||||
BetterFoliage.config.shortGrass.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
||||
}
|
||||
val grassTuftMeshesNormal = LazyMap(BetterFoliage.modelReplacer) { key: GrassKey ->
|
||||
tuftModelSet(grassTuftShapes[key], key.overrideColor) { idx -> grassTuftSpritesNormal[randomI()] }
|
||||
.withOpposites()
|
||||
.build(BlockRenderLayer.CUTOUT_MIPPED, flatLighting = false)
|
||||
}
|
||||
val grassTuftMeshesSnowed = LazyMap(BetterFoliage.modelReplacer) { key: GrassKey ->
|
||||
tuftModelSet(grassTuftShapes[key], Color.white.asInt) { idx -> grassTuftSpritesSnowed[randomI()] }
|
||||
.withOpposites()
|
||||
.build(BlockRenderLayer.CUTOUT_MIPPED, flatLighting = false)
|
||||
}
|
||||
val grassFullBlockMeshes = LazyMap(BetterFoliage.modelReplacer) { key: GrassKey ->
|
||||
Array(64) { fullCubeTextured(key.grassTopTexture, key.overrideColor) }
|
||||
}
|
||||
val snowFullBlockMeshes by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
Array(64) { fullCubeTextured(Identifier("block/snow"), Color.white.asInt) }
|
||||
}
|
||||
}
|
||||
}
|
||||
116
src/main/kotlin/mods/betterfoliage/render/block/vanilla/Leaf.kt
Normal file
116
src/main/kotlin/mods/betterfoliage/render/block/vanilla/Leaf.kt
Normal file
@@ -0,0 +1,116 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.chunk.BasicBlockCtx
|
||||
import mods.betterfoliage.render.SNOW_MATERIALS
|
||||
import mods.betterfoliage.render.lighting.withLighting
|
||||
import mods.betterfoliage.render.lighting.roundLeafLighting
|
||||
import mods.betterfoliage.render.particle.LeafParticleRegistry
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.*
|
||||
import mods.betterfoliage.resource.generated.GeneratedLeafSprite
|
||||
import mods.betterfoliage.resource.model.*
|
||||
import mods.betterfoliage.util.*
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext
|
||||
import net.minecraft.block.BlockRenderLayer.CUTOUT_MIPPED
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction.*
|
||||
import net.minecraft.world.ExtendedBlockView
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
|
||||
interface LeafKey : BlockRenderKey {
|
||||
val roundLeafTexture: Identifier
|
||||
|
||||
/** Type of the leaf block (configurable by user). */
|
||||
val leafType: String
|
||||
|
||||
/** Average color of the round leaf texture. */
|
||||
val overrideColor: Int?
|
||||
}
|
||||
|
||||
object StandardLeafDiscovery : ConfigurableModelDiscovery() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
override val matchClasses: ConfigurableBlockMatcher get() = BetterFoliage.blockConfig.leafBlocks
|
||||
override val modelTextures: List<ModelTextureList> get() = BetterFoliage.blockConfig.leafModels.modelList
|
||||
|
||||
override fun processModel(state: BlockState, textures: List<String>, atlas: Consumer<Identifier>) =
|
||||
defaultRegisterLeaf(Identifier(textures[0]), atlas)
|
||||
|
||||
}
|
||||
|
||||
fun HasLogger.defaultRegisterLeaf(sprite: Identifier, atlas: Consumer<Identifier>): BlockRenderKey? {
|
||||
val leafType = LeafParticleRegistry.typeMappings.getType(sprite) ?: "default"
|
||||
val leafId = GeneratedLeafSprite(sprite, leafType).register(BetterFoliage.generatedPack)
|
||||
atlas.accept(leafId)
|
||||
|
||||
log(" leaf texture $sprite")
|
||||
log(" particle $leafType")
|
||||
|
||||
return NormalLeavesModel.Key(
|
||||
leafId, leafType,
|
||||
getAndLogColorOverride(leafId, Atlas.BLOCKS, BetterFoliage.config.shortGrass.saturationThreshold)
|
||||
)
|
||||
}
|
||||
|
||||
fun HasLogger.getAndLogColorOverride(sprite: Identifier, atlas: Atlas, threshold: Double): Int? {
|
||||
val hsb = resourceManager.averageImageColorHSB(sprite, atlas)
|
||||
return if (hsb.saturation >= threshold) {
|
||||
log(" brightness ${hsb.brightness}")
|
||||
log(" saturation ${hsb.saturation} >= ${threshold}, using texture color")
|
||||
hsb.copy(brightness = 0.9f.coerceAtMost(hsb.brightness * 2.0f)).asColor
|
||||
} else {
|
||||
log(" saturation ${hsb.saturation} < ${threshold}, using block color")
|
||||
null
|
||||
}
|
||||
}
|
||||
|
||||
class NormalLeavesModel(val key: Key, wrapped: BakedModel) : WrappedBakedModel(wrapped), FabricBakedModel {
|
||||
|
||||
val leafNormal by leafModelsNormal.delegate(key)
|
||||
val leafSnowed by leafModelsSnowed.delegate(key)
|
||||
val leafLighting = roundLeafLighting()
|
||||
|
||||
override fun emitBlockQuads(blockView: ExtendedBlockView, state: BlockState, pos: BlockPos, randomSupplier: Supplier<Random>, context: RenderContext) {
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
if (!BetterFoliage.config.enabled || !BetterFoliage.config.leaves.enabled) return
|
||||
|
||||
val ctx = BasicBlockCtx(blockView, pos)
|
||||
val stateAbove = ctx.state(UP)
|
||||
val isSnowed = stateAbove.material in SNOW_MATERIALS
|
||||
|
||||
val random = randomSupplier.get()
|
||||
context.withLighting(leafLighting) {
|
||||
it.accept(leafNormal[random])
|
||||
if (isSnowed) it.accept(leafSnowed[random])
|
||||
}
|
||||
}
|
||||
|
||||
data class Key(
|
||||
override val roundLeafTexture: Identifier,
|
||||
override val leafType: String,
|
||||
override val overrideColor: Int?
|
||||
) : LeafKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = NormalLeavesModel(this, meshifyStandard(model, state, renderLayerOverride = CUTOUT_MIPPED))
|
||||
}
|
||||
|
||||
companion object {
|
||||
val leafSpritesSnowed by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_leaves_snowed_$idx")
|
||||
}
|
||||
val leafModelsBase = LazyMap(BetterFoliage.modelReplacer) { key: LeafKey ->
|
||||
BetterFoliage.config.leaves.let { crossModelsRaw(64, it.size, it.hOffset, it.vOffset) }
|
||||
}
|
||||
val leafModelsNormal = LazyMap(BetterFoliage.modelReplacer) { key: LeafKey ->
|
||||
crossModelsTextured(leafModelsBase[key], key.overrideColor, true) { Atlas.BLOCKS.atlas[key.roundLeafTexture]!! }
|
||||
}
|
||||
val leafModelsSnowed = LazyMap(BetterFoliage.modelReplacer) { key: LeafKey ->
|
||||
crossModelsTextured(leafModelsBase[key], Color.white.asInt, false) { leafSpritesSnowed[it] }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.BlockRenderKey
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryBase
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
||||
import mods.betterfoliage.resource.discovery.RenderKeyFactory
|
||||
import mods.betterfoliage.resource.model.*
|
||||
import mods.betterfoliage.util.LazyInvalidatable
|
||||
import mods.betterfoliage.util.get
|
||||
import mods.betterfoliage.util.semiRandom
|
||||
import net.fabricmc.fabric.api.renderer.v1.model.FabricBakedModel
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.Blocks
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction.DOWN
|
||||
import net.minecraft.world.ExtendedBlockView
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
|
||||
object LilypadKey : BlockRenderKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = LilypadModel(meshifyStandard(model, state))
|
||||
}
|
||||
|
||||
object LilyPadDiscovery : ModelDiscoveryBase() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
override fun processModel(ctx: ModelDiscoveryContext, atlas: Consumer<Identifier>) =
|
||||
if (ctx.state.block == Blocks.LILY_PAD) LilypadKey else null
|
||||
}
|
||||
|
||||
class LilypadModel(wrapped: BakedModel) : WrappedBakedModel(wrapped) {
|
||||
override fun emitBlockQuads(blockView: ExtendedBlockView, state: BlockState, pos: BlockPos, randomSupplier: Supplier<Random>, context: RenderContext) {
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
if (!BetterFoliage.config.enabled || !BetterFoliage.config.lilypad.enabled) return
|
||||
|
||||
val random = randomSupplier.get()
|
||||
context.meshConsumer().accept(lilypadRootModels[random])
|
||||
if (random.nextInt(64) < BetterFoliage.config.lilypad.population) {
|
||||
context.meshConsumer().accept(lilypadFlowerModels[random])
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val lilypadRootSprites by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_lilypad_roots_$idx")
|
||||
}
|
||||
val lilypadFlowerSprites by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_lilypad_flower_$idx")
|
||||
}
|
||||
val lilypadRootModels by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
val shapes = tuftShapeSet(1.0, 1.0, 1.0, BetterFoliage.config.lilypad.hOffset)
|
||||
tuftModelSet(shapes, Color.white.asInt) { lilypadRootSprites[it] }
|
||||
.transform { move(2.0 to DOWN) }
|
||||
.buildTufts()
|
||||
}
|
||||
val lilypadFlowerModels by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
val shapes = tuftShapeSet(0.5, 0.5, 0.5, BetterFoliage.config.lilypad.hOffset)
|
||||
tuftModelSet(shapes, Color.white.asInt) { lilypadFlowerSprites[it] }
|
||||
.transform { move(1.0 to DOWN) }
|
||||
.buildTufts()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,63 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.render.lighting.withLighting
|
||||
import mods.betterfoliage.render.lighting.grassTuftLighting
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.BlockRenderKey
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryBase
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
||||
import mods.betterfoliage.resource.discovery.RenderKeyFactory
|
||||
import mods.betterfoliage.resource.model.*
|
||||
import mods.betterfoliage.util.*
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.Blocks
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction.UP
|
||||
import net.minecraft.world.ExtendedBlockView
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
|
||||
object MyceliumKey : BlockRenderKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = MyceliumModel(meshifyStandard(model, state))
|
||||
}
|
||||
|
||||
object MyceliumDiscovery : ModelDiscoveryBase() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
val myceliumBlocks = listOf(Blocks.MYCELIUM)
|
||||
override fun processModel(ctx: ModelDiscoveryContext, atlas: Consumer<Identifier>) =
|
||||
if (ctx.state.block in myceliumBlocks) MyceliumKey else null
|
||||
}
|
||||
|
||||
class MyceliumModel(wrapped: BakedModel) : WrappedBakedModel(wrapped) {
|
||||
|
||||
val tuftLighting = grassTuftLighting(UP)
|
||||
|
||||
override fun emitBlockQuads(blockView: ExtendedBlockView, state: BlockState, pos: BlockPos, randomSupplier: Supplier<Random>, context: RenderContext) {
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
|
||||
val random = randomSupplier.get()
|
||||
if (BetterFoliage.config.enabled &&
|
||||
BetterFoliage.config.shortGrass.let { it.myceliumEnabled && random.nextInt(64) < it.population } &&
|
||||
blockView.getBlockState(pos + UP.offset).isAir
|
||||
) {
|
||||
context.withLighting(tuftLighting) {
|
||||
it.accept(myceliumTuftModels[random])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val myceliumTuftSprites by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_mycel_$idx")
|
||||
}
|
||||
val myceliumTuftModels by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
val shapes = BetterFoliage.config.shortGrass.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
||||
tuftModelSet(shapes, Color.white.asInt) { idx -> myceliumTuftSprites[randomI()] }.buildTufts()
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.render.lighting.withLighting
|
||||
import mods.betterfoliage.render.lighting.grassTuftLighting
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.BlockRenderKey
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryBase
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
||||
import mods.betterfoliage.resource.discovery.RenderKeyFactory
|
||||
import mods.betterfoliage.resource.model.*
|
||||
import mods.betterfoliage.util.*
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext
|
||||
import net.minecraft.block.BlockRenderLayer
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.Blocks
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction.DOWN
|
||||
import net.minecraft.world.ExtendedBlockView
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
|
||||
object NetherrackKey : BlockRenderKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = NetherrackModel(meshifyStandard(model, state))
|
||||
}
|
||||
|
||||
object NetherrackDiscovery : ModelDiscoveryBase() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
val netherrackBlocks = listOf(Blocks.NETHERRACK)
|
||||
override fun processModel(ctx: ModelDiscoveryContext, atlas: Consumer<Identifier>) =
|
||||
if (ctx.state.block in netherrackBlocks) NetherrackKey else null
|
||||
}
|
||||
|
||||
class NetherrackModel(wrapped: BakedModel) : WrappedBakedModel(wrapped) {
|
||||
|
||||
val tuftLighting = grassTuftLighting(DOWN)
|
||||
|
||||
override fun emitBlockQuads(blockView: ExtendedBlockView, state: BlockState, pos: BlockPos, randomSupplier: Supplier<Random>, context: RenderContext) {
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
if (BetterFoliage.config.enabled &&
|
||||
BetterFoliage.config.netherrack.enabled &&
|
||||
blockView.getBlockState(pos + DOWN.offset).isAir
|
||||
) {
|
||||
val random = randomSupplier.get()
|
||||
context.withLighting(tuftLighting) {
|
||||
it.accept(netherrackTuftModels[random])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val netherrackTuftSprites by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_netherrack_$idx")
|
||||
}
|
||||
val netherrackTuftModels by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
val shapes = BetterFoliage.config.netherrack.let { tuftShapeSet(it.size, it.heightMin, it.heightMax, it.hOffset) }
|
||||
tuftModelSet(shapes, Color.white.asInt) { netherrackTuftSprites[randomI()] }
|
||||
.transform { rotate(Rotation.fromUp[DOWN.ordinal]).rotateUV(2) }
|
||||
.withOpposites()
|
||||
.build(BlockRenderLayer.CUTOUT_MIPPED, flatLighting = false)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.render.column.*
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.*
|
||||
import mods.betterfoliage.resource.model.meshifyStandard
|
||||
import mods.betterfoliage.util.LazyMap
|
||||
import mods.betterfoliage.util.get
|
||||
import mods.betterfoliage.util.tryDefault
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.LogBlock
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.Direction.Axis
|
||||
import java.util.function.Consumer
|
||||
|
||||
object RoundLogOverlayLayer : ColumnRenderLayer() {
|
||||
override fun getColumnKey(state: BlockState) = BetterFoliage.modelReplacer.getTyped<ColumnBlockKey>(state)
|
||||
override val connectSolids: Boolean get() = BetterFoliage.config.roundLogs.connectSolids
|
||||
override val lenientConnect: Boolean get() = BetterFoliage.config.roundLogs.lenientConnect
|
||||
override val defaultToY: Boolean get() = BetterFoliage.config.roundLogs.defaultY
|
||||
}
|
||||
|
||||
object StandardLogDiscovery : ConfigurableModelDiscovery() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
override val matchClasses: ConfigurableBlockMatcher get() = BetterFoliage.blockConfig.logBlocks
|
||||
override val modelTextures: List<ModelTextureList> get() = BetterFoliage.blockConfig.logModels.modelList
|
||||
|
||||
override fun processModel(state: BlockState, textures: List<String>, atlas: Consumer<Identifier>): BlockRenderKey? {
|
||||
val axis = getAxis(state)
|
||||
log(" axis $axis")
|
||||
return RoundLogModel.Key(axis, Identifier(textures[0]), Identifier(textures[1]))
|
||||
}
|
||||
|
||||
fun getAxis(state: BlockState): Axis? {
|
||||
val axis = tryDefault(null) { state.get(LogBlock.AXIS).toString() } ?:
|
||||
state.entries.entries.find { it.key.getName().toLowerCase() == "axis" }?.value?.toString()
|
||||
return when (axis) {
|
||||
"x" -> Axis.X
|
||||
"y" -> Axis.Y
|
||||
"z" -> Axis.Z
|
||||
else -> null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
interface RoundLogKey : ColumnBlockKey, BlockRenderKey {
|
||||
val barkSprite: Identifier
|
||||
val endSprite: Identifier
|
||||
}
|
||||
|
||||
class RoundLogModel(val key: Key, wrapped: BakedModel) : ColumnModelBase(wrapped) {
|
||||
override val enabled: Boolean get() = BetterFoliage.config.enabled && BetterFoliage.config.roundLogs.enabled
|
||||
override val overlayLayer: ColumnRenderLayer get() = RoundLogOverlayLayer
|
||||
override val connectPerpendicular: Boolean get() = BetterFoliage.config.roundLogs.connectPerpendicular
|
||||
|
||||
val modelSet by modelSets.delegate(key)
|
||||
override fun getMeshSet(axis: Axis, quadrant: Int) = modelSet
|
||||
|
||||
data class Key(
|
||||
override val axis: Axis?,
|
||||
override val barkSprite: Identifier,
|
||||
override val endSprite: Identifier
|
||||
) : RoundLogKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = RoundLogModel(this, meshifyStandard(model, state))
|
||||
}
|
||||
|
||||
companion object {
|
||||
val modelSets = LazyMap(BetterFoliage.modelReplacer) { key: Key ->
|
||||
val barkSprite = Atlas.BLOCKS.atlas[key.barkSprite]!!
|
||||
val endSprite = Atlas.BLOCKS.atlas[key.endSprite]!!
|
||||
BetterFoliage.config.roundLogs.let { config ->
|
||||
ColumnMeshSet(
|
||||
config.radiusSmall, config.radiusLarge, config.zProtection,
|
||||
key.axis ?: Axis.Y,
|
||||
barkSprite, barkSprite,
|
||||
endSprite, endSprite
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
package mods.betterfoliage.render.block.vanilla
|
||||
|
||||
import mods.betterfoliage.BetterFoliage
|
||||
import mods.betterfoliage.chunk.CachedBlockCtx
|
||||
import mods.betterfoliage.render.SALTWATER_BIOMES
|
||||
import mods.betterfoliage.render.SAND_BLOCKS
|
||||
import mods.betterfoliage.render.lighting.withLighting
|
||||
import mods.betterfoliage.render.lighting.grassTuftLighting
|
||||
import mods.betterfoliage.util.Atlas
|
||||
import mods.betterfoliage.resource.discovery.BlockRenderKey
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryBase
|
||||
import mods.betterfoliage.resource.discovery.ModelDiscoveryContext
|
||||
import mods.betterfoliage.resource.model.*
|
||||
import mods.betterfoliage.util.*
|
||||
import net.fabricmc.fabric.api.renderer.v1.render.RenderContext
|
||||
import net.minecraft.block.BlockRenderLayer.CUTOUT_MIPPED
|
||||
import net.minecraft.block.BlockState
|
||||
import net.minecraft.block.Material
|
||||
import net.minecraft.client.render.model.BakedModel
|
||||
import net.minecraft.util.Identifier
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.util.math.Direction.UP
|
||||
import net.minecraft.world.ExtendedBlockView
|
||||
import java.util.*
|
||||
import java.util.function.Consumer
|
||||
import java.util.function.Supplier
|
||||
|
||||
object SandKey : BlockRenderKey {
|
||||
override fun replace(model: BakedModel, state: BlockState) = SandModel(meshifyStandard(model, state))
|
||||
}
|
||||
|
||||
object SandDiscovery : ModelDiscoveryBase() {
|
||||
override val logger = BetterFoliage.logDetail
|
||||
|
||||
override fun processModel(ctx: ModelDiscoveryContext, atlas: Consumer<Identifier>) =
|
||||
if (ctx.state.block in SAND_BLOCKS) SandKey else null
|
||||
}
|
||||
|
||||
class SandModel(wrapped: BakedModel) : WrappedBakedModel(wrapped) {
|
||||
|
||||
val coralLighting = allDirections.map { grassTuftLighting(it) }.toTypedArray()
|
||||
|
||||
override fun emitBlockQuads(blockView: ExtendedBlockView, state: BlockState, pos: BlockPos, randomSupplier: Supplier<Random>, context: RenderContext) {
|
||||
super.emitBlockQuads(blockView, state, pos, randomSupplier, context)
|
||||
|
||||
val ctx = CachedBlockCtx(blockView, pos)
|
||||
|
||||
val random = randomSupplier.get()
|
||||
if (!BetterFoliage.config.enabled || !BetterFoliage.config.coral.enabled(random)) return
|
||||
if (ctx.biome.category !in SALTWATER_BIOMES) return
|
||||
|
||||
allDirections.filter { random.nextInt(64) < BetterFoliage.config.coral.chance }.forEach { face ->
|
||||
val isWater = ctx.state(face).material == Material.WATER
|
||||
val isDeepWater = isWater && ctx.offset(face).state(UP).material == Material.WATER
|
||||
if (isDeepWater) context.withLighting(coralLighting[face]) {
|
||||
it.accept(coralCrustModels[face][random])
|
||||
it.accept(coralTuftModels[face][random])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
// val sandModel by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
// Array(64) { fullCubeTextured(Identifier("block/sand"), Color.white.asInt) }
|
||||
// }
|
||||
|
||||
val coralTuftSprites by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_coral_$idx")
|
||||
}
|
||||
val coralCrustSprites by SpriteSetDelegate(Atlas.BLOCKS) { idx ->
|
||||
Identifier(BetterFoliage.MOD_ID, "blocks/better_crust_$idx")
|
||||
}
|
||||
val coralTuftModels by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
val shapes = BetterFoliage.config.coral.let { tuftShapeSet(it.size, 1.0, 1.0, it.hOffset) }
|
||||
allDirections.map { face ->
|
||||
tuftModelSet(shapes, Color.white.asInt) { coralTuftSprites[randomI()] }
|
||||
.transform { rotate(Rotation.fromUp[face]) }
|
||||
.withOpposites()
|
||||
.build(CUTOUT_MIPPED)
|
||||
}.toTypedArray()
|
||||
}
|
||||
val coralCrustModels by LazyInvalidatable(BetterFoliage.modelReplacer) {
|
||||
allDirections.map { face ->
|
||||
Array(64) { idx ->
|
||||
listOf(horizontalRectangle(x1 = -0.5, x2 = 0.5, z1 = -0.5, z2 = 0.5, y = 0.0)
|
||||
.scale(BetterFoliage.config.coral.crustSize)
|
||||
.move(0.5 + randomD(0.01, BetterFoliage.config.coral.vOffset) to UP)
|
||||
.rotate(Rotation.fromUp[face])
|
||||
.mirrorUV(randomB(), randomB()).rotateUV(randomI(max = 4))
|
||||
.sprite(coralCrustSprites[idx]).colorAndIndex(null)
|
||||
).build(CUTOUT_MIPPED)
|
||||
}
|
||||
}.toTypedArray()
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user