don't render hidden faces on connected grass
This commit is contained in:
@@ -6,6 +6,8 @@ import mods.octarinecore.client.render.AbstractBlockRenderingHandler
|
||||
import mods.octarinecore.client.render.BlockContext
|
||||
import mods.octarinecore.client.render.withOffset
|
||||
import mods.octarinecore.common.Int3
|
||||
import mods.octarinecore.common.forgeDirsHorizontal
|
||||
import mods.octarinecore.common.offset
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher
|
||||
import net.minecraft.client.renderer.VertexBuffer
|
||||
import net.minecraft.util.BlockRenderLayer
|
||||
@@ -21,6 +23,10 @@ class RenderConnectedGrass : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_
|
||||
(Config.connectedGrass.snowEnabled || !ctx.blockState(up2).isSnow)
|
||||
|
||||
override fun render(ctx: BlockContext, dispatcher: BlockRendererDispatcher, renderer: VertexBuffer, layer: BlockRenderLayer): Boolean {
|
||||
// if the block sides are not visible anyway, render normally
|
||||
if (forgeDirsHorizontal.all { ctx.blockState(it.offset).isOpaqueCube }) return renderWorldBlockBase(ctx, dispatcher, renderer, null)
|
||||
|
||||
if (ctx.isSurroundedBy { it.isOpaqueCube } ) return false
|
||||
return ctx.withOffset(Int3.zero, up1) {
|
||||
ctx.withOffset(up1, up2) {
|
||||
renderWorldBlockBase(ctx, dispatcher, renderer, null)
|
||||
|
||||
@@ -6,9 +6,7 @@ import mods.betterfoliage.client.config.Config
|
||||
import mods.betterfoliage.client.integration.ShadersModIntegration
|
||||
import mods.betterfoliage.client.texture.GrassRegistry
|
||||
import mods.octarinecore.client.render.*
|
||||
import mods.octarinecore.common.Double3
|
||||
import mods.octarinecore.common.Int3
|
||||
import mods.octarinecore.common.Rotation
|
||||
import mods.octarinecore.common.*
|
||||
import mods.octarinecore.random
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher
|
||||
import net.minecraft.client.renderer.VertexBuffer
|
||||
@@ -66,13 +64,15 @@ class RenderGrass : AbstractBlockRenderingHandler(BetterFoliageMod.MOD_ID) {
|
||||
// get full AO data
|
||||
modelRenderer.updateShading(Int3.zero, allFaces)
|
||||
|
||||
// check occlusion
|
||||
val isHidden = forgeDirs.map { ctx.blockState(it.offset).isOpaqueCube }
|
||||
|
||||
// render full grass block
|
||||
ShadersModIntegration.renderAs(ctx.blockState(Int3.zero), renderer) {
|
||||
modelRenderer.render(
|
||||
renderer,
|
||||
fullCube,
|
||||
Rotation.identity,
|
||||
ctx.blockCenter,
|
||||
quadFilter = { qi, _ -> !isHidden[qi] },
|
||||
icon = { _, _, _ -> grassInfo.grassTopTexture },
|
||||
postProcess = { ctx, _, _, _, _ ->
|
||||
rotateUV(2)
|
||||
|
||||
@@ -49,7 +49,7 @@ 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(layer))
|
||||
if (layer == null || it.block.canRenderInLayer(it, layer))
|
||||
return dispatcher.renderBlock(it, ctx.pos, ctx.world, renderer)
|
||||
}
|
||||
return false
|
||||
|
||||
@@ -34,6 +34,7 @@ class ModelRenderer : ShadingContext() {
|
||||
rot: Rotation = Rotation.identity,
|
||||
trans: Double3 = blockContext.blockCenter,
|
||||
forceFlat: Boolean = false,
|
||||
quadFilter: (Int, Quad) -> Boolean = { _, _ -> true },
|
||||
icon: QuadIconResolver,
|
||||
postProcess: PostProcessLambda
|
||||
) {
|
||||
@@ -44,21 +45,23 @@ class ModelRenderer : ShadingContext() {
|
||||
worldRenderer.ensureSpaceForQuads(model.quads.size + 1)
|
||||
|
||||
model.quads.forEachIndexed { quadIdx, quad ->
|
||||
val drawIcon = icon(this, quadIdx, quad)
|
||||
if (drawIcon != null) {
|
||||
quad.verts.forEachIndexed { vertIdx, vert ->
|
||||
temp.init(vert).rotate(rotation).translate(trans)
|
||||
val shader = if (aoEnabled && !forceFlat) vert.aoShader else vert.flatShader
|
||||
shader.shade(this, temp)
|
||||
temp.postProcess(this, quadIdx, quad, vertIdx, vert)
|
||||
temp.setIcon(drawIcon)
|
||||
if (quadFilter(quadIdx, quad)) {
|
||||
val drawIcon = icon(this, quadIdx, quad)
|
||||
if (drawIcon != null) {
|
||||
quad.verts.forEachIndexed { vertIdx, vert ->
|
||||
temp.init(vert).rotate(rotation).translate(trans)
|
||||
val shader = if (aoEnabled && !forceFlat) vert.aoShader else vert.flatShader
|
||||
shader.shade(this, temp)
|
||||
temp.postProcess(this, quadIdx, quad, vertIdx, vert)
|
||||
temp.setIcon(drawIcon)
|
||||
|
||||
worldRenderer
|
||||
.pos(temp.x, temp.y, temp.z)
|
||||
.color(temp.red, temp.green, temp.blue, 1.0f)
|
||||
.tex(temp.u, temp.v)
|
||||
.lightmap(temp.brightness shr 16 and 65535, temp.brightness and 65535)
|
||||
.endVertex()
|
||||
worldRenderer
|
||||
.pos(temp.x, temp.y, temp.z)
|
||||
.color(temp.red, temp.green, temp.blue, 1.0f)
|
||||
.tex(temp.u, temp.v)
|
||||
.lightmap(temp.brightness shr 16 and 65535, temp.brightness and 65535)
|
||||
.endVertex()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@ val axisDirs = listOf(POSITIVE, NEGATIVE)
|
||||
val EnumFacing.dir: AxisDirection get() = axisDirection
|
||||
val AxisDirection.sign: String get() = when(this) { POSITIVE -> "+"; NEGATIVE -> "-" }
|
||||
val forgeDirs = EnumFacing.values()
|
||||
val forgeDirsHorizontal = listOf(NORTH, SOUTH, EAST, WEST)
|
||||
val forgeDirOffsets = forgeDirs.map { Int3(it) }
|
||||
val Pair<Axis, AxisDirection>.face: EnumFacing get() = when(this) {
|
||||
X to POSITIVE -> EAST; X to NEGATIVE -> WEST;
|
||||
|
||||
Reference in New Issue
Block a user