do not access TileEntities in unloaded chunks
This commit is contained in:
@@ -11,6 +11,8 @@ import mods.betterfoliage.loader.Refs
|
||||
import mods.octarinecore.client.resource.ModelProcessor
|
||||
import mods.octarinecore.client.resource.ModelVariant
|
||||
import mods.octarinecore.client.resource.registerSprite
|
||||
import mods.octarinecore.getTileEntitySafe
|
||||
import mods.octarinecore.isBlockLoaded
|
||||
import mods.octarinecore.metaprog.ClassRef
|
||||
import mods.octarinecore.metaprog.FieldRef
|
||||
import mods.octarinecore.metaprog.MethodRef
|
||||
@@ -117,7 +119,7 @@ object ForestryLeavesSupport : ILeafRegistry {
|
||||
}
|
||||
|
||||
// extract leaf texture information from TileEntity
|
||||
val tile = tryDefault(null) { world.getTileEntity(pos) } ?: return null
|
||||
val tile = world.getTileEntitySafe(pos) ?: return null
|
||||
if (!ForestryIntegration.TileLeaves.isInstance(tile)) return null
|
||||
val textureLoc = ForestryIntegration.TiLgetLeaveSprite.invoke(tile, Minecraft.isFancyGraphicsEnabled()) ?: return null
|
||||
return textureToValue[textureLoc]
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
@file:Suppress("NOTHING_TO_INLINE")
|
||||
package mods.octarinecore
|
||||
|
||||
import net.minecraft.tileentity.TileEntity
|
||||
import net.minecraft.util.ResourceLocation
|
||||
import net.minecraft.util.math.BlockPos
|
||||
import net.minecraft.world.ChunkCache
|
||||
import net.minecraft.world.IBlockAccess
|
||||
import net.minecraft.world.World
|
||||
import kotlin.reflect.KProperty
|
||||
import java.lang.Math.*
|
||||
|
||||
@@ -93,3 +98,21 @@ fun Int.minmax(minVal: Int, maxVal: Int) = min(max(this, minVal), maxVal)
|
||||
fun nextPowerOf2(x: Int): Int {
|
||||
return 1 shl (if (x == 0) 0 else 32 - Integer.numberOfLeadingZeros(x - 1))
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the Chunk containing the given [BlockPos] is loaded.
|
||||
* Works for both [World] and [ChunkCache] instances.
|
||||
*/
|
||||
fun IBlockAccess.isBlockLoaded(pos: BlockPos) = when(this) {
|
||||
is World -> isBlockLoaded(pos, false)
|
||||
is ChunkCache -> world.isBlockLoaded(pos, false)
|
||||
else -> false
|
||||
}
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
if (isBlockLoaded(pos)) getTileEntity(pos) else null
|
||||
}
|
||||
@@ -11,3 +11,5 @@ public net.minecraft.client.renderer.BufferBuilder func_181670_b(I)V # growBuffe
|
||||
public net.minecraft.client.renderer.BufferBuilder func_181664_j()I # getBufferSize
|
||||
|
||||
public net.minecraft.client.renderer.BlockModelRenderer field_187499_a # blockColors
|
||||
|
||||
public net.minecraft.world.ChunkCache field_72815_e # world
|
||||
Reference in New Issue
Block a user