2011-02-05 19:15:04 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2012-07-29 09:33:13 +02:00
|
|
|
import java.util.Iterator;
|
2011-02-05 19:15:04 +01:00
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
class PlayerInstance {
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
private final List b;
|
|
|
|
private final ChunkCoordIntPair location;
|
2011-04-20 19:05:14 +02:00
|
|
|
private short[] dirtyBlocks;
|
|
|
|
private int dirtyCount;
|
2012-07-29 09:33:13 +02:00
|
|
|
private int f;
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
final PlayerManager playerManager;
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2011-02-07 00:47:44 +01:00
|
|
|
public PlayerInstance(PlayerManager playermanager, int i, int j) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.playerManager = playermanager;
|
2011-02-05 19:15:04 +01:00
|
|
|
this.b = new ArrayList();
|
2012-03-01 11:49:23 +01:00
|
|
|
this.dirtyBlocks = new short[64];
|
2011-04-20 19:05:14 +02:00
|
|
|
this.dirtyCount = 0;
|
2011-06-27 00:25:01 +02:00
|
|
|
this.location = new ChunkCoordIntPair(i, j);
|
2011-05-26 14:48:22 +02:00
|
|
|
playermanager.a().chunkProviderServer.getChunkAt(i, j);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(EntityPlayer entityplayer) {
|
|
|
|
if (this.b.contains(entityplayer)) {
|
2012-07-29 09:33:13 +02:00
|
|
|
throw new IllegalStateException("Failed to add player. " + entityplayer + " already is in chunk " + this.location.x + ", " + this.location.z);
|
2011-02-05 19:15:04 +01:00
|
|
|
} else {
|
|
|
|
this.b.add(entityplayer);
|
2011-06-27 00:25:01 +02:00
|
|
|
entityplayer.chunkCoordIntPairQueue.add(this.location);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void b(EntityPlayer entityplayer) {
|
2011-05-31 15:55:45 +02:00
|
|
|
if (this.b.contains(entityplayer)) {
|
2012-07-29 09:33:13 +02:00
|
|
|
entityplayer.netServerHandler.sendPacket(new Packet51MapChunk(PlayerManager.a(this.playerManager).getChunkAt(this.location.x, this.location.z), true, 0));
|
2011-02-05 19:15:04 +01:00
|
|
|
this.b.remove(entityplayer);
|
2012-07-29 09:33:13 +02:00
|
|
|
entityplayer.chunkCoordIntPairQueue.remove(this.location);
|
|
|
|
if (this.b.isEmpty()) {
|
|
|
|
long i = (long) this.location.x + 2147483647L | (long) this.location.z + 2147483647L << 32;
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
PlayerManager.b(this.playerManager).remove(i);
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.dirtyCount > 0) {
|
2012-07-29 09:33:13 +02:00
|
|
|
PlayerManager.c(this.playerManager).remove(this);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
this.playerManager.a().chunkProviderServer.queueUnload(this.location.x, this.location.z);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a(int i, int j, int k) {
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.dirtyCount == 0) {
|
2012-07-29 09:33:13 +02:00
|
|
|
PlayerManager.c(this.playerManager).add(this);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
this.f |= 1 << (j >> 4);
|
2012-03-01 11:49:23 +01:00
|
|
|
if (this.dirtyCount < 64) {
|
2011-02-05 19:15:04 +01:00
|
|
|
short short1 = (short) (i << 12 | k << 8 | j);
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (int l = 0; l < this.dirtyCount; ++l) {
|
|
|
|
if (this.dirtyBlocks[l] == short1) {
|
2011-02-05 19:15:04 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
this.dirtyBlocks[this.dirtyCount++] = short1;
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
public void sendAll(Packet packet) {
|
2012-07-29 09:33:13 +02:00
|
|
|
Iterator iterator = this.b.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
EntityPlayer entityplayer = (EntityPlayer) iterator.next();
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
if (!entityplayer.chunkCoordIntPairQueue.contains(this.location)) {
|
2011-04-20 19:05:14 +02:00
|
|
|
entityplayer.netServerHandler.sendPacket(packet);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void a() {
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.dirtyCount != 0) {
|
2011-02-05 19:15:04 +01:00
|
|
|
int i;
|
|
|
|
int j;
|
|
|
|
int k;
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
if (this.dirtyCount == 1) {
|
2012-07-29 09:33:13 +02:00
|
|
|
i = this.location.x * 16 + (this.dirtyBlocks[0] >> 12 & 15);
|
2012-03-01 11:49:23 +01:00
|
|
|
j = this.dirtyBlocks[0] & 255;
|
2012-07-29 09:33:13 +02:00
|
|
|
k = this.location.z * 16 + (this.dirtyBlocks[0] >> 8 & 15);
|
|
|
|
this.sendAll(new Packet53BlockChange(i, j, k, PlayerManager.a(this.playerManager)));
|
|
|
|
if (PlayerManager.a(this.playerManager).isTileEntity(i, j, k)) {
|
|
|
|
this.sendTileEntity(PlayerManager.a(this.playerManager).getTileEntity(i, j, k));
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int l;
|
|
|
|
|
2012-03-01 11:49:23 +01:00
|
|
|
if (this.dirtyCount == 64) {
|
2012-07-29 09:33:13 +02:00
|
|
|
i = this.location.x * 16;
|
|
|
|
j = this.location.z * 16;
|
|
|
|
this.sendAll(new Packet51MapChunk(PlayerManager.a(this.playerManager).getChunkAt(this.location.x, this.location.z), (this.f == 0xFFFF), this.f)); // CraftBukkit - send everything (including biome) if all sections flagged
|
2012-03-01 11:49:23 +01:00
|
|
|
|
|
|
|
for (k = 0; k < 16; ++k) {
|
2012-07-29 09:33:13 +02:00
|
|
|
if ((this.f & 1 << k) != 0) {
|
2012-03-01 11:49:23 +01:00
|
|
|
l = k << 4;
|
2012-07-29 09:33:13 +02:00
|
|
|
List list = PlayerManager.a(this.playerManager).getTileEntities(i, l, j, i + 16, l + 16, j + 16);
|
|
|
|
Iterator iterator = list.iterator();
|
|
|
|
|
|
|
|
while (iterator.hasNext()) {
|
|
|
|
TileEntity tileentity = (TileEntity) iterator.next();
|
2012-03-01 11:49:23 +01:00
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
this.sendTileEntity(tileentity);
|
2012-03-01 11:49:23 +01:00
|
|
|
}
|
|
|
|
}
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
} else {
|
2012-07-29 09:33:13 +02:00
|
|
|
this.sendAll(new Packet52MultiBlockChange(this.location.x, this.location.z, this.dirtyBlocks, this.dirtyCount, PlayerManager.a(this.playerManager)));
|
2011-02-05 19:15:04 +01:00
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
for (i = 0; i < this.dirtyCount; ++i) {
|
2012-07-29 09:33:13 +02:00
|
|
|
j = this.location.x * 16 + (this.dirtyBlocks[i] >> 12 & 15);
|
2011-05-16 04:54:13 +02:00
|
|
|
k = this.dirtyBlocks[i] & 255;
|
2012-07-29 09:33:13 +02:00
|
|
|
l = this.location.z * 16 + (this.dirtyBlocks[i] >> 8 & 15);
|
|
|
|
if (PlayerManager.a(this.playerManager).isTileEntity(j, k, l)) {
|
|
|
|
this.sendTileEntity(PlayerManager.a(this.playerManager).getTileEntity(j, k, l));
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
this.dirtyCount = 0;
|
2012-07-29 09:33:13 +02:00
|
|
|
this.f = 0;
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-04-20 19:05:14 +02:00
|
|
|
private void sendTileEntity(TileEntity tileentity) {
|
2011-02-05 19:15:04 +01:00
|
|
|
if (tileentity != null) {
|
2012-07-29 09:33:13 +02:00
|
|
|
Packet packet = tileentity.e();
|
2011-02-05 19:15:04 +01:00
|
|
|
|
|
|
|
if (packet != null) {
|
2011-04-20 19:05:14 +02:00
|
|
|
this.sendAll(packet);
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-07-29 09:33:13 +02:00
|
|
|
|
|
|
|
static ChunkCoordIntPair a(PlayerInstance playerinstance) {
|
|
|
|
return playerinstance.location;
|
|
|
|
}
|
|
|
|
|
|
|
|
static List b(PlayerInstance playerinstance) {
|
|
|
|
return playerinstance.b;
|
|
|
|
}
|
2011-02-05 19:15:04 +01:00
|
|
|
}
|