Search in sources :

Example 1 with Frustum

use of net.minecraft.client.render.Frustum in project sodium-fabric by CaffeineMC.

the class ChunkGraph method init.

private boolean init(BlockPos blockPos, Camera camera, Vec3d cameraPos, Frustum frustum, int frame, boolean spectator) {
    MinecraftClient client = MinecraftClient.getInstance();
    ObjectArrayFIFOQueue<ChunkGraphNode<T>> queue = this.iterationQueue;
    boolean cull = client.chunkCullingEnabled;
    ChunkGraphNode<T> node = this.getOrCreateNode(blockPos);
    if (node != null) {
        node.reset();
        // Player is within bounds and inside a node
        Set<Direction> openFaces = this.getOpenChunkFaces(blockPos);
        if (openFaces.size() == 1) {
            Vector3f vector3f = camera.getHorizontalPlane();
            Direction direction = Direction.getFacing(vector3f.getX(), vector3f.getY(), vector3f.getZ()).getOpposite();
            openFaces.remove(direction);
        }
        if (openFaces.isEmpty() && !spectator) {
            this.visibleNodes.add(node);
        } else {
            if (spectator && this.world.getBlockState(blockPos).isFullOpaque(this.world, blockPos)) {
                cull = false;
            }
            node.setRebuildFrame(frame);
            queue.enqueue(node);
        }
    } else {
        // Player is out-of-bounds
        int y = blockPos.getY() > 0 ? 248 : 8;
        int x = MathHelper.floor(cameraPos.x / 16.0D) * 16;
        int z = MathHelper.floor(cameraPos.z / 16.0D) * 16;
        List<ChunkGraphNode<T>> list = Lists.newArrayList();
        for (int x2 = -this.renderDistance; x2 <= this.renderDistance; ++x2) {
            for (int z2 = -this.renderDistance; z2 <= this.renderDistance; ++z2) {
                ChunkGraphNode<T> chunk = this.getOrCreateNode(new BlockPos(x + (x2 << 4) + 8, y, z + (z2 << 4) + 8));
                if (chunk == null) {
                    continue;
                }
                if (frustum.isVisible(chunk.getBoundingBox())) {
                    chunk.setRebuildFrame(frame);
                    chunk.reset();
                    list.add(chunk);
                }
            }
        }
        list.sort(Comparator.comparingDouble(o -> blockPos.getSquaredDistance(o.chunk.getOrigin().add(8, 8, 8))));
        for (ChunkGraphNode<T> n : list) {
            queue.enqueue(n);
        }
    }
    return cull;
}
Also used : ChunkOcclusionDataBuilder(net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder) SodiumGameOptions(me.jellysquid.mods.sodium.client.gui.SodiumGameOptions) SodiumClientMod(me.jellysquid.mods.sodium.client.SodiumClientMod) net.minecraft.util.math(net.minecraft.util.math) World(net.minecraft.world.World) ObjectArrayList(it.unimi.dsi.fastutil.objects.ObjectArrayList) Set(java.util.Set) ChunkSection(net.minecraft.world.chunk.ChunkSection) DirectionUtil(me.jellysquid.mods.sodium.common.util.DirectionUtil) WorldChunk(net.minecraft.world.chunk.WorldChunk) List(java.util.List) Lists(com.google.common.collect.Lists) Frustum(net.minecraft.client.render.Frustum) Long2ObjectOpenHashMap(it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap) Vector3f(net.minecraft.client.util.math.Vector3f) ObjectArrayFIFOQueue(it.unimi.dsi.fastutil.objects.ObjectArrayFIFOQueue) MinecraftClient(net.minecraft.client.MinecraftClient) BlockState(net.minecraft.block.BlockState) Comparator(java.util.Comparator) ObjectList(it.unimi.dsi.fastutil.objects.ObjectList) EnumSet(java.util.EnumSet) Camera(net.minecraft.client.render.Camera) MinecraftClient(net.minecraft.client.MinecraftClient) Vector3f(net.minecraft.client.util.math.Vector3f)

Aggregations

Lists (com.google.common.collect.Lists)1 Long2ObjectOpenHashMap (it.unimi.dsi.fastutil.longs.Long2ObjectOpenHashMap)1 ObjectArrayFIFOQueue (it.unimi.dsi.fastutil.objects.ObjectArrayFIFOQueue)1 ObjectArrayList (it.unimi.dsi.fastutil.objects.ObjectArrayList)1 ObjectList (it.unimi.dsi.fastutil.objects.ObjectList)1 Comparator (java.util.Comparator)1 EnumSet (java.util.EnumSet)1 List (java.util.List)1 Set (java.util.Set)1 SodiumClientMod (me.jellysquid.mods.sodium.client.SodiumClientMod)1 SodiumGameOptions (me.jellysquid.mods.sodium.client.gui.SodiumGameOptions)1 DirectionUtil (me.jellysquid.mods.sodium.common.util.DirectionUtil)1 BlockState (net.minecraft.block.BlockState)1 MinecraftClient (net.minecraft.client.MinecraftClient)1 Camera (net.minecraft.client.render.Camera)1 Frustum (net.minecraft.client.render.Frustum)1 ChunkOcclusionDataBuilder (net.minecraft.client.render.chunk.ChunkOcclusionDataBuilder)1 Vector3f (net.minecraft.client.util.math.Vector3f)1 net.minecraft.util.math (net.minecraft.util.math)1 World (net.minecraft.world.World)1