Search in sources :

Example 1 with ChunkDataS2CPacket

use of net.minecraft.client.network.packet.ChunkDataS2CPacket in project ImmersivePortalsMod by qouteall.

the class MixinThreadedAnvilChunkStorage method sendChunkDataPackets.

/**
 * @author qouteall
 */
@Overwrite
private void sendChunkDataPackets(ServerPlayerEntity player, Packet<?>[] packets_1, WorldChunk worldChunk_1) {
    // vanilla will not manage interdimensional chunk loading
    if (player.dimension != world.dimension.getType()) {
        return;
    }
    DimensionalChunkPos chunkPos = new DimensionalChunkPos(world.dimension.getType(), worldChunk_1.getPos());
    boolean isChunkDataSent = SGlobal.chunkTrackingGraph.isChunkDataSent(player, chunkPos);
    if (isChunkDataSent) {
        return;
    }
    ModMain.serverTaskList.addTask(() -> {
        SGlobal.chunkTrackingGraph.onChunkDataSent(player, chunkPos);
        return true;
    });
    if (packets_1[0] == null) {
        packets_1[0] = MyNetwork.createRedirectedMessage(world.dimension.getType(), new ChunkDataS2CPacket(worldChunk_1, 65535));
        packets_1[1] = MyNetwork.createRedirectedMessage(world.dimension.getType(), new LightUpdateS2CPacket(worldChunk_1.getPos(), this.serverLightingProvider));
    }
    player.sendInitialChunkPackets(worldChunk_1.getPos(), packets_1[0], packets_1[1]);
    DebugRendererInfoManager.method_19775(this.world, worldChunk_1.getPos());
    List<Entity> list_1 = Lists.newArrayList();
    List<Entity> list_2 = Lists.newArrayList();
    ObjectIterator var6 = this.entityTrackers.values().iterator();
    while (var6.hasNext()) {
        IEEntityTracker threadedAnvilChunkStorage$EntityTracker_1 = (IEEntityTracker) var6.next();
        Entity entity_1 = threadedAnvilChunkStorage$EntityTracker_1.getEntity_();
        if (entity_1 != player && entity_1.chunkX == worldChunk_1.getPos().x && entity_1.chunkZ == worldChunk_1.getPos().z) {
            threadedAnvilChunkStorage$EntityTracker_1.updateCameraPosition_(player);
            if (entity_1 instanceof MobEntity && ((MobEntity) entity_1).getHoldingEntity() != null) {
                list_1.add(entity_1);
            }
            if (!entity_1.getPassengerList().isEmpty()) {
                list_2.add(entity_1);
            }
        }
    }
    Iterator var9;
    Entity entity_3;
    if (!list_1.isEmpty()) {
        var9 = list_1.iterator();
        while (var9.hasNext()) {
            entity_3 = (Entity) var9.next();
            player.networkHandler.sendPacket(MyNetwork.createRedirectedMessage(world.getDimension().getType(), new EntityAttachS2CPacket(entity_3, ((MobEntity) entity_3).getHoldingEntity())));
        }
    }
    if (!list_2.isEmpty()) {
        var9 = list_2.iterator();
        while (var9.hasNext()) {
            entity_3 = (Entity) var9.next();
            player.networkHandler.sendPacket(MyNetwork.createRedirectedMessage(world.getDimension().getType(), new EntityPassengersSetS2CPacket(entity_3)));
        }
    }
}
Also used : MobEntity(net.minecraft.entity.mob.MobEntity) Entity(net.minecraft.entity.Entity) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) IEEntityTracker(com.qouteall.immersive_portals.ducks.IEEntityTracker) DimensionalChunkPos(com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos) EntityPassengersSetS2CPacket(net.minecraft.client.network.packet.EntityPassengersSetS2CPacket) LightUpdateS2CPacket(net.minecraft.client.network.packet.LightUpdateS2CPacket) ChunkDataS2CPacket(net.minecraft.client.network.packet.ChunkDataS2CPacket) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) Iterator(java.util.Iterator) EntityAttachS2CPacket(net.minecraft.client.network.packet.EntityAttachS2CPacket) MobEntity(net.minecraft.entity.mob.MobEntity) ObjectIterator(it.unimi.dsi.fastutil.objects.ObjectIterator) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 2 with ChunkDataS2CPacket

use of net.minecraft.client.network.packet.ChunkDataS2CPacket 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)

Aggregations

ChunkDataS2CPacket (net.minecraft.client.network.packet.ChunkDataS2CPacket)2 LightUpdateS2CPacket (net.minecraft.client.network.packet.LightUpdateS2CPacket)2 DimensionalChunkPos (com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos)1 IEEntityTracker (com.qouteall.immersive_portals.ducks.IEEntityTracker)1 IEThreadedAnvilChunkStorage (com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)1 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)1 Iterator (java.util.Iterator)1 EntityAttachS2CPacket (net.minecraft.client.network.packet.EntityAttachS2CPacket)1 EntityPassengersSetS2CPacket (net.minecraft.client.network.packet.EntityPassengersSetS2CPacket)1 Entity (net.minecraft.entity.Entity)1 MobEntity (net.minecraft.entity.mob.MobEntity)1 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)1 ThreadedAnvilChunkStorage (net.minecraft.server.world.ThreadedAnvilChunkStorage)1 Chunk (net.minecraft.world.chunk.Chunk)1 EmptyChunk (net.minecraft.world.chunk.EmptyChunk)1 WorldChunk (net.minecraft.world.chunk.WorldChunk)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1