diff --git a/src/main/kotlin/mods/betterfoliage/client/Hooks.kt b/src/main/kotlin/mods/betterfoliage/client/Hooks.kt index 584025c..523ebdd 100644 --- a/src/main/kotlin/mods/betterfoliage/client/Hooks.kt +++ b/src/main/kotlin/mods/betterfoliage/client/Hooks.kt @@ -12,6 +12,7 @@ import mods.octarinecore.common.plus import mods.octarinecore.metaprog.allAvailable import net.minecraft.block.Block import net.minecraft.block.state.IBlockState +import net.minecraft.client.Minecraft import net.minecraft.client.renderer.BlockRendererDispatcher import net.minecraft.client.renderer.VertexBuffer import net.minecraft.init.Blocks @@ -77,26 +78,24 @@ fun renderWorldBlock(dispatcher: BlockRendererDispatcher, worldRenderer: VertexBuffer, layer: BlockRenderLayer ): Boolean { + val doBaseRender = state.canRenderInLayer(layer) || (layer == targetCutoutLayer && state.canRenderInLayer(otherCutoutLayer)) blockContext.let { ctx -> ctx.set(blockAccess, pos) Client.renderers.forEach { renderer -> if (renderer.isEligible(ctx)) { - // render on the block's default layer AND CUTOUT_MIPPED if the renderer requires it - if (state.canRenderInLayer(layer) || (layer.isCutout && renderer.addToCutout)) { + // render on the block's default layer + // also render on the cutout layer if the renderer requires it + if (doBaseRender || (renderer.addToCutout && layer == targetCutoutLayer)) { return renderer.render(ctx, dispatcher, worldRenderer, layer) } } } } - // stuff on the CUTOUT layer must be rendered on CUTOUT_MIPPED instead if OptiFine is present - val doBaseRender = state.canRenderInLayer(layer) || (isOptifinePresent && layer == CUTOUT_MIPPED && state.canRenderInLayer(CUTOUT)) + return if (doBaseRender) dispatcher.renderBlock(state, pos, blockAccess, worldRenderer) else false } -fun canRenderBlockInLayer(block: Block, state: IBlockState, layer: BlockRenderLayer): Boolean { - if (layer == CUTOUT_MIPPED && !block.canRenderInLayer(state, CUTOUT)) { - return true - } - return block.canRenderInLayer(state, layer) +fun canRenderBlockInLayer(block: Block, state: IBlockState, layer: BlockRenderLayer) = block.canRenderInLayer(state, layer) || layer == targetCutoutLayer -} \ No newline at end of file +val targetCutoutLayer: BlockRenderLayer get() = if (Minecraft.getMinecraft().gameSettings.mipmapLevels > 0) CUTOUT_MIPPED else CUTOUT +val otherCutoutLayer: BlockRenderLayer get() = if (Minecraft.getMinecraft().gameSettings.mipmapLevels > 0) CUTOUT else CUTOUT_MIPPED \ No newline at end of file diff --git a/src/main/kotlin/mods/betterfoliage/client/render/RenderConnectedGrassLog.kt b/src/main/kotlin/mods/betterfoliage/client/render/RenderConnectedGrassLog.kt index e3a40d1..961ae6c 100644 --- a/src/main/kotlin/mods/betterfoliage/client/render/RenderConnectedGrassLog.kt +++ b/src/main/kotlin/mods/betterfoliage/client/render/RenderConnectedGrassLog.kt @@ -27,13 +27,9 @@ class RenderConnectedGrassLog : AbstractBlockRenderingHandler(BetterFoliageMod.M override fun render(ctx: BlockContext, dispatcher: BlockRendererDispatcher, renderer: VertexBuffer, layer: BlockRenderLayer): Boolean { val grassDir = grassCheckDirs.find { Config.blocks.grassClasses.matchesClass(ctx.block(it.offset)) - } + } ?: return renderWorldBlockBase(ctx, dispatcher, renderer, layer) - return if (grassDir != null) { - ctx.withOffset(Int3.zero, grassDir.offset) { - renderWorldBlockBase(ctx, dispatcher, renderer, layer) - } - } else { + return ctx.withOffset(Int3.zero, grassDir.offset) { renderWorldBlockBase(ctx, dispatcher, renderer, layer) } } diff --git a/src/main/kotlin/mods/betterfoliage/client/render/Utils.kt b/src/main/kotlin/mods/betterfoliage/client/render/Utils.kt index 178e4a2..ae4ffd6 100644 --- a/src/main/kotlin/mods/betterfoliage/client/render/Utils.kt +++ b/src/main/kotlin/mods/betterfoliage/client/render/Utils.kt @@ -58,4 +58,5 @@ fun Model.mix(first: Model, second: Model, predicate: (Int)->Boolean) { val BlockRenderLayer.isCutout: Boolean get() = (this == BlockRenderLayer.CUTOUT) || (this == BlockRenderLayer.CUTOUT_MIPPED) -fun IBlockState.canRenderInLayer(layer: BlockRenderLayer) = this.block.canRenderInLayer(this, layer) \ No newline at end of file +fun IBlockState.canRenderInLayer(layer: BlockRenderLayer) = this.block.canRenderInLayer(this, layer) +fun IBlockState.canRenderInCutout() = this.block.canRenderInLayer(this, BlockRenderLayer.CUTOUT) || this.block.canRenderInLayer(this, BlockRenderLayer.CUTOUT_MIPPED) \ No newline at end of file diff --git a/src/main/kotlin/mods/octarinecore/client/render/AbstractBlockRenderingHandler.kt b/src/main/kotlin/mods/octarinecore/client/render/AbstractBlockRenderingHandler.kt index ae5ef0d..6dacb77 100644 --- a/src/main/kotlin/mods/octarinecore/client/render/AbstractBlockRenderingHandler.kt +++ b/src/main/kotlin/mods/octarinecore/client/render/AbstractBlockRenderingHandler.kt @@ -1,6 +1,9 @@ @file:JvmName("RendererHolder") package mods.octarinecore.client.render +import mods.betterfoliage.client.render.canRenderInCutout +import mods.betterfoliage.client.render.canRenderInLayer +import mods.betterfoliage.client.render.isCutout import mods.octarinecore.ThreadLocalDelegate import mods.octarinecore.client.resource.ResourceHandler import mods.octarinecore.common.Double3 @@ -49,8 +52,11 @@ abstract class AbstractBlockRenderingHandler(modId: String) : ResourceHandler(mo */ fun renderWorldBlockBase(ctx: BlockContext, dispatcher: BlockRendererDispatcher, renderer: VertexBuffer, layer: BlockRenderLayer?): Boolean { ctx.blockState(Int3.zero).let { - if (layer == null || it.block.canRenderInLayer(it, layer)) + if (layer == null || + it.canRenderInLayer(layer) || + (it.canRenderInCutout() && layer.isCutout)) { return dispatcher.renderBlock(it, ctx.pos, ctx.world, renderer) + } } return false } @@ -63,7 +69,7 @@ data class BlockData(val state: IBlockState, val color: Int, val brightness: Int * Represents the block being rendered. Has properties and methods to query the neighborhood of the block in * block-relative coordinates. */ -class BlockContext() { +class BlockContext { var world: IBlockAccess? = null var pos = BlockPos.ORIGIN