add support for block variants and multiple wood log bark textures

This commit is contained in:
octarine-noise
2017-08-12 15:59:06 +02:00
parent 25c302ecb6
commit 4761eb266f
11 changed files with 203 additions and 133 deletions

View File

@@ -13,7 +13,6 @@ import net.minecraft.client.renderer.BlockRendererDispatcher
import net.minecraft.client.renderer.VertexBuffer
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.util.BlockRenderLayer
import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumFacing.*
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
@@ -28,14 +27,18 @@ interface IColumnTextureInfo {
@SideOnly(Side.CLIENT)
interface IColumnRegistry {
operator fun get(state: IBlockState): IColumnTextureInfo?
operator fun get(state: IBlockState, rand: Int): IColumnTextureInfo?
}
@SideOnly(Side.CLIENT)
data class StaticColumnInfo(override val axis: Axis?,
val topTexture: TextureAtlasSprite,
val bottomTexture: TextureAtlasSprite,
val sideTexture: TextureAtlasSprite) : IColumnTextureInfo {
val sideTextures: List<TextureAtlasSprite>) : IColumnTextureInfo {
// index offsets for EnumFacings, to make it less likely for neighboring faces to get the same bark texture
val dirToIdx = arrayOf(0, 1, 2, 4, 3, 5)
override val top: QuadIconResolver = { ctx, _, _ ->
OptifineCTM.override(topTexture, blockContext, UP.rotate(ctx.rotation))
}
@@ -43,7 +46,9 @@ data class StaticColumnInfo(override val axis: Axis?,
OptifineCTM.override(bottomTexture, blockContext, DOWN.rotate(ctx.rotation))
}
override val side: QuadIconResolver = { ctx, idx, _ ->
OptifineCTM.override(sideTexture, blockContext, (if ((idx and 1) == 0) SOUTH else EAST).rotate(ctx.rotation))
val worldFace = (if ((idx and 1) == 0) SOUTH else EAST).rotate(ctx.rotation)
val baseTexture = sideTextures[(blockContext.random(1) + dirToIdx[worldFace.ordinal]) % sideTextures.size]
OptifineCTM.override(baseTexture, blockContext, worldFace)
}
}
@@ -141,7 +146,7 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
override fun render(ctx: BlockContext, dispatcher: BlockRendererDispatcher, renderer: VertexBuffer, layer: BlockRenderLayer): Boolean {
if (ctx.isSurroundedBy(surroundPredicate) ) return false
val columnTextures = registry[ctx.blockState(Int3.zero)]
val columnTextures = registry[ctx.blockState(Int3.zero), ctx.random(0)]
if (columnTextures == null) {
Client.logRenderError(ctx.blockState(Int3.zero), ctx.pos)
return renderWorldBlockBase(ctx, dispatcher, renderer, null)
@@ -346,7 +351,7 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
return if (!blockPredicate(state)) {
if (state.isOpaqueCube) SOLID else NONSOLID
} else {
(registry[state]?.axis ?: if (Config.roundLogs.defaultY) Axis.Y else null)?.let {
(registry[state, random(0)]?.axis ?: if (Config.roundLogs.defaultY) Axis.Y else null)?.let {
if (it == axis) PARALLEL else PERPENDICULAR
} ?: SOLID
}

View File

@@ -9,6 +9,7 @@ import mods.octarinecore.client.render.HSB
import mods.octarinecore.common.Double3
import mods.octarinecore.minmax
import mods.octarinecore.random
import mods.octarinecore.semiRandom
import net.minecraft.client.Minecraft
import net.minecraft.client.renderer.VertexBuffer
import net.minecraft.util.EnumFacing.DOWN
@@ -45,7 +46,7 @@ AbstractEntityFX(world, pos.x.toDouble() + 0.5, pos.y.toDouble(), pos.z.toDouble
val state = world.getBlockState(pos)
val blockColor = Minecraft.getMinecraft().blockColors.colorMultiplier(state, world, pos, 0)
val leafInfo = LeafRegistry.get(state, world, pos, DOWN)
val leafInfo = LeafRegistry.get(state, world, pos, DOWN, semiRandom(pos.x, pos.y, pos.z, 0))
if (leafInfo != null) {
particleTexture = leafInfo.particleTextures?.get(rand.nextInt(1024))
calculateParticleColor(leafInfo.averageColor, blockColor)

View File

@@ -4,12 +4,11 @@ import mods.betterfoliage.BetterFoliageMod
import mods.betterfoliage.client.Client
import mods.betterfoliage.client.config.Config
import mods.octarinecore.client.render.*
import mods.octarinecore.client.resource.ModelVariant
import mods.octarinecore.client.resource.TextureListModelProcessor
import mods.octarinecore.client.resource.get
import mods.octarinecore.common.Int3
import mods.octarinecore.common.Rotation
import mods.octarinecore.common.config.ConfigurableBlockMatcher
import mods.octarinecore.common.config.ModelTextureList
import mods.octarinecore.common.config.SimpleBlockMatcher
import mods.octarinecore.common.config.modelTextures
import net.minecraft.block.BlockCactus
@@ -37,8 +36,9 @@ class RenderCactus : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
init { MinecraftForge.EVENT_BUS.register(this) }
override var stateToKey = mutableMapOf<IBlockState, List<String>>()
override var stateToValue = mapOf<IBlockState, IColumnTextureInfo>()
override var variants = mutableMapOf<IBlockState, MutableList<ModelVariant>>()
override var variantToKey = mutableMapOf<ModelVariant, List<String>>()
override var variantToValue = mapOf<ModelVariant, IColumnTextureInfo>()
override val logger = BetterFoliageMod.logDetail
override val logName = "CactusTextures"
@@ -47,14 +47,17 @@ class RenderCactus : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
modelTextures("block/cactus", "top", "bottom", "side")
)
override fun processStitch(state: IBlockState, key: List<String>, atlas: TextureMap): IColumnTextureInfo? {
override fun processStitch(variant: ModelVariant, key: List<String>, atlas: TextureMap): IColumnTextureInfo? {
val topTex = atlas[key[0]] ?: return null
val bottomTex = atlas[key[1]] ?: return null
val sideTex = atlas[key[2]] ?: return null
return StaticColumnInfo(Axis.Y, topTex, bottomTex, sideTex)
return StaticColumnInfo(Axis.Y, topTex, bottomTex, listOf(sideTex))
}
override fun get(state: IBlockState) = stateToValue[state]
override fun get(state: IBlockState, rand: Int): IColumnTextureInfo? {
val variant = getVariant(state, rand) ?: return null
return variantToValue[variant]
}
}
val modelStem = model {
@@ -100,7 +103,7 @@ class RenderCactus : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
// get AO data
modelRenderer.updateShading(Int3.zero, allFaces)
val icons = cactusTextures[ctx.blockState(Int3.zero)] ?: return renderWorldBlockBase(ctx, dispatcher, renderer, null)
val icons = cactusTextures[ctx.blockState(Int3.zero), ctx.random(0)] ?: return renderWorldBlockBase(ctx, dispatcher, renderer, null)
modelRenderer.render(
renderer,

View File

@@ -2,27 +2,21 @@ package mods.betterfoliage.client.render
import mods.betterfoliage.BetterFoliageMod
import mods.betterfoliage.client.config.Config
import mods.betterfoliage.client.texture.GrassRegistry
import mods.betterfoliage.client.texture.IGrassRegistry
import mods.betterfoliage.client.texture.StandardGrassSupport
import mods.octarinecore.client.render.BlockContext
import mods.octarinecore.client.resource.ModelVariant
import mods.octarinecore.client.resource.TextureListModelProcessor
import mods.octarinecore.client.resource.get
import mods.octarinecore.common.Int3
import mods.octarinecore.common.config.ConfigurableBlockMatcher
import mods.octarinecore.common.config.ModelTextureList
import mods.octarinecore.findFirst
import mods.octarinecore.tryDefault
import net.minecraft.block.BlockLog
import net.minecraft.block.state.IBlockState
import net.minecraft.client.renderer.texture.TextureAtlasSprite
import net.minecraft.client.renderer.texture.TextureMap
import net.minecraft.util.EnumFacing.Axis
import net.minecraftforge.common.MinecraftForge
import net.minecraftforge.fml.relauncher.Side
import net.minecraftforge.fml.relauncher.SideOnly
import org.apache.logging.log4j.Level
import org.apache.logging.log4j.Logger
class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
@@ -50,7 +44,7 @@ class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
@SideOnly(Side.CLIENT)
object LogRegistry : IColumnRegistry {
val subRegistries: MutableList<IColumnRegistry> = mutableListOf()
override fun get(state: IBlockState) = subRegistries.findFirst { it[state] }
override fun get(state: IBlockState, rand: Int) = subRegistries.findFirst { it[state, rand] }
}
@SideOnly(Side.CLIENT)
@@ -61,22 +55,27 @@ object StandardLogSupport : TextureListModelProcessor<IColumnTextureInfo>, IColu
MinecraftForge.EVENT_BUS.register(this)
}
override var stateToKey = mutableMapOf<IBlockState, List<String>>()
override var stateToValue = mapOf<IBlockState, IColumnTextureInfo>()
override var variants = mutableMapOf<IBlockState, MutableList<ModelVariant>>()
override var variantToKey = mutableMapOf<ModelVariant, List<String>>()
override var variantToValue = mapOf<ModelVariant, IColumnTextureInfo>()
override val logger = BetterFoliageMod.logDetail
override val logName = "StandardLogSupport"
override val matchClasses: ConfigurableBlockMatcher get() = Config.blocks.logClasses
override val modelTextures: List<ModelTextureList> get() = Config.blocks.logModels.list
override fun processStitch(state: IBlockState, key: List<String>, atlas: TextureMap): IColumnTextureInfo? {
override fun processStitch(variant: ModelVariant, key: List<String>, atlas: TextureMap): IColumnTextureInfo? {
val topTex = atlas[key[0]] ?: return null
val bottomTex = atlas[key[1]] ?: return null
val sideTex = atlas[key[2]] ?: return null
return StaticColumnInfo(getAxis(state), topTex, bottomTex, sideTex)
val sideTexList = key.drop(2).map { atlas[it] }.filterNotNull()
if (sideTexList.isEmpty()) return null
return StaticColumnInfo(getAxis(variant.state), topTex, bottomTex, sideTexList)
}
override fun get(state: IBlockState) = stateToValue[state]
override fun get(state: IBlockState, rand: Int): IColumnTextureInfo? {
val variant = getVariant(state, rand) ?: return null
return variantToValue[variant]
}
fun getAxis(state: IBlockState): Axis? {
val axis = tryDefault(null) { state.getValue(BlockLog.LOG_AXIS).toString() } ?: