Search in sources :

Example 36 with ChunkCache

use of net.minecraft.world.ChunkCache in project Valkyrien-Warfare-Revamped by ValkyrienWarfare.

the class SurroundingChunkCacheController method updateChunkCache.

public void updateChunkCache() {
    AxisAlignedBB cacheBB = physicsObject.getShipBoundingBox();
    // Check if all those surrounding chunks are loaded
    BlockPos min = new BlockPos(cacheBB.minX, Math.max(cacheBB.minY, 0), cacheBB.minZ);
    BlockPos max = new BlockPos(cacheBB.maxX, Math.min(cacheBB.maxY, 255), cacheBB.maxZ);
    if (!physicsObject.getWorld().isRemote) {
        ChunkProviderServer serverChunkProvider = (ChunkProviderServer) physicsObject.getWorld().getChunkProvider();
        int chunkMinX = min.getX() >> 4;
        int chunkMaxX = max.getX() >> 4;
        int chunkMinZ = min.getZ() >> 4;
        int chunkMaxZ = max.getZ() >> 4;
        boolean areSurroundingChunksLoaded = true;
        outer: for (int chunkX = chunkMinX; chunkX <= chunkMaxX; chunkX++) {
            for (int chunkZ = chunkMinZ; chunkZ <= chunkMaxZ; chunkZ++) {
                areSurroundingChunksLoaded = serverChunkProvider.chunkExists(chunkX, chunkZ);
                if (!areSurroundingChunksLoaded) {
                    break outer;
                }
            }
        }
        if (areSurroundingChunksLoaded) {
            cachedChunks = new ChunkCache(physicsObject.getWorld(), min, max, 0);
        }
    } else {
        cachedChunks = new ChunkCache(physicsObject.getWorld(), min, max, 0);
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) ChunkCache(net.minecraft.world.ChunkCache) ChunkProviderServer(net.minecraft.world.gen.ChunkProviderServer) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

ChunkCache (net.minecraft.world.ChunkCache)36 TileEntity (net.minecraft.tileentity.TileEntity)16 BlockPos (net.minecraft.util.math.BlockPos)9 IBlockState (net.minecraft.block.state.IBlockState)8 Block (net.minecraft.block.Block)5 World (net.minecraft.world.World)5 LazyBlockState (com.almuradev.content.type.block.state.LazyBlockState)4 WeightedLazyBlockState (com.almuradev.content.util.WeightedLazyBlockState)4 ArrayList (java.util.ArrayList)4 BlockBush (net.minecraft.block.BlockBush)4 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)4 IBlockAccess (net.minecraft.world.IBlockAccess)4 TIntArrayList (gnu.trove.list.array.TIntArrayList)3 BlockCactus (net.minecraft.block.BlockCactus)3 ItemStack (net.minecraft.item.ItemStack)3 PathEntity (net.minecraft.pathfinding.PathEntity)3 PathPoint (net.minecraft.pathfinding.PathPoint)3 MutableBlockPos (net.minecraft.util.math.BlockPos.MutableBlockPos)3 Chunk (net.minecraft.world.chunk.Chunk)3 ExtendedBlockStorage (net.minecraft.world.chunk.storage.ExtendedBlockStorage)3