Search in sources :

Example 1 with ClientboundUpdateMobEffectPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket in project SpongeCommon by SpongePowered.

the class ServerPlayerMixin method impl$postPortalForceChangeTasks.

@Override
protected final void impl$postPortalForceChangeTasks(final Entity entity, final net.minecraft.server.level.ServerLevel targetWorld, final boolean isNetherPortal) {
    // Standard vanilla processing
    this.gameMode.setLevel(targetWorld);
    this.connection.send(new ClientboundPlayerAbilitiesPacket(this.abilities));
    final PlayerList playerlist = this.server.getPlayerList();
    playerlist.sendLevelInfo((net.minecraft.server.level.ServerPlayer) (Object) this, targetWorld);
    playerlist.sendAllPlayerInfo((net.minecraft.server.level.ServerPlayer) (Object) this);
    // Sponge Start: teleport here after all data is sent to avoid any potential "stuttering" due to slow packets.
    final net.minecraft.world.phys.Vec3 finalPos = this.shadow$position();
    this.shadow$moveTo(finalPos.x, finalPos.y, finalPos.z);
    for (final MobEffectInstance effectinstance : this.shadow$getActiveEffects()) {
        this.connection.send(new ClientboundUpdateMobEffectPacket(this.shadow$getId(), effectinstance));
    }
    if (isNetherPortal) {
        // Sponge: only play the sound if we've got a vanilla teleporter that reports a nether portal
        this.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false));
    }
    // Sponge: end if
    this.lastSentExp = -1;
    this.lastSentHealth = -1.0F;
    this.lastSentFood = -1;
}
Also used : ClientboundPlayerAbilitiesPacket(net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket) PlayerList(net.minecraft.server.players.PlayerList) ClientboundLevelEventPacket(net.minecraft.network.protocol.game.ClientboundLevelEventPacket) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ClientboundUpdateMobEffectPacket(net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket)

Example 2 with ClientboundUpdateMobEffectPacket

use of net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket in project SpongeCommon by SpongePowered.

the class EntityUtil method performPostChangePlayerWorldLogic.

public static void performPostChangePlayerWorldLogic(final ServerPlayer player, final ServerLevel fromWorld, final ServerLevel originalToWorld, final ServerLevel toWorld, final boolean isPortal) {
    // Sponge Start - Send any platform dimension data
    ((ServerPlayerBridge) player).bridge$sendDimensionData(player.connection.connection, toWorld.dimensionType(), toWorld.dimension());
    // Sponge End
    final LevelData worldinfo = toWorld.getLevelData();
    // We send dimension change for portals before loading chunks
    if (!isPortal) {
        // Sponge Start - Allow the platform to handle how dimension changes are sent down
        ((ServerPlayerBridge) player).bridge$sendChangeDimension(toWorld.dimensionType(), toWorld.dimension(), BiomeManager.obfuscateSeed(toWorld.getSeed()), player.gameMode.getGameModeForPlayer(), player.gameMode.getPreviousGameModeForPlayer(), toWorld.isDebug(), toWorld.isFlat(), true);
    }
    // Sponge End
    player.connection.send(new ClientboundChangeDifficultyPacket(worldinfo.getDifficulty(), worldinfo.isDifficultyLocked()));
    final PlayerList playerlist = player.getServer().getPlayerList();
    playerlist.sendPlayerPermissionLevel(player);
    // Sponge Start - Have the platform handle removing the entity from the world. Move this to after the event call so
    // that we do not remove the player from the world unless we really have teleported..
    ((PlatformServerLevelBridge) fromWorld).bridge$removeEntity(player, true);
    ((PlatformEntityBridge) player).bridge$revive();
    // Sponge End
    player.setLevel(toWorld);
    toWorld.addDuringPortalTeleport(player);
    if (isPortal) {
        ((ServerPlayerAccessor) player).invoker$triggerDimensionChangeTriggers(toWorld);
    }
    player.gameMode.setLevel(toWorld);
    player.connection.send(new ClientboundPlayerAbilitiesPacket(player.abilities));
    playerlist.sendLevelInfo(player, toWorld);
    playerlist.sendAllPlayerInfo(player);
    for (final MobEffectInstance effectinstance : player.getActiveEffects()) {
        player.connection.send(new ClientboundUpdateMobEffectPacket(player.getId(), effectinstance));
    }
    if (isPortal) {
        player.connection.send(new ClientboundLevelEventPacket(1032, BlockPos.ZERO, 0, false));
    }
    ((ServerLevelBridge) fromWorld).bridge$getBossBarManager().onPlayerDisconnect(player);
    ((ServerLevelBridge) toWorld).bridge$getBossBarManager().onPlayerDisconnect(player);
    ((ServerPlayerAccessor) player).accessor$lastSentExp(-1);
    ((ServerPlayerAccessor) player).accessor$lastSentHealth(-1.0f);
    ((ServerPlayerAccessor) player).accessor$lastSentFood(-1);
    if (!isPortal) {
        player.connection.teleport(player.getX(), player.getY(), player.getZ(), player.yRot, player.xRot);
        player.connection.resetPosition();
    }
    if (player.containerMenu != player.inventoryMenu) {
        player.closeContainer();
    }
    // Sponge Start - Call event
    Sponge.eventManager().post(SpongeEventFactory.createChangeEntityWorldEventPost(PhaseTracker.getCauseStackManager().currentCause(), (org.spongepowered.api.entity.Entity) player, (ServerWorld) fromWorld, (ServerWorld) originalToWorld, (ServerWorld) toWorld));
// Sponge End
}
Also used : Entity(net.minecraft.world.entity.Entity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) PlatformServerLevelBridge(org.spongepowered.common.bridge.world.level.PlatformServerLevelBridge) PlayerList(net.minecraft.server.players.PlayerList) ClientboundLevelEventPacket(net.minecraft.network.protocol.game.ClientboundLevelEventPacket) MobEffectInstance(net.minecraft.world.effect.MobEffectInstance) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) ClientboundUpdateMobEffectPacket(net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket) PlatformEntityBridge(org.spongepowered.common.bridge.world.entity.PlatformEntityBridge) ServerPlayerBridge(org.spongepowered.common.bridge.server.level.ServerPlayerBridge) ServerWorld(org.spongepowered.api.world.server.ServerWorld) ClientboundPlayerAbilitiesPacket(net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket) ServerPlayerAccessor(org.spongepowered.common.accessor.server.level.ServerPlayerAccessor) LevelData(net.minecraft.world.level.storage.LevelData)

Aggregations

ClientboundLevelEventPacket (net.minecraft.network.protocol.game.ClientboundLevelEventPacket)2 ClientboundPlayerAbilitiesPacket (net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket)2 ClientboundUpdateMobEffectPacket (net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket)2 PlayerList (net.minecraft.server.players.PlayerList)2 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)2 ClientboundChangeDifficultyPacket (net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket)1 Entity (net.minecraft.world.entity.Entity)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 LevelData (net.minecraft.world.level.storage.LevelData)1 ServerWorld (org.spongepowered.api.world.server.ServerWorld)1 ServerPlayerAccessor (org.spongepowered.common.accessor.server.level.ServerPlayerAccessor)1 ServerPlayerBridge (org.spongepowered.common.bridge.server.level.ServerPlayerBridge)1 PlatformEntityBridge (org.spongepowered.common.bridge.world.entity.PlatformEntityBridge)1 PlatformServerLevelBridge (org.spongepowered.common.bridge.world.level.PlatformServerLevelBridge)1