Search in sources :

Example 1 with ClientboundChangeDifficultyPacket

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

the class PrimaryLevelDataMixin method impl$updateWorldForDifficultyChange.

void impl$updateWorldForDifficultyChange(final ServerLevel world, final boolean isLocked) {
    if (world == null) {
        return;
    }
    final MinecraftServer server = world.getServer();
    final Difficulty difficulty = ((LevelData) this).getDifficulty();
    if (difficulty == Difficulty.HARD) {
        world.setSpawnSettings(true, true);
    } else if (server.isSingleplayer()) {
        world.setSpawnSettings(difficulty != Difficulty.PEACEFUL, true);
    } else {
        world.setSpawnSettings(((MinecraftServerAccessor) server).invoker$isSpawningMonsters(), server.isSpawningAnimals());
    }
    world.players().forEach(player -> player.connection.send(new ClientboundChangeDifficultyPacket(difficulty, isLocked)));
}
Also used : MinecraftServerAccessor(org.spongepowered.common.accessor.server.MinecraftServerAccessor) Difficulty(net.minecraft.world.Difficulty) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) PrimaryLevelData(net.minecraft.world.level.storage.PrimaryLevelData) ServerLevelData(net.minecraft.world.level.storage.ServerLevelData) LevelData(net.minecraft.world.level.storage.LevelData) MinecraftServer(net.minecraft.server.MinecraftServer)

Example 2 with ClientboundChangeDifficultyPacket

use of net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket 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)

Example 3 with ClientboundChangeDifficultyPacket

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

the class DifficultyCommandMixin method setDifficulty.

// @formatter:on
/**
 * @author Zidane
 * @reason Only apply difficulty for the world the command was ran in (as in Sponge, all worlds have difficulties)
 */
@Overwrite
public static int setDifficulty(CommandSourceStack source, Difficulty difficulty) throws CommandSyntaxException {
    if (source.getLevel().getDifficulty() == difficulty) {
        throw DifficultyCommandMixin.ERROR_ALREADY_DIFFICULT.create(difficulty.getKey());
    } else {
        final LevelData levelData = source.getLevel().getLevelData();
        ((ServerWorldProperties) levelData).setDifficulty((org.spongepowered.api.world.difficulty.Difficulty) (Object) difficulty);
        source.getLevel().setSpawnSettings(((MinecraftServerAccessor) SpongeCommon.server()).invoker$isSpawningMonsters(), SpongeCommon.server().isSpawningAnimals());
        source.getLevel().getPlayers(p -> true).forEach(p -> p.connection.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked())));
        source.sendSuccess(new TranslatableComponent("commands.difficulty.success", difficulty.getDisplayName()), true);
        return 0;
    }
}
Also used : CommandSourceStack(net.minecraft.commands.CommandSourceStack) MinecraftServerAccessor(org.spongepowered.common.accessor.server.MinecraftServerAccessor) Overwrite(org.spongepowered.asm.mixin.Overwrite) SpongeCommon(org.spongepowered.common.SpongeCommon) Final(org.spongepowered.asm.mixin.Final) ServerWorldProperties(org.spongepowered.api.world.server.storage.ServerWorldProperties) LevelData(net.minecraft.world.level.storage.LevelData) Mixin(org.spongepowered.asm.mixin.Mixin) DynamicCommandExceptionType(com.mojang.brigadier.exceptions.DynamicCommandExceptionType) Shadow(org.spongepowered.asm.mixin.Shadow) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) DifficultyCommand(net.minecraft.server.commands.DifficultyCommand) CommandSyntaxException(com.mojang.brigadier.exceptions.CommandSyntaxException) Difficulty(net.minecraft.world.Difficulty) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ServerWorldProperties(org.spongepowered.api.world.server.storage.ServerWorldProperties) TranslatableComponent(net.minecraft.network.chat.TranslatableComponent) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) LevelData(net.minecraft.world.level.storage.LevelData) Overwrite(org.spongepowered.asm.mixin.Overwrite)

Example 4 with ClientboundChangeDifficultyPacket

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

the class ServerPlayerMixin method impl$prepareForPortalTeleport.

@Override
protected final void impl$prepareForPortalTeleport(final ServerLevel currentWorld, final ServerLevel targetWorld) {
    final LevelData levelData = targetWorld.getLevelData();
    this.connection.send(new ClientboundRespawnPacket(targetWorld.dimensionType(), targetWorld.dimension(), BiomeManager.obfuscateSeed(targetWorld.getSeed()), this.gameMode.getGameModeForPlayer(), this.gameMode.getPreviousGameModeForPlayer(), targetWorld.isDebug(), targetWorld.isFlat(), true));
    this.connection.send(new ClientboundChangeDifficultyPacket(levelData.getDifficulty(), levelData.isDifficultyLocked()));
    final PlayerList playerlist = this.server.getPlayerList();
    playerlist.sendPlayerPermissionLevel((net.minecraft.server.level.ServerPlayer) (Object) this);
    currentWorld.removePlayerImmediately((net.minecraft.server.level.ServerPlayer) (Object) this);
    this.removed = false;
}
Also used : PlayerList(net.minecraft.server.players.PlayerList) ClientboundRespawnPacket(net.minecraft.network.protocol.game.ClientboundRespawnPacket) ClientboundChangeDifficultyPacket(net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket) LevelData(net.minecraft.world.level.storage.LevelData)

Aggregations

ClientboundChangeDifficultyPacket (net.minecraft.network.protocol.game.ClientboundChangeDifficultyPacket)4 LevelData (net.minecraft.world.level.storage.LevelData)4 PlayerList (net.minecraft.server.players.PlayerList)2 Difficulty (net.minecraft.world.Difficulty)2 MinecraftServerAccessor (org.spongepowered.common.accessor.server.MinecraftServerAccessor)2 CommandSyntaxException (com.mojang.brigadier.exceptions.CommandSyntaxException)1 DynamicCommandExceptionType (com.mojang.brigadier.exceptions.DynamicCommandExceptionType)1 CommandSourceStack (net.minecraft.commands.CommandSourceStack)1 TranslatableComponent (net.minecraft.network.chat.TranslatableComponent)1 ClientboundLevelEventPacket (net.minecraft.network.protocol.game.ClientboundLevelEventPacket)1 ClientboundPlayerAbilitiesPacket (net.minecraft.network.protocol.game.ClientboundPlayerAbilitiesPacket)1 ClientboundRespawnPacket (net.minecraft.network.protocol.game.ClientboundRespawnPacket)1 ClientboundUpdateMobEffectPacket (net.minecraft.network.protocol.game.ClientboundUpdateMobEffectPacket)1 MinecraftServer (net.minecraft.server.MinecraftServer)1 DifficultyCommand (net.minecraft.server.commands.DifficultyCommand)1 MobEffectInstance (net.minecraft.world.effect.MobEffectInstance)1 Entity (net.minecraft.world.entity.Entity)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 PrimaryLevelData (net.minecraft.world.level.storage.PrimaryLevelData)1 ServerLevelData (net.minecraft.world.level.storage.ServerLevelData)1