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