Cache round log neighborhood data for faster chunk re-rendering
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
@file:Suppress("NOTHING_TO_INLINE")
|
||||
package mods.octarinecore
|
||||
|
||||
import mods.betterfoliage.loader.Refs
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraft.util.math.BlockPos
|
||||
@@ -101,11 +102,12 @@ fun nextPowerOf2(x: Int): Int {
|
||||
|
||||
/**
|
||||
* Check if the Chunk containing the given [BlockPos] is loaded.
|
||||
* Works for both [World] and [ChunkCache] instances.
|
||||
* Works for both [World] and [ChunkCache] (vanilla and OptiFine) instances.
|
||||
*/
|
||||
fun IBlockAccess.isBlockLoaded(pos: BlockPos) = when(this) {
|
||||
is World -> isBlockLoaded(pos, false)
|
||||
is ChunkCache -> world.isBlockLoaded(pos, false)
|
||||
fun IBlockAccess.isBlockLoaded(pos: BlockPos) = when {
|
||||
this is World -> isBlockLoaded(pos, false)
|
||||
this is ChunkCache -> world.isBlockLoaded(pos, false)
|
||||
Refs.OptifineChunkCache.isInstance(this) -> (Refs.CCOFChunkCache.get(this) as ChunkCache).world.isBlockLoaded(pos, false)
|
||||
else -> false
|
||||
}
|
||||
|
||||
@@ -113,6 +115,6 @@ fun IBlockAccess.isBlockLoaded(pos: BlockPos) = when(this) {
|
||||
* Get the [TileEntity] at the given position, suppressing exceptions.
|
||||
* Also returns null if the chunk is unloaded, which can happen because of multithreaded rendering.
|
||||
*/
|
||||
fun IBlockAccess.getTileEntitySafe(pos: BlockPos): TileEntity? = tryDefault(null) {
|
||||
fun IBlockAccess.getTileEntitySafe(pos: BlockPos): TileEntity? = tryDefault(null as TileEntity?) {
|
||||
if (isBlockLoaded(pos)) getTileEntity(pos) else null
|
||||
}
|
||||
@@ -71,10 +71,10 @@ 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 {
|
||||
var world: IBlockAccess? = null
|
||||
var pos = BlockPos.ORIGIN
|
||||
|
||||
class BlockContext(
|
||||
var world: IBlockAccess? = null,
|
||||
var pos: BlockPos = BlockPos.ORIGIN
|
||||
) {
|
||||
fun set(world: IBlockAccess, pos: BlockPos) { this.world = world; this.pos = pos; }
|
||||
|
||||
val block: Block get() = block(Int3.zero)
|
||||
|
||||
Reference in New Issue
Block a user