From 66558932a9ba10d0977acb46b4da8adc4169563f Mon Sep 17 00:00:00 2001 From: octarine-noise Date: Wed, 21 Dec 2016 19:36:40 +0100 Subject: [PATCH] move log block axis into the info object --- .../client/integration/ForestryIntegration.kt | 13 +++---- .../client/render/AbstractRenderColumn.kt | 22 ++++++----- .../client/render/RenderCactus.kt | 14 +++---- .../betterfoliage/client/render/RenderLog.kt | 37 ++++++++++--------- 4 files changed, 43 insertions(+), 43 deletions(-) diff --git a/src/main/kotlin/mods/betterfoliage/client/integration/ForestryIntegration.kt b/src/main/kotlin/mods/betterfoliage/client/integration/ForestryIntegration.kt index e7c7324..511e627 100644 --- a/src/main/kotlin/mods/betterfoliage/client/integration/ForestryIntegration.kt +++ b/src/main/kotlin/mods/betterfoliage/client/integration/ForestryIntegration.kt @@ -3,10 +3,7 @@ package mods.betterfoliage.client.integration import mods.betterfoliage.BetterFoliageMod import mods.betterfoliage.client.Client import mods.betterfoliage.client.config.Config -import mods.betterfoliage.client.render.IColumnRegistry -import mods.betterfoliage.client.render.IColumnTextureResolver -import mods.betterfoliage.client.render.LogRegistry -import mods.betterfoliage.client.render.StaticColumnInfo +import mods.betterfoliage.client.render.* import mods.betterfoliage.client.texture.ILeafRegistry import mods.betterfoliage.client.texture.LeafInfo import mods.betterfoliage.client.texture.LeafRegistry @@ -126,10 +123,10 @@ object ForestryLeavesSupport : ILeafRegistry { } } -object ForestryLogSupport : ModelProcessor, IColumnTextureResolver>, IColumnRegistry { +object ForestryLogSupport : ModelProcessor, IColumnTextureInfo>, IColumnRegistry { override var stateToKey = mutableMapOf>() - override var stateToValue = mapOf() + override var stateToValue = mapOf() override val logger = BetterFoliageMod.logDetail @@ -155,10 +152,10 @@ object ForestryLogSupport : ModelProcessor, IColumnTextureResolver> return if (bark != null && heart != null) listOf(heart, bark) else null } - override fun processStitch(state: IBlockState, key: List, atlas: TextureMap): IColumnTextureResolver? { + override fun processStitch(state: IBlockState, key: List, atlas: TextureMap): IColumnTextureInfo? { val heart = atlas[key[0]] ?: 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] diff --git a/src/main/kotlin/mods/betterfoliage/client/render/AbstractRenderColumn.kt b/src/main/kotlin/mods/betterfoliage/client/render/AbstractRenderColumn.kt index 362b051..247ec24 100644 --- a/src/main/kotlin/mods/betterfoliage/client/render/AbstractRenderColumn.kt +++ b/src/main/kotlin/mods/betterfoliage/client/render/AbstractRenderColumn.kt @@ -1,5 +1,6 @@ package mods.betterfoliage.client.render +import mods.betterfoliage.client.config.Config import mods.betterfoliage.client.integration.OptifineCTM import mods.betterfoliage.client.integration.ShadersModIntegration 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.* -interface IColumnTextureResolver { +interface IColumnTextureInfo { + val axis: Axis? val top: (ShadingContext, Int, Quad)->TextureAtlasSprite? val bottom: (ShadingContext, Int, Quad)->TextureAtlasSprite? val side: (ShadingContext, Int, Quad)->TextureAtlasSprite? } 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 sideTexture: TextureAtlasSprite) : IColumnTextureResolver { + val sideTexture: TextureAtlasSprite) : IColumnTextureInfo { override val top = { ctx: ShadingContext, idx: Int, quad: Quad -> 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) = q1 == q2 || ((q1 == SQUARE || q1 == INVISIBLE) && (q2 == SQUARE || q2 == INVISIBLE)) - abstract val axisFunc: (IBlockState)->EnumFacing.Axis? abstract val blockPredicate: (IBlockState)->Boolean abstract val registry: IColumnRegistry @@ -138,7 +140,8 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl modelRenderer.updateShading(Int3.zero, allFaces) // 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 upType = ctx.blockType(baseRotation, logAxis, Int3(0, 1, 0)) @@ -328,9 +331,6 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl 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. */ @@ -340,7 +340,9 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl return if (!blockPredicate(state)) { if (state.isOpaqueCube) SOLID else NONSOLID } 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 } } } \ No newline at end of file diff --git a/src/main/kotlin/mods/betterfoliage/client/render/RenderCactus.kt b/src/main/kotlin/mods/betterfoliage/client/render/RenderCactus.kt index 3fbf34d..790a083 100644 --- a/src/main/kotlin/mods/betterfoliage/client/render/RenderCactus.kt +++ b/src/main/kotlin/mods/betterfoliage/client/render/RenderCactus.kt @@ -30,12 +30,12 @@ class RenderCactus : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) { val iconCross = iconStatic(BetterFoliageMod.LEGACY_DOMAIN, "blocks/better_cactus") val iconArm = iconSet(BetterFoliageMod.LEGACY_DOMAIN, "blocks/better_cactus_arm_%d") - val cactusTextures: IColumnRegistry = object : TextureListModelProcessor, IColumnRegistry { + val cactusTextures: IColumnRegistry = object : TextureListModelProcessor, IColumnRegistry { init { MinecraftForge.EVENT_BUS.register(this) } override var stateToKey = mutableMapOf>() - override var stateToValue = mapOf() + override var stateToValue = mapOf() override val logger = BetterFoliageMod.logDetail override val logName = "CactusTextures" @@ -44,11 +44,11 @@ class RenderCactus : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) { modelTextures("block/cactus", "top", "bottom", "side") ) - override fun processStitch(state: IBlockState, key: List, atlas: TextureMap): IColumnTextureResolver? { - val topTex = atlas[key[0]] - val bottomTex = atlas[key[1]] - val sideTex = atlas[key[2]] - return if (topTex != null && bottomTex != null && sideTex != null) StaticColumnInfo(topTex, bottomTex, sideTex) else null + override fun processStitch(state: IBlockState, key: List, 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) } override fun get(state: IBlockState) = stateToValue[state] diff --git a/src/main/kotlin/mods/betterfoliage/client/render/RenderLog.kt b/src/main/kotlin/mods/betterfoliage/client/render/RenderLog.kt index 9de5aac..e6781ff 100644 --- a/src/main/kotlin/mods/betterfoliage/client/render/RenderLog.kt +++ b/src/main/kotlin/mods/betterfoliage/client/render/RenderLog.kt @@ -19,6 +19,7 @@ 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 org.apache.logging.log4j.Level import org.apache.logging.log4j.Logger class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) { @@ -30,17 +31,6 @@ class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) { ctx.cameraDistance < Config.roundLogs.distance && 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 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] } } -object StandardLogSupport : TextureListModelProcessor, IColumnRegistry { +object StandardLogSupport : TextureListModelProcessor, IColumnRegistry { init { MinecraftForge.EVENT_BUS.register(this) } override var stateToKey = mutableMapOf>() - override var stateToValue = mapOf() + override var stateToValue = mapOf() override val logger = BetterFoliageMod.logDetail override val logName = "StandardLogSupport" override val matchClasses: ConfigurableBlockMatcher get() = Config.blocks.logClasses override val modelTextures: List get() = Config.blocks.logModels.list - override fun processStitch(state: IBlockState, key: List, atlas: TextureMap): IColumnTextureResolver? { - val topTex = atlas[key[0]] - val bottomTex = atlas[key[1]] - val sideTex = atlas[key[2]] - return if (topTex != null && bottomTex != null && sideTex != null) StaticColumnInfo(topTex, bottomTex, sideTex) else null + override fun processStitch(state: IBlockState, key: List, 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) } 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 + } + } } \ No newline at end of file