allow for custom column textures (preparation for rubber log support)

This commit is contained in:
octarine-noise
2016-07-23 12:01:28 +02:00
parent 2ca330fd29
commit f96409f9a1
2 changed files with 33 additions and 34 deletions

View File

@@ -1,14 +1,12 @@
package mods.betterfoliage.client.render package mods.betterfoliage.client.render
import mods.betterfoliage.client.config.BlockMatcher import mods.betterfoliage.client.config.BlockMatcher
import mods.betterfoliage.client.integration.OptifineCTM
import mods.betterfoliage.client.render.AbstractRenderColumn.BlockType.* import mods.betterfoliage.client.render.AbstractRenderColumn.BlockType.*
import mods.betterfoliage.client.render.AbstractRenderColumn.QuadrantType.* import mods.betterfoliage.client.render.AbstractRenderColumn.QuadrantType.*
import mods.octarinecore.client.render.* import mods.octarinecore.client.render.*
import mods.octarinecore.client.resource.BlockTextureInspector import mods.octarinecore.client.resource.BlockTextureInspector
import mods.octarinecore.common.Int3 import mods.octarinecore.common.*
import mods.octarinecore.common.Rotation
import mods.octarinecore.common.face
import mods.octarinecore.common.rot
import net.minecraft.block.state.IBlockState import net.minecraft.block.state.IBlockState
import net.minecraft.client.renderer.BlockRendererDispatcher import net.minecraft.client.renderer.BlockRendererDispatcher
import net.minecraft.client.renderer.WorldRenderer import net.minecraft.client.renderer.WorldRenderer
@@ -18,18 +16,34 @@ import net.minecraft.util.EnumFacing
import net.minecraft.util.EnumFacing.* import net.minecraft.util.EnumFacing.*
import net.minecraft.util.EnumWorldBlockLayer import net.minecraft.util.EnumWorldBlockLayer
data class ColumnInfo(val topTexture: TextureAtlasSprite, interface ColumnTextureResolver {
val bottomTexture: TextureAtlasSprite, val top: (ShadingContext, Int, Quad)->TextureAtlasSprite?
val sideTexture: TextureAtlasSprite) val bottom: (ShadingContext, Int, Quad)->TextureAtlasSprite?
val side: (ShadingContext, Int, Quad)->TextureAtlasSprite?
}
open class ColumnTextures(val matcher: BlockMatcher) : BlockTextureInspector<ColumnInfo>() { data class StaticColumnInfo(val topTexture: TextureAtlasSprite,
val bottomTexture: TextureAtlasSprite,
val sideTexture: TextureAtlasSprite) : ColumnTextureResolver {
override val top = { ctx: ShadingContext, idx: Int, quad: Quad ->
OptifineCTM.override(topTexture, blockContext, UP.rotate(ctx.rotation))
}
override val bottom = { ctx: ShadingContext, idx: Int, quad: Quad ->
OptifineCTM.override(bottomTexture, blockContext, DOWN.rotate(ctx.rotation))
}
override val side = { ctx: ShadingContext, idx: Int, quad: Quad ->
OptifineCTM.override(sideTexture, blockContext, (if ((idx and 1) == 0) SOUTH else EAST).rotate(ctx.rotation))
}
}
open class ColumnTextures(val matcher: BlockMatcher) : BlockTextureInspector<StaticColumnInfo>() {
init { init {
matchClassAndModel(matcher, "block/column_side", listOf("end", "end", "side")) matchClassAndModel(matcher, "block/column_side", listOf("end", "end", "side"))
matchClassAndModel(matcher, "block/cube_column", listOf("end", "end", "side")) matchClassAndModel(matcher, "block/cube_column", listOf("end", "end", "side"))
matchClassAndModel(matcher, "block/cube_all", listOf("all", "all", "all")) matchClassAndModel(matcher, "block/cube_all", listOf("all", "all", "all"))
} }
override fun processTextures(state: IBlockState, textures: List<TextureAtlasSprite>, atlas: TextureMap) = override fun processTextures(state: IBlockState, textures: List<TextureAtlasSprite>, atlas: TextureMap) =
ColumnInfo(textures[0], textures[1], textures[2]) StaticColumnInfo(textures[0], textures[1], textures[2])
} }
/** Index of SOUTH-EAST quadrant. */ /** Index of SOUTH-EAST quadrant. */
@@ -120,14 +134,14 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
abstract val axisFunc: (IBlockState)->EnumFacing.Axis? abstract val axisFunc: (IBlockState)->EnumFacing.Axis?
abstract val blockPredicate: (IBlockState)->Boolean abstract val blockPredicate: (IBlockState)->Boolean
abstract val sideTexture: (ShadingContext, Int, Quad)->TextureAtlasSprite? abstract fun resolver(ctx: BlockContext): ColumnTextureResolver?
abstract val upTexture: (ShadingContext, Int, Quad)->TextureAtlasSprite?
abstract val downTexture: (ShadingContext, Int, Quad)->TextureAtlasSprite?
@Suppress("NON_EXHAUSTIVE_WHEN") @Suppress("NON_EXHAUSTIVE_WHEN")
override fun render(ctx: BlockContext, dispatcher: BlockRendererDispatcher, renderer: WorldRenderer, layer: EnumWorldBlockLayer): Boolean { override fun render(ctx: BlockContext, dispatcher: BlockRendererDispatcher, renderer: WorldRenderer, layer: EnumWorldBlockLayer): Boolean {
if (ctx.isSurroundedBy(surroundPredicate) ) return false if (ctx.isSurroundedBy(surroundPredicate) ) return false
val columnTextures = resolver(ctx) ?: return false
// get AO data // get AO data
modelRenderer.updateShading(Int3.zero, allFaces) modelRenderer.updateShading(Int3.zero, allFaces)
@@ -170,7 +184,7 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
sideModel, sideModel,
rotation, rotation,
blockContext.blockCenter, blockContext.blockCenter,
icon = sideTexture, icon = columnTextures.side,
rotateUV = { 0 }, rotateUV = { 0 },
postProcess = noPost postProcess = noPost
) )
@@ -178,8 +192,8 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
// render top and bottom end of current quadrant // render top and bottom end of current quadrant
var upModel: Model? = null var upModel: Model? = null
var downModel: Model? = null var downModel: Model? = null
var upIcon = upTexture var upIcon = columnTextures.top
var downIcon = downTexture var downIcon = columnTextures.bottom
var shouldRotateUp = true var shouldRotateUp = true
var shouldRotateDown = true var shouldRotateDown = true
@@ -189,7 +203,7 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
if (!connectPerpendicular) { if (!connectPerpendicular) {
upModel = flatTop(quadrants[idx]) upModel = flatTop(quadrants[idx])
} else { } else {
upIcon = sideTexture upIcon = columnTextures.side
upModel = extendTop(quadrants[idx]) upModel = extendTop(quadrants[idx])
shouldRotateUp = false shouldRotateUp = false
} }
@@ -208,7 +222,7 @@ abstract class AbstractRenderColumn(modId: String) : AbstractBlockRenderingHandl
if (!connectPerpendicular) { if (!connectPerpendicular) {
downModel = flatBottom(quadrants[idx]) downModel = flatBottom(quadrants[idx])
} else { } else {
downIcon = sideTexture downIcon = columnTextures.side
downModel = extendBottom(quadrants[idx]) downModel = extendBottom(quadrants[idx])
shouldRotateDown = false shouldRotateDown = false
} }

View File

@@ -45,6 +45,8 @@ class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
} }
} }
override fun resolver(ctx: BlockContext): ColumnTextureResolver? = columnTextures[ctx.blockState(Int3.zero)]
override val blockPredicate = { state: IBlockState -> Config.blocks.logs.matchesID(state.block) } override val blockPredicate = { state: IBlockState -> Config.blocks.logs.matchesID(state.block) }
override val surroundPredicate = { state: IBlockState -> state.block.isOpaqueCube && !Config.blocks.logs.matchesID(state.block) } override val surroundPredicate = { state: IBlockState -> state.block.isOpaqueCube && !Config.blocks.logs.matchesID(state.block) }
@@ -54,21 +56,4 @@ class RenderLog : AbstractRenderColumn(BetterFoliageMod.MOD_ID) {
override val radiusLarge: Double get() = Config.roundLogs.radiusLarge override val radiusLarge: Double get() = Config.roundLogs.radiusLarge
override val radiusSmall: Double get() = Config.roundLogs.radiusSmall override val radiusSmall: Double get() = Config.roundLogs.radiusSmall
override val downTexture = { ctx: ShadingContext, idx: Int, quad: Quad ->
columnTextures[ctx.blockData(Int3.zero).state]?.bottomTexture?.let { base ->
OptifineCTM.override(base, blockContext, DOWN.rotate(ctx.rotation))
}
}
override val sideTexture = { ctx: ShadingContext, idx: Int, quad: Quad ->
columnTextures[ctx.blockData(Int3.zero).state]?.sideTexture?.let { base ->
OptifineCTM.override(base, blockContext, (if ((idx and 1) == 0) SOUTH else EAST).rotate(ctx.rotation))
}
}
override val upTexture = { ctx: ShadingContext, idx: Int, quad: Quad ->
columnTextures[ctx.blockData(Int3.zero).state]?.topTexture?.let { base ->
OptifineCTM.override(base, blockContext, UP.rotate(ctx.rotation))
}
}
} }