PlayerManager updated.

This commit is contained in:
LexManos 2016-03-14 22:58:01 -07:00
parent 3839d33770
commit 28ae283b96
3 changed files with 120 additions and 229 deletions

View file

@ -1,10 +1,121 @@
--- ../src-base/minecraft/net/minecraft/server/management/PlayerManager.java
+++ ../src-work/minecraft/net/minecraft/server/management/PlayerManager.java
@@ -338,6 +338,7 @@
int i1 = this.field_72698_e;
int j1 = i - k;
int k1 = j - l;
+ List<ChunkCoordIntPair> chunksToLoad = Lists.newArrayList();
@@ -468,11 +468,18 @@
private int field_187288_h;
private long field_187289_i;
private boolean field_187290_j;
+ private Runnable loadedRunnable = new Runnable()
+ {
+ public void run()
+ {
+ PlayerInstance.this.field_187286_f = PlayerManager.this.func_72688_a().func_72863_F().func_186028_c(PlayerInstance.this.field_187284_d.field_77276_a, PlayerInstance.this.field_187284_d.field_77275_b);
+ }
+ };
if (j1 != 0 || k1 != 0)
public PlayerInstance(int p_i1518_2_, int p_i1518_3_)
{
this.field_187284_d = new ChunkCoordIntPair(p_i1518_2_, p_i1518_3_);
- this.field_187286_f = PlayerManager.this.func_72688_a().func_72863_F().func_186028_c(p_i1518_2_, p_i1518_3_);
+ PlayerManager.this.func_72688_a().func_72863_F().loadChunk(p_i1518_2_, p_i1518_3_, this.loadedRunnable);
}
public ChunkCoordIntPair func_187264_a()
@@ -506,6 +513,20 @@
{
if (this.field_187283_c.contains(p_187277_1_))
{
+ // If we haven't loaded yet don't load the chunk just so we can clean it up
+ if (this.field_187286_f == null)
+ {
+ this.field_187283_c.remove(p_187277_1_);
+
+ if (this.field_187283_c.isEmpty())
+ {
+ net.minecraftforge.common.chunkio.ChunkIOExecutor.dropQueuedChunkLoad(PlayerManager.this.func_72688_a(), this.field_187284_d.field_77276_a, this.field_187284_d.field_77275_b, this.loadedRunnable);
+ PlayerManager.this.func_187305_b(this);
+ }
+
+ return;
+ }
+
if (this.field_187290_j)
{
p_187277_1_.field_71135_a.func_147359_a(new SPacketUnloadChunk(this.field_187284_d.field_77276_a, this.field_187284_d.field_77275_b));
@@ -513,6 +534,8 @@
this.field_187283_c.remove(p_187277_1_);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.UnWatch(this.field_187284_d, p_187277_1_));
+
if (this.field_187283_c.isEmpty())
{
PlayerManager.this.func_187305_b(this);
@@ -625,7 +648,7 @@
this.field_187288_h |= 1 << (p_187265_2_ >> 4);
- if (this.field_187287_g < 64)
+ //Forge; Cache everything, so always run
{
short short1 = (short)(p_187265_1_ << 12 | p_187265_3_ << 8 | p_187265_2_);
@@ -637,6 +660,8 @@
}
}
+ if (this.field_187287_g == this.field_187285_e.length)
+ this.field_187285_e = java.util.Arrays.copyOf(this.field_187285_e, this.field_187285_e.length << 1);
this.field_187285_e[this.field_187287_g++] = short1;
}
}
@@ -653,6 +678,7 @@
}
}
+ @SuppressWarnings("unused")
public void func_187280_d()
{
if (this.field_187290_j && this.field_187286_f != null)
@@ -666,18 +692,20 @@
int k = (this.field_187285_e[0] >> 8 & 15) + this.field_187284_d.field_77275_b * 16;
BlockPos blockpos = new BlockPos(i, j, k);
this.func_187267_a(new SPacketBlockChange(PlayerManager.this.func_72688_a(), blockpos));
+ net.minecraft.block.state.IBlockState state = PlayerManager.this.func_72688_a().func_180495_p(blockpos);
- if (PlayerManager.this.func_72688_a().func_180495_p(blockpos).func_177230_c().func_149716_u())
+ if (state.func_177230_c().hasTileEntity(state))
{
this.func_187273_a(PlayerManager.this.func_72688_a().func_175625_s(blockpos));
}
}
- else if (this.field_187287_g == 64)
+ else if (this.field_187287_g >= net.minecraftforge.common.ForgeModContainer.clumpingThreshold)
{
int i1 = this.field_187284_d.field_77276_a * 16;
int k1 = this.field_187284_d.field_77275_b * 16;
this.func_187267_a(new SPacketChunkData(this.field_187286_f, false, this.field_187288_h));
+ if (false) // Forge: Grabs ALL the tile entities, costly on a modded server, only send needed ones
for (int i2 = 0; i2 < 16; ++i2)
{
if ((this.field_187288_h & 1 << i2) != 0)
@@ -695,15 +723,17 @@
else
{
this.func_187267_a(new SPacketMultiBlockChange(this.field_187287_g, this.field_187285_e, this.field_187286_f));
-
+ }
+ { // Forge: Send only the tile entities that are updated, Adding this brace lets us keep the indent and the patch small
for (int j1 = 0; j1 < this.field_187287_g; ++j1)
{
int l1 = (this.field_187285_e[j1] >> 12 & 15) + this.field_187284_d.field_77276_a * 16;
int j2 = this.field_187285_e[j1] & 255;
int l2 = (this.field_187285_e[j1] >> 8 & 15) + this.field_187284_d.field_77275_b * 16;
BlockPos blockpos1 = new BlockPos(l1, j2, l2);
+ net.minecraft.block.state.IBlockState state = PlayerManager.this.func_72688_a().func_180495_p(blockpos1);
- if (PlayerManager.this.func_72688_a().func_180495_p(blockpos1).func_177230_c().func_149716_u())
+ if (state.func_177230_c().hasTileEntity(state))
{
this.func_187273_a(PlayerManager.this.func_72688_a().func_175625_s(blockpos1));
}

View file

@ -1,223 +0,0 @@
++++ REJECTED PATCH 1
int j = (int)player.posZ >> 4;
player.managedPosX = player.posX;
player.managedPosZ = player.posZ;
+ // Load nearby chunks first
+ List<ChunkCoordIntPair> chunkList = Lists.newArrayList();
for (int k = i - this.playerViewRadius; k <= i + this.playerViewRadius; ++k)
{
for (int l = j - this.playerViewRadius; l <= j + this.playerViewRadius; ++l)
{
- this.getPlayerInstance(k, l, true).addPlayer(player);
+ chunkList.add(new ChunkCoordIntPair(k, l));
}
}
+ java.util.Collections.sort(chunkList, new net.minecraftforge.common.util.ChunkCoordComparator(player));
+
+ for (ChunkCoordIntPair pair : chunkList)
+ {
+ this.getPlayerInstance(pair.chunkXPos, pair.chunkZPos, true).addPlayer(player);
+ }
+
this.players.add(player);
this.filterChunkLoadQueue(player);
}
++++ END PATCH
++++ REJECTED PATCH 3
{
if (!this.overlaps(l1, i2, k, l, i1))
{
- this.getPlayerInstance(l1, i2, true).addPlayer(player);
+ chunksToLoad.add(new ChunkCoordIntPair(l1, i2));
}
if (!this.overlaps(l1 - j1, i2 - k1, i, j, i1))
++++ END PATCH
++++ REJECTED PATCH 4
this.filterChunkLoadQueue(player);
player.managedPosX = player.posX;
player.managedPosZ = player.posZ;
+ // send nearest chunks first
+ java.util.Collections.sort(chunksToLoad, new net.minecraftforge.common.util.ChunkCoordComparator(player));
+
+ for (ChunkCoordIntPair pair : chunksToLoad)
+ {
+ this.getPlayerInstance(pair.chunkXPos, pair.chunkZPos, true).addPlayer(player);
+ }
+
+ if (i1 > 1 || i1 < -1 || j1 > 1 || j1 < -1)
+ {
+ java.util.Collections.sort(player.loadedChunks, new net.minecraftforge.common.util.ChunkCoordComparator(player));
+ }
}
}
}
++++ END PATCH
++++ REJECTED PATCH 5
private int numBlocksToUpdate;
private int flagsYAreasToUpdate;
private long previousWorldTime;
+ private final java.util.HashMap<EntityPlayerMP, Runnable> players = new java.util.HashMap<EntityPlayerMP, Runnable>();
+ private boolean loaded = false;
+ private Runnable loadedRunnable = new Runnable()
+ {
+ public void run()
+ {
+ PlayerInstance.this.loaded = true;
+ }
+ };
public PlayerInstance(int chunkX, int chunkZ)
{
this.chunkCoords = new ChunkCoordIntPair(chunkX, chunkZ);
- PlayerManager.this.getWorldServer().theChunkProviderServer.loadChunk(chunkX, chunkZ);
+ PlayerManager.this.getWorldServer().theChunkProviderServer.loadChunk(chunkX, chunkZ, this.loadedRunnable);
}
public void addPlayer(EntityPlayerMP player)
++++ END PATCH
++++ REJECTED PATCH 6
}
this.playersWatchingChunk.add(player);
+ Runnable playerRunnable = null;
+ if (this.loaded)
+ {
player.loadedChunks.add(this.chunkCoords);
+ }
+ else
+ {
+ final EntityPlayerMP tmp = player;
+ playerRunnable = new Runnable()
+ {
+ public void run()
+ {
+ tmp.loadedChunks.add(PlayerInstance.this.chunkCoords);
+ }
+ };
+ PlayerManager.this.getWorldServer().theChunkProviderServer.loadChunk(this.chunkCoords.chunkXPos, this.chunkCoords.chunkZPos, playerRunnable);
+ }
+ this.players.put(player, playerRunnable);
}
}
++++ END PATCH
++++ REJECTED PATCH 7
{
if (this.playersWatchingChunk.contains(player))
{
+ // If we haven't loaded yet don't load the chunk just so we can clean it up
+ if (!this.loaded)
+ {
+ net.minecraftforge.common.chunkio.ChunkIOExecutor.dropQueuedChunkLoad(PlayerManager.this.getWorldServer(), this.chunkCoords.chunkXPos, this.chunkCoords.chunkZPos, this.players.get(player));
+ this.playersWatchingChunk.remove(player);
+ this.players.remove(player);
+
+ if (this.playersWatchingChunk.isEmpty())
+ {
+ net.minecraftforge.common.chunkio.ChunkIOExecutor.dropQueuedChunkLoad(PlayerManager.this.getWorldServer(), this.chunkCoords.chunkXPos, this.chunkCoords.chunkZPos, this.loadedRunnable);
+ long i = (long) this.chunkCoords.chunkXPos + 2147483647L | (long) this.chunkCoords.chunkZPos + 2147483647L << 32;
+ PlayerManager.this.playerInstances.remove(i);
+ PlayerManager.this.playerInstanceList.remove(this);
+ }
+
+ return;
+ }
+
Chunk chunk = PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkCoords.chunkXPos, this.chunkCoords.chunkZPos);
if (chunk.isPopulated())
++++ END PATCH
++++ REJECTED PATCH 8
player.playerNetServerHandler.sendPacket(new S21PacketChunkData(chunk, true, 0));
}
+ this.players.remove(player);
this.playersWatchingChunk.remove(player);
player.loadedChunks.remove(this.chunkCoords);
+ net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.event.world.ChunkWatchEvent.UnWatch(chunkCoords, player));
+
if (this.playersWatchingChunk.isEmpty())
{
long i = (long)this.chunkCoords.chunkXPos + 2147483647L | (long)this.chunkCoords.chunkZPos + 2147483647L << 32;
++++ END PATCH
++++ REJECTED PATCH 9
this.flagsYAreasToUpdate |= 1 << (y >> 4);
- if (this.numBlocksToUpdate < 64)
+ //Forge; Cache everything, so always run
{
short short1 = (short)(x << 12 | z << 8 | y);
++++ END PATCH
++++ REJECTED PATCH 10
}
}
+ if (numBlocksToUpdate == locationOfBlockChange.length)
+ {
+ locationOfBlockChange = java.util.Arrays.copyOf(locationOfBlockChange, locationOfBlockChange.length << 1);
+ }
this.locationOfBlockChange[this.numBlocksToUpdate++] = short1;
}
}
++++ END PATCH
++++ REJECTED PATCH 11
}
}
+ @SuppressWarnings("unused")
public void onUpdate()
{
if (this.numBlocksToUpdate != 0)
++++ END PATCH
++++ REJECTED PATCH 12
BlockPos blockpos = new BlockPos(i, j, k);
this.sendToAllPlayersWatchingChunk(new S23PacketBlockChange(PlayerManager.this.theWorldServer, blockpos));
- if (PlayerManager.this.theWorldServer.getBlockState(blockpos).getBlock().hasTileEntity())
+ if (PlayerManager.this.theWorldServer.getBlockState(blockpos).getBlock().hasTileEntity(PlayerManager.this.theWorldServer.getBlockState(blockpos)))
{
this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(blockpos));
}
}
- else if (this.numBlocksToUpdate == 64)
+ else if (this.numBlocksToUpdate >= net.minecraftforge.common.ForgeModContainer.clumpingThreshold)
{
int i1 = this.chunkCoords.chunkXPos * 16;
int k1 = this.chunkCoords.chunkZPos * 16;
this.sendToAllPlayersWatchingChunk(new S21PacketChunkData(PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkCoords.chunkXPos, this.chunkCoords.chunkZPos), false, this.flagsYAreasToUpdate));
- for (int i2 = 0; i2 < 16; ++i2)
+ // Forge: Grabs ALL tile entities is costly on a modded server, only send needed ones
+ for (int i2 = 0; false && i2 < 16; ++i2)
{
if ((this.flagsYAreasToUpdate & 1 << i2) != 0)
{
++++ END PATCH
++++ REJECTED PATCH 13
else
{
this.sendToAllPlayersWatchingChunk(new S22PacketMultiBlockChange(this.numBlocksToUpdate, this.locationOfBlockChange, PlayerManager.this.theWorldServer.getChunkFromChunkCoords(this.chunkCoords.chunkXPos, this.chunkCoords.chunkZPos)));
-
+ }
+ { // Forge: Send only the tile entities that are updated, Adding this brace lets us keep the indent and the patch small
+ WorldServer world = PlayerManager.this.theWorldServer;
for (int j1 = 0; j1 < this.numBlocksToUpdate; ++j1)
{
int l1 = (this.locationOfBlockChange[j1] >> 12 & 15) + this.chunkCoords.chunkXPos * 16;
++++ END PATCH
++++ REJECTED PATCH 14
int l2 = (this.locationOfBlockChange[j1] >> 8 & 15) + this.chunkCoords.chunkZPos * 16;
BlockPos blockpos1 = new BlockPos(l1, j2, l2);
- if (PlayerManager.this.theWorldServer.getBlockState(blockpos1).getBlock().hasTileEntity())
+ if (world.getBlockState(blockpos1).getBlock().hasTileEntity(world.getBlockState(blockpos1)))
{
this.sendTileToAllPlayersWatchingChunk(PlayerManager.this.theWorldServer.getTileEntity(blockpos1));
}
++++ END PATCH

View file

@ -279,3 +279,6 @@ public-f net/minecraft/world/gen/ChunkProviderHell/field_185946_g #scale
public-f net/minecraft/world/gen/ChunkProviderHell/field_185947_h #depth
private-f net/minecraft/world/gen/ChunkProviderHell/field_185939_I #netherCaveGenerator
private-f net/minecraft/world/gen/ChunkProviderHell/field_73172_c #netherBridgeGenerator
# PlayerManager
private-f net.minecraft.server.management.PlayerManager$PlayerInstance field_187285_e # field_187285_e