本文整理汇总了Java中net.minecraft.server.management.PlayerList.updateTimeAndWeatherForPlayer方法的典型用法代码示例。如果您正苦于以下问题:Java PlayerList.updateTimeAndWeatherForPlayer方法的具体用法?Java PlayerList.updateTimeAndWeatherForPlayer怎么用?Java PlayerList.updateTimeAndWeatherForPlayer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.minecraft.server.management.PlayerList
的用法示例。
在下文中一共展示了PlayerList.updateTimeAndWeatherForPlayer方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: teleportPlayerToDim
import net.minecraft.server.management.PlayerList; //导入方法依赖的package包/类
private Entity teleportPlayerToDim(World oldWorld, int newWorldID, double d, double e, double f, Entity entity)
{
MinecraftServer server = entity.getServer();
WorldServer oldWorldServer = server.worldServerForDimension(entity.dimension);
WorldServer newWorldServer = server.worldServerForDimension(newWorldID);
if (entity instanceof EntityPlayer) {
EntityPlayerMP player = (EntityPlayerMP) entity;
if (!player.worldObj.isRemote) {
player.worldObj.theProfiler.startSection("portal");
player.worldObj.theProfiler.startSection("changeDimension");
PlayerList config = player.mcServer.getPlayerList();
player.closeScreen();
player.dimension = newWorldServer.provider.getDimension();
player.playerNetServerHandler.sendPacket(new SPacketRespawn(player.dimension, player.worldObj.getDifficulty(), newWorldServer.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
oldWorldServer.removeEntity(player);
player.isDead = false;
player.setLocationAndAngles(d, e, f, player.rotationYaw, player.rotationPitch);
newWorldServer.spawnEntityInWorld(player);
player.setWorld(newWorldServer);
config.preparePlayer(player, oldWorldServer);
player.playerNetServerHandler.setPlayerLocation(d, e, f, entity.rotationYaw, entity.rotationPitch);
player.interactionManager.setWorld(newWorldServer);
config.updateTimeAndWeatherForPlayer(player, newWorldServer);
config.syncPlayerInventory(player);
player.worldObj.theProfiler.endSection();
oldWorldServer.resetUpdateEntityTick();
newWorldServer.resetUpdateEntityTick();
player.worldObj.theProfiler.endSection();
for (PotionEffect potionEffect : player.getActivePotionEffects()) {
player.playerNetServerHandler.sendPacket(new SPacketEntityEffect(player.getEntityId(), potionEffect));
}
player.playerNetServerHandler.sendPacket(new SPacketSetExperience(player.experience, player.experienceTotal, player.experienceLevel));
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldWorldServer.provider.getDimension(), player.dimension);
}
player.worldObj.theProfiler.endSection();
return player;
}
return null;
}
示例2: transferPlayerToDimension
import net.minecraft.server.management.PlayerList; //导入方法依赖的package包/类
private static void transferPlayerToDimension(PlayerList playerList, net.minecraft.entity.player.EntityPlayerMP player, int dimension, Teleporter teleporter) {
int i = player.dimension;
WorldServer worldserver = playerList.getServerInstance().getWorld(player.dimension);
player.dimension = dimension;
WorldServer worldserver1 = playerList.getServerInstance().getWorld(player.dimension);
player.connection.sendPacket(new SPacketRespawn(player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
//MoreCommands Bug fix: client world has wrong spawn position, because WorldClient is recreated after receiving S07PacketRespawn
//with default spawn coordinates 8, 64, 8. This causes e.g. the compass to point to a wrong direction. A possible solution is sending a S05PacketSpawnPosition.
//Fixes https://bugs.mojang.com/browse/MC-679
player.connection.sendPacket(new SPacketSpawnPosition(new BlockPos(worldserver1.getWorldInfo().getSpawnX(), worldserver1.getWorldInfo().getSpawnY(), worldserver1.getWorldInfo().getSpawnZ())));
playerList.updatePermissionLevel(player);
worldserver.removeEntityDangerously(player);
player.isDead = false;
playerList.transferEntityToWorld(player, i, worldserver, worldserver1, teleporter);
playerList.preparePlayer(player, worldserver);
player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
player.interactionManager.setWorld(worldserver1);
player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
playerList.updateTimeAndWeatherForPlayer(player, worldserver1);
playerList.syncPlayerInventory(player);
for (PotionEffect potioneffect : player.getActivePotionEffects())
{
player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
}
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, i, dimension);
}
示例3: transferPlayerToDimension
import net.minecraft.server.management.PlayerList; //导入方法依赖的package包/类
static void transferPlayerToDimension(EntityPlayerMP player, int dimensionTo, int targetHeight)
{
if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimensionTo)) { return; } // Moving that here, to consolidate these functions.
net.minecraft.world.Teleporter teleporter = player.mcServer.worldServerForDimension(dimensionTo).getDefaultTeleporter();
PlayerList playerList = player.mcServer.getPlayerList();
int dimensionFrom = player.dimension;
// Changing dimensions...
WorldServer wsPrev = player.mcServer.worldServerForDimension(player.dimension);
player.dimension = dimensionTo;
WorldServer wsNew = player.mcServer.worldServerForDimension(player.dimension);
// Respawn? Used to recreate the player entity.
player.connection.sendPacket(new SPacketRespawn(player.dimension, wsNew.getDifficulty(), wsNew.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
// Capabilities...
playerList.updatePermissionLevel(player);
// Begone from the old world?
wsPrev.removeEntity(player);
// Safety, I suppose.
player.isDead = false;
// We haven't reached the "set portal" level yet. Going deeper.
transferEntityToWorld(player, dimensionFrom, wsPrev, wsNew, teleporter, targetHeight);
// Getting chunks ready?
playerList.preparePlayer(player, wsPrev);
// Inserting their new position here? May not be necessary, since this is called by the drop and transfer, which sets the position beforehand and afterwards.
player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
// More formalities...
player.interactionManager.setWorld(wsNew);
player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
playerList.updateTimeAndWeatherForPlayer(player, wsNew);
playerList.syncPlayerInventory(player);
// Reapplying potion effects
for (PotionEffect potioneffect : player.getActivePotionEffects())
{
player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
}
// We're done.
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, dimensionFrom, dimensionTo);
}
示例4: teleportPlayerToDim
import net.minecraft.server.management.PlayerList; //导入方法依赖的package包/类
private static EntityPlayer teleportPlayerToDim(EntityPlayerMP player, MinecraftServer server, int sourceDim, int targetDim, double xCoord, double yCoord, double zCoord, float yaw, float pitch, Vector3d motion) {
WorldServer sourceWorld = server.worldServerForDimension(sourceDim);
WorldServer targetWorld = server.worldServerForDimension(targetDim);
PlayerList playerList = server.getPlayerList();
player.dimension = targetDim;
player.connection.sendPacket(new SPacketRespawn(player.dimension, targetWorld.getDifficulty(), targetWorld.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
playerList.updatePermissionLevel(player);
sourceWorld.removeEntityDangerously(player);
player.isDead = false;
//region Transfer to world
player.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
player.connection.setPlayerLocation(xCoord, yCoord, zCoord, yaw, pitch);
targetWorld.spawnEntity(player);
targetWorld.updateEntityWithOptionalForce(player, false);
player.setWorld(targetWorld);
//endregion
playerList.preparePlayer(player, sourceWorld);
player.connection.setPlayerLocation(xCoord, yCoord, zCoord, yaw, pitch);
player.interactionManager.setWorld(targetWorld);
player.connection.sendPacket(new SPacketPlayerAbilities(player.capabilities));
playerList.updateTimeAndWeatherForPlayer(player, targetWorld);
playerList.syncPlayerInventory(player);
for (PotionEffect potioneffect : player.getActivePotionEffects()) {
player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
}
net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, sourceDim, targetDim);
player.setLocationAndAngles(xCoord, yCoord, zCoord, yaw, pitch);
player.motionX += motion.x; player.motionY += motion.y; player.motionZ += motion.z;
NBTTagCompound nbt = new NBTTagCompound();
nbt.setDouble("X", motion.x);
nbt.setDouble("Y", motion.y);
nbt.setDouble("Z", motion.z);
CrystalModNetwork.sendToAll(new PacketEntityMessage(player, "AddMotion", nbt));
return player;
}
示例5: transferPlayerToDimension
import net.minecraft.server.management.PlayerList; //导入方法依赖的package包/类
/**
* Transfers a player to a different dimension and location, as if they were being teleported by a dimension portal
*/
private static boolean transferPlayerToDimension(EntityPlayerMP player, double posX, double posY, double posZ, float yaw, float pitch, int dimension)
{
MinecraftServer minecraftServer = FMLCommonHandler.instance().getMinecraftServerInstance();
WorldServer srcWorld = minecraftServer.worldServerForDimension(player.dimension);
WorldServer dstWorld = minecraftServer.worldServerForDimension(dimension);
if(dstWorld != null)
{
// fire player change dimension event and check that action is valid before continuing
if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimension)) return false;
// (hard) set the player's dimension to the destination dimension
player.dimension = dimension;
// send a player respawn packet to the destination dimension so the player respawns there
player.connection.sendPacket(
new SPacketRespawn(
player.dimension,
player.world.getDifficulty(),
player.world.getWorldInfo().getTerrainType(),
player.interactionManager.getGameType()
)
);
srcWorld.removeEntity(player); // remove the original player entity
player.isDead = false; // make sure the player isn't dead (removeEntity sets player as dead)
PlayerList playerList = player.mcServer.getPlayerList();
// set player's location (net server handler)
setPlayerPosition(player, posX, posY, posZ, yaw, pitch);
// spawn the player in the new world
dstWorld.spawnEntity(player);
// update the entity (do not force)
dstWorld.updateEntityWithOptionalForce(player, false);
// set the player's world to the new world
player.setWorld(dstWorld);
// add the player into the appropriate player list
playerList.preparePlayer(player, srcWorld);
// set item in world manager's world to the same as the player
player.interactionManager.setWorld(dstWorld);
// update time and weather for the player so that it's the same as the world
playerList.updateTimeAndWeatherForPlayer(player, dstWorld);
// sync the player's inventory
playerList.syncPlayerInventory(player);
// add no experience (syncs experience)
player.addExperience(0);
// update player's health
player.setPlayerHealthUpdated();
// fire the dimension changed event so that minecraft swithces dimensions properly
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(
player,
srcWorld.provider.getDimension(),
dstWorld.provider.getDimension()
);
return true;
}
else
{
return false;
}
}
示例6: changeDimension
import net.minecraft.server.management.PlayerList; //导入方法依赖的package包/类
/**
* Changes the dimension a player is in, in a safe way. This will make sure the player is
* teleported to the dimension and all the correct packets are sent to keep the client in
* sync. It also gets around teleporter code which in some cases will crash the server.
*
* @param player The player to change the dimension of.
* @param dimension The dimension to send the player to.
* @param playerData The player data from the server.
*/
public static void changeDimension (EntityPlayerMP player, int dimension, PlayerList playerData) {
if (!net.minecraftforge.common.ForgeHooks.onTravelToDimension(player, dimension)) {
return;
}
final int oldDim = player.dimension;
final boolean wasAlive = player.isEntityAlive();
final WorldServer worldOld = playerData.getServerInstance().getWorld(player.dimension);
final WorldServer worldNew = playerData.getServerInstance().getWorld(dimension);
if (player.isBeingRidden()) {
player.removePassengers();
}
if (player.isRiding()) {
player.dismountRidingEntity();
}
player.dimension = dimension;
player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
worldOld.removeEntityDangerously(player);
EntityUtils.changeWorld(player, worldOld, worldNew);
playerData.preparePlayer(player, worldOld);
player.connection.setPlayerLocation(player.posX, player.posY, player.posZ, player.rotationYaw, player.rotationPitch);
player.interactionManager.setWorld(worldNew);
playerData.updateTimeAndWeatherForPlayer(player, worldNew);
playerData.syncPlayerInventory(player);
if (player.isDead && wasAlive) {
player.isDead = false;
}
for (final PotionEffect potioneffect : player.getActivePotionEffects()) {
player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
}
FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, oldDim, dimension);
}