Esempio n. 1
0
 private Optional<ChunkCoordinates> findValidTombstoneLocation(EntityPlayer player) {
   final int maxRadius = 100;
   /** Search an increasing square box (only check edge) for a valid location */
   for (int radius = 0; radius < maxRadius; radius++) {
     List<ChunkCoordinates> validLocations = new ArrayList<ChunkCoordinates>();
     validLocations.addAll(searchXPlaneAt(-radius, radius, player));
     validLocations.addAll(searchXPlaneAt(radius, radius, player));
     validLocations.addAll(searchZPlaneAt(-radius, radius, player));
     validLocations.addAll(searchZPlaneAt(radius, radius, player));
     validLocations.addAll(searchYPlaneAt(-radius, radius, player));
     validLocations.addAll(searchYPlaneAt(radius, radius, player));
     ChunkCoordinates closestPoint = null;
     float bestDistance = 0;
     for (ChunkCoordinates chunkCoordinates : validLocations) {
       if (closestPoint != null) {
         float distance =
             chunkCoordinates.getDistanceSquared(
                 (int) player.posX, (int) player.posY, (int) player.posZ);
         if (distance < bestDistance) {
           bestDistance = distance;
           closestPoint = chunkCoordinates;
         }
       } else {
         closestPoint = chunkCoordinates;
         bestDistance =
             closestPoint.getDistanceSquared(
                 (int) player.posX, (int) player.posY, (int) player.posZ);
       }
     }
     if (closestPoint != null) {
       return Optional.of(closestPoint);
     }
   }
   return Optional.absent();
 }
  /** Teleports the entity to another dimension. Params: Dimension number to teleport to */
  public static void travelEntityToDimension(Entity entity, int dimensionId, int x, int y, int z) {
    if (!entity.worldObj.isRemote && !entity.isDead) {
      entity.worldObj.theProfiler.startSection("changeDimension");
      MinecraftServer minecraftserver = MinecraftServer.getServer();
      int j = entity.dimension;
      WorldServer worldserver = minecraftserver.worldServerForDimension(j);
      WorldServer worldserver1 = minecraftserver.worldServerForDimension(dimensionId);
      entity.dimension = dimensionId;

      if (j == 1 && dimensionId == 1) {
        worldserver1 = minecraftserver.worldServerForDimension(0);
        entity.dimension = 0;
      }

      entity.worldObj.removeEntity(entity);
      entity.isDead = false;
      entity.worldObj.theProfiler.startSection("reposition");
      minecraftserver
          .getConfigurationManager()
          .transferEntityToWorld(entity, j, worldserver, worldserver1);
      entity.worldObj.theProfiler.endStartSection("reloading");
      Entity newEntity =
          EntityList.createEntityByName(EntityList.getEntityString(entity), worldserver1);

      if (newEntity != null) {
        newEntity.copyDataFrom(entity, true);

        if (j == 1 && dimensionId == 1) {
          ChunkCoordinates chunkcoordinates = worldserver1.getSpawnPoint();
          chunkcoordinates.posY =
              entity.worldObj.getTopSolidOrLiquidBlock(
                  chunkcoordinates.posX, chunkcoordinates.posZ);
          newEntity.setLocationAndAngles(
              (double) chunkcoordinates.posX,
              (double) chunkcoordinates.posY,
              (double) chunkcoordinates.posZ,
              newEntity.rotationYaw,
              newEntity.rotationPitch);
        }

        worldserver1.spawnEntityInWorld(newEntity);
        newEntity.setPosition(x + 0.5D, y, z + 0.5D);
      }

      entity.isDead = true;
      entity.worldObj.theProfiler.endSection();
      worldserver.resetUpdateEntityTick();
      worldserver1.resetUpdateEntityTick();
      entity.worldObj.theProfiler.endSection();
    }
  }
  /** Find all players in a specified range and narrowing down by other parameters */
  public List findPlayers(
      ChunkCoordinates par1ChunkCoordinates,
      int par2,
      int par3,
      int par4,
      int par5,
      int par6,
      int par7) {
    if (this.playerEntityList.isEmpty()) {
      return null;
    } else {
      Object var8 = new ArrayList();
      boolean var9 = par4 < 0;
      int var10 = par2 * par2;
      int var11 = par3 * par3;
      par4 = MathHelper.abs_int(par4);

      for (int var12 = 0; var12 < this.playerEntityList.size(); ++var12) {
        EntityPlayerMP var13 = (EntityPlayerMP) this.playerEntityList.get(var12);

        if (par1ChunkCoordinates != null && (par2 > 0 || par3 > 0)) {
          float var14 =
              par1ChunkCoordinates.getDistanceSquaredToChunkCoordinates(
                  var13.getPlayerCoordinates());

          if (par2 > 0 && var14 < (float) var10 || par3 > 0 && var14 > (float) var11) {
            continue;
          }
        }

        if ((par5 == EnumGameType.NOT_SET.getID()
                || par5 == var13.theItemInWorldManager.getGameType().getID())
            && (par6 <= 0 || var13.experienceLevel >= par6)
            && var13.experienceLevel <= par7) {
          ((List) var8).add(var13);
        }
      }

      if (par1ChunkCoordinates != null) {
        Collections.sort((List) var8, new PlayerPositionComparator(par1ChunkCoordinates));
      }

      if (var9) {
        Collections.reverse((List) var8);
      }

      if (par4 > 0) {
        var8 = ((List) var8).subList(0, Math.min(par4, ((List) var8).size()));
      }

      return (List) var8;
    }
  }