当前位置: 首页>>代码示例>>Java>>正文


Java SPacketRespawn类代码示例

本文整理汇总了Java中net.minecraft.network.play.server.SPacketRespawn的典型用法代码示例。如果您正苦于以下问题:Java SPacketRespawn类的具体用法?Java SPacketRespawn怎么用?Java SPacketRespawn使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SPacketRespawn类属于net.minecraft.network.play.server包,在下文中一共展示了SPacketRespawn类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transferPlayerToDimension

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
public static void transferPlayerToDimension(EntityPlayerMP player, int dimensionIn, BlockPos pos, IBlockState state)
{
    int i = player.dimension;
    WorldServer worldserver = player.mcServer.getWorld(player.dimension);
    player.dimension = dimensionIn;
    WorldServer worldserver1 = player.mcServer.getWorld(player.dimension);
    player.connection.sendPacket(new SPacketRespawn(player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    player.mcServer.getPlayerList().updatePermissionLevel(player);
    worldserver.removeEntityDangerously(player);
    player.isDead = false;
    transferPlayerToWorld(player, i, worldserver, worldserver1, pos, state);
    player.mcServer.getPlayerList().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));
    player.mcServer.getPlayerList().updateTimeAndWeatherForPlayer(player, worldserver1);
    player.mcServer.getPlayerList().syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects())
    {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, i, dimensionIn);
}
 
开发者ID:kenijey,项目名称:harshencastle,代码行数:25,代码来源:HarshenUtils.java

示例2: handleRespawn

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
public void handleRespawn(SPacketRespawn packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

    if (packetIn.getDimensionID() != this.gameController.player.dimension)
    {
        this.doneLoadingTerrain = false;
        Scoreboard scoreboard = this.clientWorldController.getScoreboard();
        this.clientWorldController = new WorldClient(this, new WorldSettings(0L, packetIn.getGameType(), false, this.gameController.world.getWorldInfo().isHardcoreModeEnabled(), packetIn.getWorldType()), packetIn.getDimensionID(), packetIn.getDifficulty(), this.gameController.mcProfiler);
        this.clientWorldController.setWorldScoreboard(scoreboard);
        this.gameController.loadWorld(this.clientWorldController);
        this.gameController.player.dimension = packetIn.getDimensionID();
        this.gameController.displayGuiScreen(new GuiDownloadTerrain(this));
    }

    this.gameController.setDimensionAndSpawnPlayer(packetIn.getDimensionID());
    this.gameController.playerController.setGameType(packetIn.getGameType());
}
 
开发者ID:NSExceptional,项目名称:Zombe-Modpack,代码行数:19,代码来源:NetHandlerPlayClient.java

示例3: changePlayerDimension

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
public void changePlayerDimension(EntityPlayerMP player, int dimensionIn)
{
    int i = player.dimension;
    WorldServer worldserver = this.mcServer.worldServerForDimension(player.dimension);
    player.dimension = dimensionIn;
    WorldServer worldserver1 = this.mcServer.worldServerForDimension(player.dimension);
    player.connection.sendPacket(new SPacketRespawn(player.dimension, player.world.getDifficulty(), player.world.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    this.updatePermissionLevel(player);
    worldserver.removeEntityDangerously(player);
    player.isDead = false;
    this.transferEntityToWorld(player, i, worldserver, worldserver1);
    this.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));
    this.updateTimeAndWeatherForPlayer(player, worldserver1);
    this.syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects())
    {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
}
 
开发者ID:sudofox,项目名称:Backmemed,代码行数:24,代码来源:PlayerList.java

示例4: handleRespawn

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
public void handleRespawn(SPacketRespawn packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.gameController);

    if (packetIn.getDimensionID() != this.gameController.thePlayer.dimension)
    {
        this.doneLoadingTerrain = false;
        Scoreboard scoreboard = this.clientWorldController.getScoreboard();
        this.clientWorldController = new WorldClient(this, new WorldSettings(0L, packetIn.getGameType(), false, this.gameController.theWorld.getWorldInfo().isHardcoreModeEnabled(), packetIn.getWorldType()), packetIn.getDimensionID(), packetIn.getDifficulty(), this.gameController.mcProfiler);
        this.clientWorldController.setWorldScoreboard(scoreboard);
        this.gameController.loadWorld(this.clientWorldController);
        this.gameController.thePlayer.dimension = packetIn.getDimensionID();
        this.gameController.displayGuiScreen(new GuiDownloadTerrain(this));
    }

    this.gameController.setDimensionAndSpawnPlayer(packetIn.getDimensionID());
    this.gameController.playerController.setGameType(packetIn.getGameType());
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:19,代码来源:NetHandlerPlayClient.java

示例5: transferPlayerToDimension

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
public void transferPlayerToDimension(EntityPlayerMP player, int dimensionIn, net.minecraft.world.Teleporter teleporter)
{
    int i = player.dimension;
    WorldServer worldserver = this.mcServer.worldServerForDimension(player.dimension);
    player.dimension = dimensionIn;
    WorldServer worldserver1 = this.mcServer.worldServerForDimension(player.dimension);
    player.connection.sendPacket(new SPacketRespawn(player.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), player.interactionManager.getGameType()));
    this.updatePermissionLevel(player);
    worldserver.removeEntityDangerously(player);
    player.isDead = false;
    this.transferEntityToWorld(player, i, worldserver, worldserver1, teleporter);
    this.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));
    this.updateTimeAndWeatherForPlayer(player, worldserver1);
    this.syncPlayerInventory(player);

    for (PotionEffect potioneffect : player.getActivePotionEffects())
    {
        player.connection.sendPacket(new SPacketEntityEffect(player.getEntityId(), potioneffect));
    }
    net.minecraftforge.fml.common.FMLCommonHandler.instance().firePlayerChangedDimensionEvent(player, i, dimensionIn);
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:25,代码来源:PlayerList.java

示例6: teleportPlayerToDim

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的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;
}
 
开发者ID:GamingsModding,项目名称:LittleThings-old,代码行数:40,代码来源:CommandDimTeleport.java

示例7: transferPlayerToDimension

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的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);
}
 
开发者ID:MrNobody98,项目名称:morecommands,代码行数:30,代码来源:PatchEntityPlayerMP.java

示例8: channelRead0

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
@Override
protected void channelRead0(ChannelHandlerContext ctx, SPacketRespawn msg) throws Exception {
       if (ctx.channel().isOpen())
       {
           try
           {

           	try {

    	    	NetHandlerPlayClient handler = (NetHandlerPlayClient) m_manager.getNetHandler();

   	    		Minecraft scheduler = InjectionHandler.readFieldOfType(handler, Minecraft.class);

                if (!scheduler.isCallingFromMinecraftThread())
                {
                    scheduler.addScheduledTask(new Runnable()
                    {
                        @Override
						public void run()
                        {
                            invoke(msg);
                        }
                    });
                    throw ThreadQuickExitException.INSTANCE;
                } else {
                	invoke(msg);
                }

   	    	} catch (Exception e) {

   	    		if (e instanceof ThreadQuickExitException) throw e;

   	    		Util.logger.logException("Unable to get scheduler!", e);

   	    		// we died - let vanilla take over!
   	    		ctx.fireChannelRead(msg);
   	    		return;
   	    	}

           }
           catch (ThreadQuickExitException var4)
           {
               ;
           }
       }
}
 
开发者ID:orbwoi,项目名称:UniversalRemote,代码行数:47,代码来源:RespawnInterceptor.java

示例9: handleSpectate

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
public void handleSpectate(CPacketSpectate packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.isSpectator())
    {
        Entity entity = null;

        for (WorldServer worldserver : this.serverController.worldServers)
        {
            if (worldserver != null)
            {
                entity = packetIn.getEntity(worldserver);

                if (entity != null)
                {
                    break;
                }
            }
        }

        if (entity != null)
        {
            this.playerEntity.setSpectatingEntity(this.playerEntity);
            this.playerEntity.dismountRidingEntity();

            if (entity.world == this.playerEntity.world)
            {
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
            }
            else
            {
                WorldServer worldserver1 = this.playerEntity.getServerWorld();
                WorldServer worldserver2 = (WorldServer)entity.world;
                this.playerEntity.dimension = entity.dimension;
                this.sendPacket(new SPacketRespawn(this.playerEntity.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), this.playerEntity.interactionManager.getGameType()));
                this.serverController.getPlayerList().updatePermissionLevel(this.playerEntity);
                worldserver1.removeEntityDangerously(this.playerEntity);
                this.playerEntity.isDead = false;
                this.playerEntity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);

                if (this.playerEntity.isEntityAlive())
                {
                    worldserver1.updateEntityWithOptionalForce(this.playerEntity, false);
                    worldserver2.spawnEntityInWorld(this.playerEntity);
                    worldserver2.updateEntityWithOptionalForce(this.playerEntity, false);
                }

                this.playerEntity.setWorld(worldserver2);
                this.serverController.getPlayerList().preparePlayer(this.playerEntity, worldserver1);
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
                this.playerEntity.interactionManager.setWorld(worldserver2);
                this.serverController.getPlayerList().updateTimeAndWeatherForPlayer(this.playerEntity, worldserver2);
                this.serverController.getPlayerList().syncPlayerInventory(this.playerEntity);
            }
        }
    }
}
 
开发者ID:NSExceptional,项目名称:Zombe-Modpack,代码行数:59,代码来源:NetHandlerPlayServer.java

示例10: handleSpectate

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
public void handleSpectate(CPacketSpectate packetIn)
{
    PacketThreadUtil.checkThreadAndEnqueue(packetIn, this, this.playerEntity.getServerWorld());

    if (this.playerEntity.isSpectator())
    {
        Entity entity = null;

        for (WorldServer worldserver : this.serverController.worldServers)
        {
            if (worldserver != null)
            {
                entity = packetIn.getEntity(worldserver);

                if (entity != null)
                {
                    break;
                }
            }
        }

        if (entity != null)
        {
            this.playerEntity.setSpectatingEntity(this.playerEntity);
            this.playerEntity.dismountRidingEntity();

            if (entity.worldObj == this.playerEntity.worldObj)
            {
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
            }
            else
            {
                WorldServer worldserver1 = this.playerEntity.getServerWorld();
                WorldServer worldserver2 = (WorldServer)entity.worldObj;
                this.playerEntity.dimension = entity.dimension;
                this.sendPacket(new SPacketRespawn(this.playerEntity.dimension, worldserver1.getDifficulty(), worldserver1.getWorldInfo().getTerrainType(), this.playerEntity.interactionManager.getGameType()));
                this.serverController.getPlayerList().updatePermissionLevel(this.playerEntity);
                worldserver1.removeEntityDangerously(this.playerEntity);
                this.playerEntity.isDead = false;
                this.playerEntity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);

                if (this.playerEntity.isEntityAlive())
                {
                    worldserver1.updateEntityWithOptionalForce(this.playerEntity, false);
                    worldserver2.spawnEntityInWorld(this.playerEntity);
                    worldserver2.updateEntityWithOptionalForce(this.playerEntity, false);
                }

                this.playerEntity.setWorld(worldserver2);
                this.serverController.getPlayerList().preparePlayer(this.playerEntity, worldserver1);
                this.playerEntity.setPositionAndUpdate(entity.posX, entity.posY, entity.posZ);
                this.playerEntity.interactionManager.setWorld(worldserver2);
                this.serverController.getPlayerList().updateTimeAndWeatherForPlayer(this.playerEntity, worldserver2);
                this.serverController.getPlayerList().syncPlayerInventory(this.playerEntity);
            }
        }
    }
}
 
开发者ID:F1r3w477,项目名称:CustomWorldGen,代码行数:59,代码来源:NetHandlerPlayServer.java

示例11: transferPlayerToDimension

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的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);
  }
 
开发者ID:Domochevsky,项目名称:minecraft-territorialdealings,代码行数:54,代码来源:Transition.java

示例12: teleportPlayerToDim

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的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;
}
 
开发者ID:Alec-WAM,项目名称:CrystalMod,代码行数:45,代码来源:TeleportUtil.java

示例13: transferPlayerToDimension

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的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;
	}
}
 
开发者ID:dyeo,项目名称:VanillaTeleporter,代码行数:71,代码来源:TeleporterUtility.java

示例14: changeDimension

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的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);
}
 
开发者ID:Darkhax-Minecraft,项目名称:Bookshelf,代码行数:55,代码来源:PlayerUtils.java

示例15: handleRespawn

import net.minecraft.network.play.server.SPacketRespawn; //导入依赖的package包/类
void handleRespawn(SPacketRespawn packetIn); 
开发者ID:sudofox,项目名称:Backmemed,代码行数:2,代码来源:INetHandlerPlayClient.java


注:本文中的net.minecraft.network.play.server.SPacketRespawn类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。