move log block axis into the info object
This commit is contained in:
@@ -3,10 +3,7 @@ package mods.betterfoliage.client.integration
|
|||||||
import mods.betterfoliage.BetterFoliageMod
|
import mods.betterfoliage.BetterFoliageMod
|
||||||
import mods.betterfoliage.client.Client
|
import mods.betterfoliage.client.Client
|
||||||
import mods.betterfoliage.client.config.Config
|
import mods.betterfoliage.client.config.Config
|
||||||
import mods.betterfoliage.client.render.IColumnRegistry
|
import mods.betterfoliage.client.render.*
|
||||||
import mods.betterfoliage.client.render.IColumnTextureResolver
|
|
||||||
import mods.betterfoliage.client.render.LogRegistry
|
|
||||||
import mods.betterfoliage.client.render.StaticColumnInfo
|
|
||||||
import mods.betterfoliage.client.texture.ILeafRegistry
|
import mods.betterfoliage.client.texture.ILeafRegistry
|
||||||
import mods.betterfoliage.client.texture.LeafInfo
|
import mods.betterfoliage.client.texture.LeafInfo
|
||||||
import mods.betterfoliage.client.texture.LeafRegistry
|
import mods.betterfoliage.client.texture.LeafRegistry
|
||||||
@@ -126,10 +123,10 @@ object ForestryLeavesSupport : ILeafRegistry {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
object ForestryLogSupport : ModelProcessor<List<String>, IColumnTextureResolver>, IColumnRegistry {
|
object ForestryLogSupport : ModelProcessor<List<String>, IColumnTextureInfo>, IColumnRegistry {
|
||||||
|
|
||||||
override var stateToKey = mutableMapOf<IBlockState, List<String>>()
|
override var stateToKey = mutableMapOf<IBlockState, List<String>>()
|
||||||
override var stateToValue = mapOf<IBlockState, IColumnTextureResolver>()
|
override var stateToValue = mapOf<IBlockState, IColumnTextureInfo>()
|
||||||
|
|
||||||
override val logger = BetterFoliageMod.logDetail
|
override val logger = BetterFoliageMod.logDetail
|
||||||
|
|
||||||
@@ -155,10 +152,10 @@ object ForestryLogSupport : ModelProcessor<List<String>, IColumnTextureResolver>
|
|||||||
return if (bark != null && heart != null) listOf(heart, bark) else null
|
return if (bark != null && heart != null) listOf(heart, bark) else null
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun processStitch(state: IBlockState, key: List<String>, atlas: TextureMap): IColumnTextureResolver? {
|
override fun processStitch(state: IBlockState, key: List<String>, atlas: TextureMap): IColumnTextureInfo? {
|
||||||
val heart = atlas[key[0]] ?: return null
|
val heart = atlas[key[0]] ?: return null
|
||||||
val bark = atlas[key[1]] ?: return null
|
val bark = atlas[key[1]] ?: return null
|
||||||
return StaticColumnInfo(heart, heart, bark)
|
return StaticColumnInfo(StandardLogSupport.getAxis(state), heart, heart, bark)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(state: IBlockState) = stateToValue[state]
|
override fun get(state: IBlockState) = stateToValue[state]
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
package mods.betterfoliage.client.render
|
package mods.betterfoliage.client.render
|
||||||
|
|
||||||
|
import mods.betterfoliage.client.config.Config
|
||||||
import mods.betterfoliage.client.integration.OptifineCTM
|
import mods.betterfoliage.client.integration.OptifineCTM
|
||||||
import mods.betterfoliage.client.integration.ShadersModIntegration
|
import mods.betterfoliage.client.integration.ShadersModIntegration
|
||||||
import mods.betterfoliage.client.render.AbstractRenderColumn.BlockType.*
|
import mods.betterfoliage.client.render.AbstractRenderColumn.BlockType.*
|
||||||
@@ -14,19 +15,21 @@ import net.minecraft.util.BlockRenderLayer
|
|||||||
import net.minecraft.util.EnumFacing
|
import net.minecraft.util.EnumFacing
|
||||||
import net.minecraft.util.EnumFacing.*
|
import net.minecraft.util.EnumFacing.*
|
||||||
|
|
||||||
interface IColumnTextureResolver {
|
interface IColumnTextureInfo {
|
||||||
|
val axis: Axis?
|
||||||
val top: (ShadingContext, Int, Quad)->TextureAtlasSprite?
|
val top: (ShadingContext, Int, Quad)->TextureAtlasSprite?
|
||||||
val bottom: (ShadingContext, Int, Quad)->TextureAtlasSprite?
|
val bottom: (ShadingContext, Int, Quad)->TextureAtlasSprite?
|
||||||
val side: (ShadingContext, Int, Quad)->TextureAtlasSprite?
|
val side: (ShadingContext, Int, Quad)->TextureAtlasSprite?
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IColumnRegistry {
|
interface IColumnRegistry {
|
||||||
operator fun get(state: IBlockState): IColumnTextureResolver?
|
operator fun get(state: IBlockState): IColumnTextureInfo?
|
||||||
}
|
}
|
||||||
|
|
||||||
data class StaticColumnInfo(val topTexture: TextureAtlasSprite,
|
data class StaticColumnInfo(override val axis: Axis?,
|
||||||
|
val topTexture: TextureAtlasSprite,
|
||||||
val bottomTexture: TextureAtlasSprite,
|
val bottomTexture: TextureAtlasSprite,
|
||||||
val sideTexture: TextureAtlasSprite) : IColumnTextureResolver {
|
val sideTexture: TextureAtlasSprite) : IColumnTextureInfo {
|
||||||
override val top = { ctx: ShadingContext, idx: Int, quad: Quad ->
|
override val top = { ctx: ShadingContext, idx: Int, quad: Quad ->
|
||||||
OptifineCTM.override(topTexture, blockContext, UP.rotate(ctx.rotation))
|
OptifineCTM.override(topTexture, blockContext, UP.rotate(ctx.rotation))
|
||||||
}
|
}
|
||||||
@@ -123,7 +126,6 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
|
|||||||
inline fun continous(q1: QuadrantType, q2: QuadrantType) =
|
inline fun continous(q1: QuadrantType, q2: QuadrantType) =
|
||||||
q1 == q2 || ((q1 == SQUARE || q1 == INVISIBLE) && (q2 == SQUARE || q2 == INVISIBLE))
|
q1 == q2 || ((q1 == SQUARE || q1 == INVISIBLE) && (q2 == SQUARE || q2 == INVISIBLE))
|
||||||
|
|
||||||
abstract val axisFunc: (IBlockState)->EnumFacing.Axis?
|
|
||||||
abstract val blockPredicate: (IBlockState)->Boolean
|
abstract val blockPredicate: (IBlockState)->Boolean
|
||||||
|
|
||||||
abstract val registry: IColumnRegistry
|
abstract val registry: IColumnRegistry
|
||||||
@@ -138,7 +140,8 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
|
|||||||
modelRenderer.updateShading(Int3.zero, allFaces)
|
modelRenderer.updateShading(Int3.zero, allFaces)
|
||||||
|
|
||||||
// check log neighborhood
|
// check log neighborhood
|
||||||
val logAxis = ctx.blockAxis ?: return renderWorldBlockBase(ctx, dispatcher, renderer, null)
|
// if log axis is not defined and "Default to vertical" config option is not set, render normally
|
||||||
|
val logAxis = columnTextures.axis ?: if (Config.roundLogs.defaultY) Axis.Y else return renderWorldBlockBase(ctx, dispatcher, renderer, null)
|
||||||
val baseRotation = rotationFromUp[(logAxis to AxisDirection.POSITIVE).face.ordinal]
|
val baseRotation = rotationFromUp[(logAxis to AxisDirection.POSITIVE).face.ordinal]
|
||||||
|
|
||||||
val upType = ctx.blockType(baseRotation, logAxis, Int3(0, 1, 0))
|
val upType = ctx.blockType(baseRotation, logAxis, Int3(0, 1, 0))
|
||||||
@@ -328,9 +331,6 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
|
|||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get the axis of the block */
|
|
||||||
val BlockContext.blockAxis: Axis? get() = axisFunc(blockState(Int3.zero))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the type of the block at the given offset in a rotated reference frame.
|
* Get the type of the block at the given offset in a rotated reference frame.
|
||||||
*/
|
*/
|
||||||
@@ -340,7 +340,9 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
|
|||||||
return if (!blockPredicate(state)) {
|
return if (!blockPredicate(state)) {
|
||||||
if (state.isOpaqueCube) SOLID else NONSOLID
|
if (state.isOpaqueCube) SOLID else NONSOLID
|
||||||
} else {
|
} else {
|
||||||
axisFunc(state)?.let { if (it == axis) PARALLEL else PERPENDICULAR } ?: SOLID
|
(registry[state]?.axis ?: if (Config.roundLogs.defaultY) Axis.Y else null)?.let {
|
||||||
|
if (it == axis) PARALLEL else PERPENDICULAR
|
||||||
|
} ?: SOLID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -30,12 +30,12 @@ class RenderCactus : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
|
|||||||
val iconCross = iconStatic(BetterFoliageMod.LEGACY_DOMAIN, "blocks/better_cactus")
|
val iconCross = iconStatic(BetterFoliageMod.LEGACY_DOMAIN, "blocks/better_cactus")
|
||||||
val iconArm = iconSet(BetterFoliageMod.LEGACY_DOMAIN, "blocks/better_cactus_arm_%d")
|
val iconArm = iconSet(BetterFoliageMod.LEGACY_DOMAIN, "blocks/better_cactus_arm_%d")
|
||||||
|
|
||||||
val cactusTextures: IColumnRegistry = object : TextureListModelProcessor<IColumnTextureResolver>, IColumnRegistry {
|
val cactusTextures: IColumnRegistry = object : TextureListModelProcessor<IColumnTextureInfo>, IColumnRegistry {
|
||||||
|
|
||||||
init { MinecraftForge.EVENT_BUS.register(this) }
|
init { MinecraftForge.EVENT_BUS.register(this) }
|
||||||
|
|
||||||
override var stateToKey = mutableMapOf<IBlockState, List<String>>()
|
override var stateToKey = mutableMapOf<IBlockState, List<String>>()
|
||||||
override var stateToValue = mapOf<IBlockState, IColumnTextureResolver>()
|
override var stateToValue = mapOf<IBlockState, IColumnTextureInfo>()
|
||||||
|
|
||||||
override val logger = BetterFoliageMod.logDetail
|
override val logger = BetterFoliageMod.logDetail
|
||||||
override val logName = "CactusTextures"
|
override val logName = "CactusTextures"
|
||||||
@@ -44,11 +44,11 @@ class RenderCactus : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
|
|||||||
modelTextures("block/cactus", "top", "bottom", "side")
|
modelTextures("block/cactus", "top", "bottom", "side")
|
||||||
)
|
)
|
||||||
|
|
||||||
override fun processStitch(state: IBlockState, key: List<String>, atlas: TextureMap): IColumnTextureResolver? {
|
override fun processStitch(state: IBlockState, key: List<String>, atlas: TextureMap): IColumnTextureInfo? {
|
||||||
val topTex = atlas[key[0]]
|
val topTex = atlas[key[0]] ?: return null
|
||||||
val bottomTex = atlas[key[1]]
|
val bottomTex = atlas[key[1]] ?: return null
|
||||||
val sideTex = atlas[key[2]]
|
val sideTex = atlas[key[2]] ?: return null
|
||||||
return if (topTex != null && bottomTex != null && sideTex != null) StaticColumnInfo(topTex, bottomTex, sideTex) else null
|
return StaticColumnInfo(Axis.Y, topTex, bottomTex, sideTex)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(state: IBlockState) = stateToValue[state]
|
override fun get(state: IBlockState) = stateToValue[state]
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import net.minecraft.client.renderer.texture.TextureAtlasSprite
|
|||||||
import net.minecraft.client.renderer.texture.TextureMap
|
import net.minecraft.client.renderer.texture.TextureMap
|
||||||
import net.minecraft.util.EnumFacing.Axis
|
import net.minecraft.util.EnumFacing.Axis
|
||||||
import net.minecraftforge.common.MinecraftForge
|
import net.minecraftforge.common.MinecraftForge
|
||||||
|
import org.apache.logging.log4j.Level
|
||||||
import org.apache.logging.log4j.Logger
|
import org.apache.logging.log4j.Logger
|
||||||
|
|
||||||
class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
|
class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
|
||||||
@@ -30,17 +31,6 @@ class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
|
|||||||
ctx.cameraDistance < Config.roundLogs.distance &&
|
ctx.cameraDistance < Config.roundLogs.distance &&
|
||||||
Config.blocks.logClasses.matchesClass(ctx.block)
|
Config.blocks.logClasses.matchesClass(ctx.block)
|
||||||
|
|
||||||
override var axisFunc = { state: IBlockState ->
|
|
||||||
val axis = tryDefault(null) { state.getValue(BlockLog.LOG_AXIS).toString() } ?:
|
|
||||||
state.properties.entries.find { it.key.getName().toLowerCase() == "axis" }?.let { it.value.toString() }
|
|
||||||
when (axis) {
|
|
||||||
"x" -> Axis.X
|
|
||||||
"y" -> Axis.Y
|
|
||||||
"z" -> Axis.Z
|
|
||||||
else -> if (Config.roundLogs.defaultY) Axis.Y else null
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override val registry: IColumnRegistry get() = LogRegistry
|
override val registry: IColumnRegistry get() = LogRegistry
|
||||||
|
|
||||||
override val blockPredicate = { state: IBlockState -> Config.blocks.logClasses.matchesClass(state.block) }
|
override val blockPredicate = { state: IBlockState -> Config.blocks.logClasses.matchesClass(state.block) }
|
||||||
@@ -59,24 +49,35 @@ object LogRegistry : IColumnRegistry {
|
|||||||
override fun get(state: IBlockState) = subRegistries.findFirst { it[state] }
|
override fun get(state: IBlockState) = subRegistries.findFirst { it[state] }
|
||||||
}
|
}
|
||||||
|
|
||||||
object StandardLogSupport : TextureListModelProcessor<IColumnTextureResolver>, IColumnRegistry {
|
object StandardLogSupport : TextureListModelProcessor<IColumnTextureInfo>, IColumnRegistry {
|
||||||
|
|
||||||
init { MinecraftForge.EVENT_BUS.register(this) }
|
init { MinecraftForge.EVENT_BUS.register(this) }
|
||||||
|
|
||||||
override var stateToKey = mutableMapOf<IBlockState, List<String>>()
|
override var stateToKey = mutableMapOf<IBlockState, List<String>>()
|
||||||
override var stateToValue = mapOf<IBlockState, IColumnTextureResolver>()
|
override var stateToValue = mapOf<IBlockState, IColumnTextureInfo>()
|
||||||
|
|
||||||
override val logger = BetterFoliageMod.logDetail
|
override val logger = BetterFoliageMod.logDetail
|
||||||
override val logName = "StandardLogSupport"
|
override val logName = "StandardLogSupport"
|
||||||
override val matchClasses: ConfigurableBlockMatcher get() = Config.blocks.logClasses
|
override val matchClasses: ConfigurableBlockMatcher get() = Config.blocks.logClasses
|
||||||
override val modelTextures: List<ModelTextureList> get() = Config.blocks.logModels.list
|
override val modelTextures: List<ModelTextureList> get() = Config.blocks.logModels.list
|
||||||
|
|
||||||
override fun processStitch(state: IBlockState, key: List<String>, atlas: TextureMap): IColumnTextureResolver? {
|
override fun processStitch(state: IBlockState, key: List<String>, atlas: TextureMap): IColumnTextureInfo? {
|
||||||
val topTex = atlas[key[0]]
|
val topTex = atlas[key[0]] ?: return null
|
||||||
val bottomTex = atlas[key[1]]
|
val bottomTex = atlas[key[1]] ?: return null
|
||||||
val sideTex = atlas[key[2]]
|
val sideTex = atlas[key[2]] ?: return null
|
||||||
return if (topTex != null && bottomTex != null && sideTex != null) StaticColumnInfo(topTex, bottomTex, sideTex) else null
|
return StaticColumnInfo(getAxis(state), topTex, bottomTex, sideTex)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun get(state: IBlockState) = stateToValue[state]
|
override fun get(state: IBlockState) = stateToValue[state]
|
||||||
|
|
||||||
|
fun getAxis(state: IBlockState): Axis? {
|
||||||
|
val axis = tryDefault(null) { state.getValue(BlockLog.LOG_AXIS).toString() } ?:
|
||||||
|
state.properties.entries.find { it.key.getName().toLowerCase() == "axis" }?.let { it.value.toString() }
|
||||||
|
return when (axis) {
|
||||||
|
"x" -> Axis.X
|
||||||
|
"y" -> Axis.Y
|
||||||
|
"z" -> Axis.Z
|
||||||
|
else -> null
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user