Search in sources :

Example 1 with IEThreadedAnvilChunkStorage

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

the class ChunkDataSyncManager method onBeginWatch.

/**
 * {@link ThreadedAnvilChunkStorage#sendChunkDataPackets(ServerPlayerEntity, Packet[], WorldChunk)}
 */
private void onBeginWatch(ServerPlayerEntity player, DimensionalChunkPos chunkPos) {
    if (isChunkManagedByVanilla(player, chunkPos)) {
        return;
    }
    if (SGlobal.chunkTrackingGraph.isChunkDataSent(player, chunkPos)) {
        return;
    }
    McHelper.getServer().getProfiler().push("begin_watch");
    SGlobal.chunkTrackingGraph.onChunkDataSent(player, chunkPos);
    IEThreadedAnvilChunkStorage ieStorage = McHelper.getIEStorage(chunkPos.dimension);
    if (SGlobal.isChunkLoadingMultiThreaded) {
        sendPacketMultiThreaded(player, chunkPos, ieStorage);
    } else {
        sendPacketNormally(player, chunkPos, ieStorage);
    }
    McHelper.getServer().getProfiler().pop();
}
Also used : IEThreadedAnvilChunkStorage(com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)

Example 2 with IEThreadedAnvilChunkStorage

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

the class ChunkDataSyncManager method onPlayerRespawn.

public void onPlayerRespawn(ServerPlayerEntity oldPlayer) {
    SGlobal.chunkTrackingGraph.onPlayerRespawn(oldPlayer);
    McHelper.getServer().getWorlds().forEach(world -> {
        ServerChunkManager chunkManager = (ServerChunkManager) world.getChunkManager();
        IEThreadedAnvilChunkStorage storage = (IEThreadedAnvilChunkStorage) chunkManager.threadedAnvilChunkStorage;
        storage.onPlayerRespawn(oldPlayer);
    });
}
Also used : ServerChunkManager(net.minecraft.server.world.ServerChunkManager) IEThreadedAnvilChunkStorage(com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)

Example 3 with IEThreadedAnvilChunkStorage

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

the class ChunkDataSyncManager method sendPacketMultiThreaded.

private void sendPacketMultiThreaded(ServerPlayerEntity player, DimensionalChunkPos chunkPos, IEThreadedAnvilChunkStorage ieStorage) {
    ModMain.serverTaskList.addTask(() -> {
        ChunkHolder chunkHolder = ieStorage.getChunkHolder_(chunkPos.getChunkPos().toLong());
        if (chunkHolder == null) {
            // TODO cleanup it
            SGlobal.chunkTrackingGraph.setIsLoadedByPortal(chunkPos.dimension, chunkPos.getChunkPos(), true);
            return false;
        }
        CompletableFuture<Either<Chunk, ChunkHolder.Unloaded>> future = chunkHolder.createFuture(ChunkStatus.FULL, ((ThreadedAnvilChunkStorage) ieStorage));
        future.thenAcceptAsync(either -> {
            ModMain.serverTaskList.addTask(() -> {
                sendWatchPackets(player, chunkPos, ieStorage);
                return true;
            });
        });
        return true;
    });
}
Also used : ChunkHolder(net.minecraft.server.world.ChunkHolder) Either(com.mojang.datafixers.util.Either) ThreadedAnvilChunkStorage(net.minecraft.server.world.ThreadedAnvilChunkStorage) IEThreadedAnvilChunkStorage(com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)

Example 4 with IEThreadedAnvilChunkStorage

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

the class ChunkDataSyncManager method sendWatchPackets.

private void sendWatchPackets(ServerPlayerEntity player, DimensionalChunkPos chunkPos, IEThreadedAnvilChunkStorage ieStorage) {
    McHelper.getServer().getProfiler().push("send_chunk_data");
    Chunk chunk = McHelper.getServer().getWorld(chunkPos.dimension).getChunk(chunkPos.x, chunkPos.z);
    assert chunk != null;
    assert !(chunk instanceof EmptyChunk);
    player.networkHandler.sendPacket(MyNetwork.createRedirectedMessage(chunkPos.dimension, new ChunkDataS2CPacket(((WorldChunk) chunk), 65535)));
    player.networkHandler.sendPacket(MyNetwork.createRedirectedMessage(chunkPos.dimension, new LightUpdateS2CPacket(chunkPos.getChunkPos(), ieStorage.getLightingProvider())));
    // update the entity trackers
    ((ThreadedAnvilChunkStorage) ieStorage).updateCameraPosition(player);
    McHelper.getServer().getProfiler().pop();
}
Also used : EmptyChunk(net.minecraft.world.chunk.EmptyChunk) WorldChunk(net.minecraft.world.chunk.WorldChunk) LightUpdateS2CPacket(net.minecraft.client.network.packet.LightUpdateS2CPacket) ChunkDataS2CPacket(net.minecraft.client.network.packet.ChunkDataS2CPacket) ThreadedAnvilChunkStorage(net.minecraft.server.world.ThreadedAnvilChunkStorage) IEThreadedAnvilChunkStorage(com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage) WorldChunk(net.minecraft.world.chunk.WorldChunk) EmptyChunk(net.minecraft.world.chunk.EmptyChunk) Chunk(net.minecraft.world.chunk.Chunk)

Example 5 with IEThreadedAnvilChunkStorage

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

the class MixinChunkHolder method sendPacketToPlayersWatching.

/**
 * @author qouteall
 */
@Overwrite
private void sendPacketToPlayersWatching(Packet<?> packet_1, boolean boolean_1) {
    DimensionType dimension = ((IEThreadedAnvilChunkStorage) playersWatchingChunkProvider).getWorld().dimension.getType();
    Streams.concat(this.playersWatchingChunkProvider.getPlayersWatchingChunk(this.pos, boolean_1), SGlobal.chunkTrackingGraph.getPlayersViewingChunk(dimension, pos)).distinct().forEach(player -> player.networkHandler.sendPacket(MyNetwork.createRedirectedMessage(dimension, packet_1)));
}
Also used : DimensionType(net.minecraft.world.dimension.DimensionType) IEThreadedAnvilChunkStorage(com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage) Overwrite(org.spongepowered.asm.mixin.Overwrite)

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