Multi-layer rendering support
This commit is contained in:
@@ -12,9 +12,10 @@ import mods.betterfoliage.util.Int3
|
||||
import mods.betterfoliage.util.plus
|
||||
import net.minecraft.block.Block
|
||||
import net.minecraft.client.Minecraft
|
||||
import net.minecraft.client.renderer.BlockRendererDispatcher
|
||||
import net.minecraft.client.renderer.chunk.ChunkRenderCache
|
||||
import net.minecraft.util.Direction
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.IBlockDisplayReader
|
||||
import net.minecraftforge.client.model.data.IModelData
|
||||
import java.util.Random
|
||||
|
||||
@@ -25,17 +26,19 @@ import java.util.Random
|
||||
* push-based partial rendering pipeline for [SpecialRenderModel] instances.
|
||||
*/
|
||||
abstract class RenderCtxBase(
|
||||
world: IBlockDisplayReader,
|
||||
pos: BlockPos,
|
||||
blockCtx: BlockCtx,
|
||||
val matrixStack: MatrixStack,
|
||||
var checkSides: Boolean,
|
||||
val random: Random,
|
||||
val modelData: IModelData
|
||||
) : BlockCtx by BasicBlockCtx(world, pos) {
|
||||
|
||||
abstract fun renderQuad(quad: HalfBakedQuad)
|
||||
val modelData: IModelData,
|
||||
) : BlockCtx by blockCtx {
|
||||
|
||||
var hasRendered = false
|
||||
var modelRenderData: Any? = null
|
||||
inline fun <reified T> withRenderData(renderFunc: (T)->Boolean) = (modelRenderData as? T?).let {
|
||||
if (it == null) false else renderFunc(it)
|
||||
}
|
||||
|
||||
val blockModelShapes = Minecraft.getInstance().blockRenderer.blockModelShaper
|
||||
var vertexLighter: VanillaVertexLighter = VanillaFullBlockLighting
|
||||
protected val lightingData = RenderCtxBase.lightingData.get().apply {
|
||||
@@ -43,6 +46,8 @@ abstract class RenderCtxBase(
|
||||
blockColors = Minecraft.getInstance().blockColors
|
||||
}
|
||||
|
||||
abstract fun renderQuad(quad: HalfBakedQuad)
|
||||
|
||||
inline fun Direction?.shouldRender() = this == null || !checkSides || Block.shouldRenderFace(state, world, pos, this)
|
||||
|
||||
fun renderQuads(quads: Iterable<HalfBakedQuad>) {
|
||||
@@ -61,6 +66,17 @@ abstract class RenderCtxBase(
|
||||
}
|
||||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun reset(chunkRenderCache: ChunkRenderCache, blockRendererDispatcher: BlockRendererDispatcher, pos: BlockPos, random: Random) {
|
||||
// prepare render data
|
||||
val blockCtx = BasicBlockCtx(chunkRenderCache, pos)
|
||||
val model = blockRendererDispatcher.getBlockModel(blockCtx.state)
|
||||
random.setSeed(blockCtx.seed)
|
||||
val data = if (model is SpecialRenderModel) model.prepare(blockCtx, random) else Unit
|
||||
specialRenderData.set(data)
|
||||
}
|
||||
|
||||
val lightingData = ThreadLocal.withInitial { VanillaQuadLighting() }
|
||||
val specialRenderData = ThreadLocal<Any?>()
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user