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();
}
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)));
}
}
}
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);
}
}
}
Aggregations