Search in sources :

Example 6 with IEThreadedAnvilChunkStorage

use of com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage in project ImmersivePortalsMod by qouteall.

the class MixinEntityTracker method updateCameraPosition_.

@Override
public void updateCameraPosition_(ServerPlayerEntity player) {
    IEThreadedAnvilChunkStorage storage = McHelper.getIEStorage(entity.dimension);
    if (player != this.entity) {
        Vec3d relativePos = (new Vec3d(player.x, player.y, player.z)).subtract(this.entry.method_18759());
        int maxWatchDistance = Math.min(this.maxDistance, (storage.getWatchDistance() - 1) * 16);
        boolean isWatchedNow = player.dimension == entity.dimension && relativePos.x >= (double) (-maxWatchDistance) && relativePos.x <= (double) maxWatchDistance && relativePos.z >= (double) (-maxWatchDistance) && relativePos.z <= (double) maxWatchDistance && this.entity.canBeSpectated(player);
        isWatchedNow = isWatchedNow || SGlobal.chunkTrackingGraph.isPlayerWatchingChunk(player, new DimensionalChunkPos(entity.dimension, new ChunkPos(entity.getBlockPos())));
        if (isWatchedNow) {
            boolean shouldTrack = this.entity.teleporting;
            if (!shouldTrack) {
                ChunkPos chunkPos_1 = new ChunkPos(this.entity.chunkX, this.entity.chunkZ);
                ChunkHolder chunkHolder_1 = storage.getChunkHolder_(chunkPos_1.toLong());
                if (chunkHolder_1 != null && chunkHolder_1.getWorldChunk() != null) {
                    shouldTrack = true;
                }
            // else {
            // retry it next tick
            // ModMain.serverTaskList.addTask(() -> {
            // Helper.log("Retry tracking player " + player.getName());
            // updateCameraPosition_(player);
            // return true;
            // });
            // }
            }
            if (shouldTrack && this.playersTracking.add(player)) {
                this.entry.startTracking(player);
            }
        } else if (this.playersTracking.remove(player)) {
            this.entry.stopTracking(player);
        }
    }
}
Also used : DimensionalChunkPos(com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos) ChunkHolder(net.minecraft.server.world.ChunkHolder) IEThreadedAnvilChunkStorage(com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage) ChunkPos(net.minecraft.util.math.ChunkPos) DimensionalChunkPos(com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

IEThreadedAnvilChunkStorage (com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)6 ChunkHolder (net.minecraft.server.world.ChunkHolder)2 ThreadedAnvilChunkStorage (net.minecraft.server.world.ThreadedAnvilChunkStorage)2 Either (com.mojang.datafixers.util.Either)1 DimensionalChunkPos (com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos)1 ChunkDataS2CPacket (net.minecraft.client.network.packet.ChunkDataS2CPacket)1 LightUpdateS2CPacket (net.minecraft.client.network.packet.LightUpdateS2CPacket)1 ServerChunkManager (net.minecraft.server.world.ServerChunkManager)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 Chunk (net.minecraft.world.chunk.Chunk)1 EmptyChunk (net.minecraft.world.chunk.EmptyChunk)1 WorldChunk (net.minecraft.world.chunk.WorldChunk)1 DimensionType (net.minecraft.world.dimension.DimensionType)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1