@SuppressWarnings("unchecked")
 private void pop() {
   List<EntityLivingBase> ents =
       worldObj.getEntitiesWithinAABB(
           EntityLivingBase.class,
           AxisAlignedBB.getBoundingBox(
               xCoord + 1.0,
               yCoord + 1.0,
               zCoord + 1.0,
               xCoord + xLength - 1,
               yCoord + 3.0,
               zCoord + zLength - 1));
   for (EntityLivingBase ent : ents) {
     if (ent instanceof EntityPlayer) {
       EntityPlayerMP player = (EntityPlayerMP) ent;
       if (!player.capabilities.isCreativeMode) {
         player.playerNetServerHandler.sendPacket(
             new S12PacketEntityVelocity(
                 player.getEntityId(), 0.0, MathHelper.randomDoubleInRange(0.5, 2), 0.0));
       }
     } else {
       if (!ent.isDead) {
         ent.addVelocity(0.0, MathHelper.randomDoubleInRange(0.5, 2), 0);
       }
     }
   }
 }
  /** moves provided player from overworld to nether or vice versa */
  public void transferPlayerToDimension(EntityPlayerMP playerIn, int dimension) {
    int var3 = playerIn.dimension;
    WorldServer var4 = this.mcServer.worldServerForDimension(playerIn.dimension);
    playerIn.dimension = dimension;
    WorldServer var5 = this.mcServer.worldServerForDimension(playerIn.dimension);
    playerIn.playerNetServerHandler.sendPacket(
        new S07PacketRespawn(
            playerIn.dimension,
            playerIn.worldObj.getDifficulty(),
            playerIn.worldObj.getWorldInfo().getTerrainType(),
            playerIn.theItemInWorldManager.getGameType()));
    var4.removePlayerEntityDangerously(playerIn);
    playerIn.isDead = false;
    this.transferEntityToWorld(playerIn, var3, var4, var5);
    this.func_72375_a(playerIn, var4);
    playerIn.playerNetServerHandler.setPlayerLocation(
        playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
    playerIn.theItemInWorldManager.setWorld(var5);
    this.updateTimeAndWeatherForPlayer(playerIn, var5);
    this.syncPlayerInventory(playerIn);
    Iterator var6 = playerIn.getActivePotionEffects().iterator();

    while (var6.hasNext()) {
      PotionEffect var7 = (PotionEffect) var6.next();
      playerIn.playerNetServerHandler.sendPacket(
          new S1DPacketEntityEffect(playerIn.getEntityId(), var7));
    }
  }
예제 #3
0
 public static void syncAllAugmentsToClient(EntityPlayer receiver) {
   List<EntityPlayerMP> players =
       MinecraftServer.getServer().getConfigurationManager().playerEntityList;
   for (EntityPlayerMP player : players) {
     PlayerHandler.setPlayerAugments(
         player, PlayerAugmentProperties.get(player).loadAugmentsFromInventory());
     EventHandlerEntity.syncSchedule.add(player.getEntityId());
     ChatHelper.sendTo(
         (EntityPlayer) receiver, "Synced Player Augments for " + player.getCommandSenderName());
   }
 }
  /**
   * @author blood - May 21st, 2016
   * @reason - adjusted to support {@link DisplaceEntityEvent.Teleport.Portal}
   * @param playerIn The player teleporting to another dimension
   * @param targetDimensionId The id of target dimension.
   * @param teleporter The teleporter used to transport and create the portal
   */
  public void transferPlayerToDimension(
      EntityPlayerMP playerIn, int targetDimensionId, net.minecraft.world.Teleporter teleporter) {
    DisplaceEntityEvent.Teleport.Portal event =
        SpongeCommonEventFactory.handleDisplaceEntityPortalEvent(
            playerIn, targetDimensionId, teleporter);
    if (event == null || event.isCancelled()) {
      return;
    }

    WorldServer fromWorld = (WorldServer) event.getFromTransform().getExtent();
    WorldServer toWorld = (WorldServer) event.getToTransform().getExtent();
    playerIn.dimension = toWorld.provider.getDimensionId();
    // Support vanilla clients teleporting to custom dimensions
    int dimension =
        DimensionManager.getClientDimensionToSend(
            toWorld.provider.getDimensionId(), toWorld, playerIn);
    if (((IMixinEntityPlayerMP) playerIn).usesCustomClient()) {
      DimensionManager.sendDimensionRegistration(toWorld, playerIn, dimension);
    }
    playerIn.playerNetServerHandler.sendPacket(
        new S07PacketRespawn(
            playerIn.dimension,
            fromWorld.getDifficulty(),
            fromWorld.getWorldInfo().getTerrainType(),
            playerIn.theItemInWorldManager.getGameType()));
    fromWorld.removePlayerEntityDangerously(playerIn);
    playerIn.isDead = false;
    // we do not need to call transferEntityToWorld as we already have the correct transform and
    // created the portal in handleDisplaceEntityPortalEvent
    ((IMixinEntity) playerIn).setLocationAndAngles(event.getToTransform());
    toWorld.spawnEntityInWorld(playerIn);
    toWorld.updateEntityWithOptionalForce(playerIn, false);
    playerIn.setWorld(toWorld);
    this.preparePlayer(playerIn, fromWorld);
    playerIn.playerNetServerHandler.setPlayerLocation(
        playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
    playerIn.theItemInWorldManager.setWorld(toWorld);
    this.updateTimeAndWeatherForPlayer(playerIn, toWorld);
    this.syncPlayerInventory(playerIn);

    for (PotionEffect potioneffect : playerIn.getActivePotionEffects()) {
      playerIn.playerNetServerHandler.sendPacket(
          new S1DPacketEntityEffect(playerIn.getEntityId(), potioneffect));
    }
    ((IMixinEntityPlayerMP) playerIn).refreshXpHealthAndFood();
    // Forge needs to know when a player changes to new a dimension
    // This cannot be mapped to DisplaceEntityEvent.Teleport as this event must be called AFTER
    // transfer.
    net.minecraftforge.fml.common.FMLCommonHandler.instance()
        .firePlayerChangedDimensionEvent(
            playerIn, fromWorld.provider.getDimensionId(), toWorld.provider.getDimensionId());
  }
  /** Called on respawn */
  public EntityPlayerMP recreatePlayerEntity(
      EntityPlayerMP playerIn, int dimension, boolean conqueredEnd) {
    playerIn.getServerForPlayer().getEntityTracker().removePlayerFromTrackers(playerIn);
    playerIn.getServerForPlayer().getEntityTracker().untrackEntity(playerIn);
    playerIn.getServerForPlayer().getPlayerManager().removePlayer(playerIn);
    this.playerEntityList.remove(playerIn);
    this.mcServer
        .worldServerForDimension(playerIn.dimension)
        .removePlayerEntityDangerously(playerIn);
    BlockPos var4 = playerIn.func_180470_cg();
    boolean var5 = playerIn.isSpawnForced();
    playerIn.dimension = dimension;
    Object var6;

    if (this.mcServer.isDemo()) {
      var6 = new DemoWorldManager(this.mcServer.worldServerForDimension(playerIn.dimension));
    } else {
      var6 = new ItemInWorldManager(this.mcServer.worldServerForDimension(playerIn.dimension));
    }

    EntityPlayerMP var7 =
        new EntityPlayerMP(
            this.mcServer,
            this.mcServer.worldServerForDimension(playerIn.dimension),
            playerIn.getGameProfile(),
            (ItemInWorldManager) var6);
    var7.playerNetServerHandler = playerIn.playerNetServerHandler;
    var7.clonePlayer(playerIn, conqueredEnd);
    var7.setEntityId(playerIn.getEntityId());
    var7.func_174817_o(playerIn);
    WorldServer var8 = this.mcServer.worldServerForDimension(playerIn.dimension);
    this.func_72381_a(var7, playerIn, var8);
    BlockPos var9;

    if (var4 != null) {
      var9 =
          EntityPlayer.func_180467_a(
              this.mcServer.worldServerForDimension(playerIn.dimension), var4, var5);

      if (var9 != null) {
        var7.setLocationAndAngles(
            (double) ((float) var9.getX() + 0.5F),
            (double) ((float) var9.getY() + 0.1F),
            (double) ((float) var9.getZ() + 0.5F),
            0.0F,
            0.0F);
        var7.func_180473_a(var4, var5);
      } else {
        var7.playerNetServerHandler.sendPacket(new S2BPacketChangeGameState(0, 0.0F));
      }
    }

    var8.theChunkProviderServer.loadChunk((int) var7.posX >> 4, (int) var7.posZ >> 4);

    while (!var8.getCollidingBoundingBoxes(var7, var7.getEntityBoundingBox()).isEmpty()
        && var7.posY < 256.0D) {
      var7.setPosition(var7.posX, var7.posY + 1.0D, var7.posZ);
    }

    var7.playerNetServerHandler.sendPacket(
        new S07PacketRespawn(
            var7.dimension,
            var7.worldObj.getDifficulty(),
            var7.worldObj.getWorldInfo().getTerrainType(),
            var7.theItemInWorldManager.getGameType()));
    var9 = var8.getSpawnPoint();
    var7.playerNetServerHandler.setPlayerLocation(
        var7.posX, var7.posY, var7.posZ, var7.rotationYaw, var7.rotationPitch);
    var7.playerNetServerHandler.sendPacket(new S05PacketSpawnPosition(var9));
    var7.playerNetServerHandler.sendPacket(
        new S1FPacketSetExperience(var7.experience, var7.experienceTotal, var7.experienceLevel));
    this.updateTimeAndWeatherForPlayer(var7, var8);
    var8.getPlayerManager().addPlayer(var7);
    var8.spawnEntityInWorld(var7);
    this.playerEntityList.add(var7);
    this.field_177454_f.put(var7.getUniqueID(), var7);
    var7.addSelfToInternalCraftingInventory();
    var7.setHealth(var7.getHealth());
    return var7;
  }
  public void initializeConnectionToPlayer(NetworkManager netManager, EntityPlayerMP playerIn) {
    GameProfile var3 = playerIn.getGameProfile();
    PlayerProfileCache var4 = this.mcServer.getPlayerProfileCache();
    GameProfile var5 = var4.func_152652_a(var3.getId());
    String var6 = var5 == null ? var3.getName() : var5.getName();
    var4.func_152649_a(var3);
    NBTTagCompound var7 = this.readPlayerDataFromFile(playerIn);
    playerIn.setWorld(this.mcServer.worldServerForDimension(playerIn.dimension));
    playerIn.theItemInWorldManager.setWorld((WorldServer) playerIn.worldObj);
    String var8 = "local";

    if (netManager.getRemoteAddress() != null) {
      var8 = netManager.getRemoteAddress().toString();
    }

    logger.info(
        playerIn.getName()
            + "["
            + var8
            + "] logged in with entity id "
            + playerIn.getEntityId()
            + " at ("
            + playerIn.posX
            + ", "
            + playerIn.posY
            + ", "
            + playerIn.posZ
            + ")");
    WorldServer var9 = this.mcServer.worldServerForDimension(playerIn.dimension);
    WorldInfo var10 = var9.getWorldInfo();
    BlockPos var11 = var9.getSpawnPoint();
    this.func_72381_a(playerIn, (EntityPlayerMP) null, var9);
    NetHandlerPlayServer var12 = new NetHandlerPlayServer(this.mcServer, netManager, playerIn);
    var12.sendPacket(
        new S01PacketJoinGame(
            playerIn.getEntityId(),
            playerIn.theItemInWorldManager.getGameType(),
            var10.isHardcoreModeEnabled(),
            var9.provider.getDimensionId(),
            var9.getDifficulty(),
            this.getMaxPlayers(),
            var10.getTerrainType(),
            var9.getGameRules().getGameRuleBooleanValue("reducedDebugInfo")));
    var12.sendPacket(
        new S3FPacketCustomPayload(
            "MC|Brand",
            (new PacketBuffer(Unpooled.buffer()))
                .writeString(this.getServerInstance().getServerModName())));
    var12.sendPacket(
        new S41PacketServerDifficulty(var10.getDifficulty(), var10.isDifficultyLocked()));
    var12.sendPacket(new S05PacketSpawnPosition(var11));
    var12.sendPacket(new S39PacketPlayerAbilities(playerIn.capabilities));
    var12.sendPacket(new S09PacketHeldItemChange(playerIn.inventory.currentItem));
    playerIn.getStatFile().func_150877_d();
    playerIn.getStatFile().func_150884_b(playerIn);
    this.func_96456_a((ServerScoreboard) var9.getScoreboard(), playerIn);
    this.mcServer.refreshStatusNextTick();
    ChatComponentTranslation var13;

    if (!playerIn.getName().equalsIgnoreCase(var6)) {
      var13 =
          new ChatComponentTranslation(
              "multiplayer.player.joined.renamed", new Object[] {playerIn.getDisplayName(), var6});
    } else {
      var13 =
          new ChatComponentTranslation(
              "multiplayer.player.joined", new Object[] {playerIn.getDisplayName()});
    }

    var13.getChatStyle().setColor(EnumChatFormatting.YELLOW);
    this.sendChatMsg(var13);
    this.playerLoggedIn(playerIn);
    var12.setPlayerLocation(
        playerIn.posX, playerIn.posY, playerIn.posZ, playerIn.rotationYaw, playerIn.rotationPitch);
    this.updateTimeAndWeatherForPlayer(playerIn, var9);

    if (this.mcServer.getResourcePackUrl().length() > 0) {
      playerIn.func_175397_a(
          this.mcServer.getResourcePackUrl(), this.mcServer.getResourcePackHash());
    }

    Iterator var14 = playerIn.getActivePotionEffects().iterator();

    while (var14.hasNext()) {
      PotionEffect var15 = (PotionEffect) var14.next();
      var12.sendPacket(new S1DPacketEntityEffect(playerIn.getEntityId(), var15));
    }

    playerIn.addSelfToInternalCraftingInventory();

    if (var7 != null && var7.hasKey("Riding", 10)) {
      Entity var16 = EntityList.createEntityFromNBT(var7.getCompoundTag("Riding"), var9);

      if (var16 != null) {
        var16.forceSpawn = true;
        var9.spawnEntityInWorld(var16);
        playerIn.mountEntity(var16);
        var16.forceSpawn = false;
      }
    }
  }
  private static Entity sendEntityToWorld(
      Entity entity, int newDimension, Vector3 newPos, Facing3 newLook) {
    MinecraftServer server = MinecraftServer.getServer();
    Entity currentEntity = entity;
    if (entity.dimension != newDimension) {
      if (entity instanceof EntityPlayerMP) {
        EntityPlayerMP player = (EntityPlayerMP) entity;
        ServerConfigurationManager scm = server.getConfigurationManager();
        int oldDimension = player.dimension;
        player.dimension = newDimension;
        WorldServer oldWorld = server.worldServerForDimension(oldDimension);
        WorldServer newWorld = server.worldServerForDimension(newDimension);

        DimensionRegisterMessage packet =
            new DimensionRegisterMessage(
                newDimension, DimensionManager.getProviderType(newDimension));
        LCRuntime.runtime.network().getPreferredPipe().sendForgeMessageTo(packet, player);

        player.closeScreen();
        player.playerNetServerHandler.sendPacket(
            new S07PacketRespawn(
                player.dimension,
                player.worldObj.difficultySetting,
                newWorld.getWorldInfo().getTerrainType(),
                player.theItemInWorldManager.getGameType()));
        oldWorld.removePlayerEntityDangerously(player);
        player.isDead = false;
        player.setLocationAndAngles(
            newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch);
        newWorld.spawnEntityInWorld(player);
        player.setWorld(newWorld);
        scm.func_72375_a(player, oldWorld);
        player.playerNetServerHandler.setPlayerLocation(
            newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch);
        player.theItemInWorldManager.setWorld(newWorld);
        scm.updateTimeAndWeatherForPlayer(player, newWorld);
        scm.syncPlayerInventory(player);
        Iterator<?> var6 = player.getActivePotionEffects().iterator();
        while (var6.hasNext())
          player.playerNetServerHandler.sendPacket(
              new S1DPacketEntityEffect(player.getEntityId(), (PotionEffect) var6.next()));
        player.playerNetServerHandler.sendPacket(
            new S1FPacketSetExperience(
                player.experience, player.experienceTotal, player.experienceLevel));
      } else {
        int oldDimension = entity.dimension;
        WorldServer oldWorld = server.worldServerForDimension(oldDimension);
        WorldServer newWorld = server.worldServerForDimension(newDimension);
        entity.dimension = newDimension;

        entity.worldObj.removeEntity(entity);
        entity.isDead = false;
        server
            .getConfigurationManager()
            .transferEntityToWorld(entity, oldDimension, oldWorld, newWorld);
        currentEntity = EntityList.createEntityByName(EntityList.getEntityString(entity), newWorld);

        if (currentEntity != null) {
          currentEntity.copyDataFrom(entity, true);
          currentEntity.setLocationAndAngles(
              newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch);
          newWorld.spawnEntityInWorld(currentEntity);
        }

        entity.isDead = true;
        oldWorld.resetUpdateEntityTick();
        newWorld.resetUpdateEntityTick();
      }
    } else {
      currentEntity.setLocationAndAngles(
          newPos.x, newPos.y, newPos.z, (float) newLook.yaw, (float) newLook.pitch);
      if (currentEntity instanceof EntityPlayerMP) {
        EntityPlayerMP mpEnt = (EntityPlayerMP) currentEntity;
        mpEnt.rotationYaw = (float) newLook.yaw;
        mpEnt.setPositionAndUpdate(newPos.x, newPos.y, newPos.z);
        mpEnt.worldObj.updateEntityWithOptionalForce(entity, false);
      }
    }
    return currentEntity;
  }