Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-120780

Chunk data packets are sometimes created unnecessarily

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Resolved
    • Resolution: Fixed
    • Affects Version/s: Minecraft 1.12.2
    • Fix Version/s: Minecraft 18w30b
    • Labels:
      None
    • Confirmation Status:
      Confirmed

      Description

      Basically, the method PlayerChunkMapEntry.sendToPlayers() is sometimes called on an entry while it contains no players.

      The end of that method looks like this:

      else
      {
      	this.changes = 0;
      	this.changedSectionFilter = 0;
      	this.sentToPlayers = true;
      	Packet<?> packet = new SPacketChunkData(this.chunk, 65535);
      
      	for (EntityPlayerMP entityplayermp : this.players)
      	{
      		entityplayermp.connection.sendPacket(packet);
      		this.playerChunkMap.getWorldServer().getEntityTracker().sendLeashedEntitiesInChunk(entityplayermp, this.chunk);
      	}
      
      	return true;
      }
      

      When that code is run, the SPacketChunkData packet is created even if the list players is empty at this point and the packet is not actually needed.

      As creating the packet here involves reading all the data for a chunk, including block entity data, it's better to avoid doing so unnecessarily.

      The issue can be easily resolved by adding a check to the method like so:

      else
      {
      	this.changes = 0;
      	this.changedSectionFilter = 0;
      	this.sentToPlayers = true;
      	if (!this.players.isEmpty())
      	{
      		Packet<?> packet = new SPacketChunkData(this.chunk, 65535);
      
      		for (EntityPlayerMP entityplayermp : this.players)
      		{
      			entityplayermp.connection.sendPacket(packet);
      			this.playerChunkMap.getWorldServer().getEntityTracker().sendLeashedEntitiesInChunk(entityplayermp, this.chunk);
      		}
      	}
      	return true;
      }
      

        Attachments

          Activity

            People

            • Assignee:
              grum [Mojang] Grum (Erik Broes)
              Reporter:
              quadraxis Ben Staddon
            • Votes:
              7 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:
                CHK: