Search in sources :

Example 1 with DimensionalChunkPos

use of com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos in project ImmersivePortalsMod by qouteall.

the class MixinServerPlayerEntity method onSendUnloadChunkPacket.

@Inject(method = "Lnet/minecraft/server/network/ServerPlayerEntity;sendUnloadChunkPacket(Lnet/minecraft/util/math/ChunkPos;)V", at = @At("HEAD"), cancellable = true)
private void onSendUnloadChunkPacket(ChunkPos chunkPos_1, CallbackInfo ci) {
    ServerPlayerEntity this_ = (ServerPlayerEntity) (Object) this;
    DimensionalChunkPos dimensionalChunkPos = new DimensionalChunkPos(this_.dimension, chunkPos_1);
    SGlobal.chunkDataSyncManager.sendUnloadPacket(this_, dimensionalChunkPos);
    ci.cancel();
}
Also used : DimensionalChunkPos(com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos) ServerPlayerEntity(net.minecraft.server.network.ServerPlayerEntity) IEServerPlayerEntity(com.qouteall.immersive_portals.ducks.IEServerPlayerEntity) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 2 with DimensionalChunkPos

use of com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos 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 3 with DimensionalChunkPos

use of com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos 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

DimensionalChunkPos (com.qouteall.immersive_portals.chunk_loading.DimensionalChunkPos)3 ServerPlayerEntity (net.minecraft.server.network.ServerPlayerEntity)2 IEEntityTracker (com.qouteall.immersive_portals.ducks.IEEntityTracker)1 IEServerPlayerEntity (com.qouteall.immersive_portals.ducks.IEServerPlayerEntity)1 IEThreadedAnvilChunkStorage (com.qouteall.immersive_portals.ducks.IEThreadedAnvilChunkStorage)1 ObjectIterator (it.unimi.dsi.fastutil.objects.ObjectIterator)1 Iterator (java.util.Iterator)1 ChunkDataS2CPacket (net.minecraft.client.network.packet.ChunkDataS2CPacket)1 EntityAttachS2CPacket (net.minecraft.client.network.packet.EntityAttachS2CPacket)1 EntityPassengersSetS2CPacket (net.minecraft.client.network.packet.EntityPassengersSetS2CPacket)1 LightUpdateS2CPacket (net.minecraft.client.network.packet.LightUpdateS2CPacket)1 Entity (net.minecraft.entity.Entity)1 MobEntity (net.minecraft.entity.mob.MobEntity)1 ChunkHolder (net.minecraft.server.world.ChunkHolder)1 ChunkPos (net.minecraft.util.math.ChunkPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 Overwrite (org.spongepowered.asm.mixin.Overwrite)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1