Example #1
0
  public void sendThisChunkToPlayer(EntityPlayerMP par1EntityPlayerMP) {
    if (this.playersInChunk.contains(par1EntityPlayerMP)) {
      par1EntityPlayerMP.playerNetServerHandler.sendPacketToPlayer(
          new Packet51MapChunk(
              PlayerManager.getWorldServer(this.thePlayerManager)
                  .getChunkFromChunkCoords(
                      this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos),
              true,
              0));
      this.playersInChunk.remove(par1EntityPlayerMP);
      par1EntityPlayerMP.loadedChunks.remove(this.chunkLocation);

      MinecraftForge.EVENT_BUS.post(new ChunkWatchEvent.UnWatch(chunkLocation, par1EntityPlayerMP));

      if (this.playersInChunk.isEmpty()) {
        long i =
            (long) this.chunkLocation.chunkXPos + 2147483647L
                | (long) this.chunkLocation.chunkZPos + 2147483647L << 32;
        PlayerManager.getChunkWatchers(this.thePlayerManager).remove(i);

        if (this.numberOfTilesToUpdate > 0) {
          PlayerManager.getChunkWatchersWithPlayers(this.thePlayerManager).remove(this);
        }

        this.thePlayerManager
            .getWorldServer()
            .theChunkProviderServer
            .unloadChunksIfNotNearSpawn(this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos);
      }
    }
  }
Example #2
0
 public PlayerInstance(PlayerManager par1PlayerManager, int par2, int par3) {
   this.thePlayerManager = par1PlayerManager;
   this.playersInChunk = new ArrayList();
   this.locationOfBlockChange = new short[64];
   this.numberOfTilesToUpdate = 0;
   this.chunkLocation = new ChunkCoordIntPair(par2, par3);
   par1PlayerManager.getWorldServer().theChunkProviderServer.loadChunk(par2, par3);
 }
Example #3
0
  public void sendChunkUpdate() {
    if (this.numberOfTilesToUpdate != 0) {
      int i;
      int j;
      int k;

      if (this.numberOfTilesToUpdate == 1) {
        i = this.chunkLocation.chunkXPos * 16 + (this.locationOfBlockChange[0] >> 12 & 15);
        j = this.locationOfBlockChange[0] & 255;
        k = this.chunkLocation.chunkZPos * 16 + (this.locationOfBlockChange[0] >> 8 & 15);
        this.sendToAllPlayersWatchingChunk(
            new Packet53BlockChange(i, j, k, PlayerManager.getWorldServer(this.thePlayerManager)));

        if (PlayerManager.getWorldServer(this.thePlayerManager).blockHasTileEntity(i, j, k)) {
          this.sendTileToAllPlayersWatchingChunk(
              PlayerManager.getWorldServer(this.thePlayerManager).getBlockTileEntity(i, j, k));
        }
      } else {
        int l;

        if (this.numberOfTilesToUpdate >= ForgeDummyContainer.clumpingThreshold) {
          i = this.chunkLocation.chunkXPos * 16;
          j = this.chunkLocation.chunkZPos * 16;
          this.sendToAllPlayersWatchingChunk(
              new Packet51MapChunk(
                  PlayerManager.getWorldServer(this.thePlayerManager)
                      .getChunkFromChunkCoords(
                          this.chunkLocation.chunkXPos, this.chunkLocation.chunkZPos),
                  false,
                  this.field_73260_f));

          /* Forge: Grabs ALL tile entities is costly on a modded server, only send needed ones
          for (k = 0; k < 16; ++k)
          {
              if ((this.field_73260_f & 1 << k) != 0)
              {
                  l = k << 4;
                  List list = PlayerManager.getWorldServer(this.thePlayerManager).getAllTileEntityInBox(i, l, j, i + 16, l + 16, j + 16);

                  for (int i1 = 0; i1 < list.size(); ++i1)
                  {
                      this.sendTileToAllPlayersWatchingChunk((TileEntity)list.get(i1));
                  }
              }
          }
          */
        } else {
          this.sendToAllPlayersWatchingChunk(
              new Packet52MultiBlockChange(
                  this.chunkLocation.chunkXPos,
                  this.chunkLocation.chunkZPos,
                  this.locationOfBlockChange,
                  this.numberOfTilesToUpdate,
                  PlayerManager.getWorldServer(this.thePlayerManager)));
        }

        { // Forge: Send only the tile entities that are updated, Adding this brace lets us keep the
          // indent and the patch small
          for (i = 0; i < this.numberOfTilesToUpdate; ++i) {
            j = this.chunkLocation.chunkXPos * 16 + (this.locationOfBlockChange[i] >> 12 & 15);
            k = this.locationOfBlockChange[i] & 255;
            l = this.chunkLocation.chunkZPos * 16 + (this.locationOfBlockChange[i] >> 8 & 15);

            if (PlayerManager.getWorldServer(this.thePlayerManager).blockHasTileEntity(j, k, l)) {
              this.sendTileToAllPlayersWatchingChunk(
                  PlayerManager.getWorldServer(this.thePlayerManager).getBlockTileEntity(j, k, l));
            }
          }
        }
      }

      this.numberOfTilesToUpdate = 0;
      this.field_73260_f = 0;
    }
  }