2012-03-09 06:49:05 +01:00
|
|
|
package net.minecraft.server;
|
|
|
|
|
|
|
|
public class ChunkSection {
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
private int yPos;
|
|
|
|
private int nonEmptyBlockCount;
|
|
|
|
private int tickingBlockCount;
|
|
|
|
private byte[] blockIds;
|
|
|
|
private NibbleArray extBlockIds;
|
|
|
|
private NibbleArray blockData;
|
|
|
|
private NibbleArray blockLight;
|
|
|
|
private NibbleArray skyLight;
|
2012-03-09 06:49:05 +01:00
|
|
|
|
|
|
|
public ChunkSection(int i) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.yPos = i;
|
|
|
|
this.blockIds = new byte[4096];
|
|
|
|
this.blockData = new NibbleArray(this.blockIds.length, 4);
|
|
|
|
this.skyLight = new NibbleArray(this.blockIds.length, 4);
|
|
|
|
this.blockLight = new NibbleArray(this.blockIds.length, 4);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-03-09 06:57:26 +01:00
|
|
|
// CraftBukkit start
|
2012-10-25 05:53:23 +02:00
|
|
|
public ChunkSection(int y, byte[] blkIds, byte[] extBlkIds) {
|
|
|
|
this.yPos = y;
|
|
|
|
this.blockIds = blkIds;
|
|
|
|
if (extBlkIds != null) {
|
|
|
|
this.extBlockIds = new NibbleArray(extBlkIds, 4);
|
2012-03-09 06:57:26 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
this.blockData = new NibbleArray(this.blockIds.length, 4);
|
|
|
|
this.blockLight = new NibbleArray(this.blockIds.length, 4);
|
|
|
|
this.skyLight = new NibbleArray(this.blockIds.length, 4);
|
|
|
|
this.recalcBlockCounts();
|
2012-03-09 06:57:26 +01:00
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-03-09 06:49:05 +01:00
|
|
|
public int a(int i, int j, int k) {
|
2012-10-25 05:53:23 +02:00
|
|
|
int l = this.blockIds[j << 8 | k << 4 | i] & 255;
|
2012-03-09 06:49:05 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.extBlockIds != null ? this.extBlockIds.a(i, j, k) << 8 | l : l;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(int i, int j, int k, int l) {
|
2012-10-25 05:53:23 +02:00
|
|
|
int i1 = this.blockIds[j << 8 | k << 4 | i] & 255;
|
2012-03-09 06:49:05 +01:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.extBlockIds != null) {
|
|
|
|
i1 |= this.extBlockIds.a(i, j, k) << 8;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (i1 == 0 && l != 0) {
|
2012-10-25 05:53:23 +02:00
|
|
|
++this.nonEmptyBlockCount;
|
|
|
|
if (Block.byId[l] != null && Block.byId[l].isTicking()) {
|
|
|
|
++this.tickingBlockCount;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
} else if (i1 != 0 && l == 0) {
|
2012-10-25 05:53:23 +02:00
|
|
|
--this.nonEmptyBlockCount;
|
|
|
|
if (Block.byId[i1] != null && Block.byId[i1].isTicking()) {
|
|
|
|
--this.tickingBlockCount;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
} else if (Block.byId[i1] != null && Block.byId[i1].isTicking() && (Block.byId[l] == null || !Block.byId[l].isTicking())) {
|
|
|
|
--this.tickingBlockCount;
|
|
|
|
} else if ((Block.byId[i1] == null || !Block.byId[i1].isTicking()) && Block.byId[l] != null && Block.byId[l].isTicking()) {
|
|
|
|
++this.tickingBlockCount;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.blockIds[j << 8 | k << 4 | i] = (byte) (l & 255);
|
2012-03-09 06:49:05 +01:00
|
|
|
if (l > 255) {
|
2012-10-25 05:53:23 +02:00
|
|
|
if (this.extBlockIds == null) {
|
|
|
|
this.extBlockIds = new NibbleArray(this.blockIds.length, 4);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.extBlockIds.a(i, j, k, (l & 3840) >> 8);
|
|
|
|
} else if (this.extBlockIds != null) {
|
|
|
|
this.extBlockIds.a(i, j, k, 0);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int b(int i, int j, int k) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.blockData.a(i, j, k);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(int i, int j, int k, int l) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.blockData.a(i, j, k, l);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean a() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.nonEmptyBlockCount == 0;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public boolean b() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.tickingBlockCount > 0;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public int d() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.yPos;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void c(int i, int j, int k, int l) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.skyLight.a(i, j, k, l);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int c(int i, int j, int k) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.skyLight.a(i, j, k);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void d(int i, int j, int k, int l) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.blockLight.a(i, j, k, l);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public int d(int i, int j, int k) {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.blockLight.a(i, j, k);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void recalcBlockCounts() {
|
2012-08-09 08:10:12 +02:00
|
|
|
// CraftBukkit start - optimize for speed
|
2012-10-25 05:53:23 +02:00
|
|
|
byte[] blkIds = this.blockIds;
|
|
|
|
int cntNonEmpty = 0;
|
|
|
|
int cntTicking = 0;
|
|
|
|
if (this.extBlockIds == null) { // No extended block IDs? Don't waste time messing with them
|
|
|
|
for (int off = 0; off < blkIds.length; off++) {
|
|
|
|
int l = blkIds[off] & 0xFF;
|
2012-08-09 08:10:12 +02:00
|
|
|
if (l > 0) {
|
|
|
|
if (Block.byId[l] == null) {
|
2012-10-25 05:53:23 +02:00
|
|
|
blkIds[off] = 0;
|
2012-08-09 08:10:12 +02:00
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
++cntNonEmpty;
|
|
|
|
if (Block.byId[l].isTicking()) {
|
|
|
|
++cntTicking;
|
2012-08-09 08:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
byte[] ext = this.extBlockIds.a;
|
|
|
|
for (int off = 0, off2 = 0; off < blkIds.length;) {
|
2012-08-09 08:10:12 +02:00
|
|
|
byte extid = ext[off2];
|
2012-10-25 05:53:23 +02:00
|
|
|
int l = (blkIds[off] & 0xFF) | ((extid & 0xF) << 8); // Even data
|
2012-08-09 08:10:12 +02:00
|
|
|
if (l > 0) {
|
|
|
|
if (Block.byId[l] == null) {
|
2012-10-25 05:53:23 +02:00
|
|
|
blkIds[off] = 0;
|
2012-08-09 08:10:12 +02:00
|
|
|
ext[off2] &= 0xF0;
|
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
++cntNonEmpty;
|
|
|
|
if (Block.byId[l].isTicking()) {
|
|
|
|
++cntTicking;
|
2012-08-09 08:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
off++;
|
2012-10-25 05:53:23 +02:00
|
|
|
l = (blkIds[off] & 0xFF) | ((extid & 0xF0) << 4); // Odd data
|
2012-08-09 08:10:12 +02:00
|
|
|
if (l > 0) {
|
|
|
|
if (Block.byId[l] == null) {
|
2012-10-25 05:53:23 +02:00
|
|
|
blkIds[off] = 0;
|
2012-08-09 08:10:12 +02:00
|
|
|
ext[off2] &= 0x0F;
|
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
++cntNonEmpty;
|
|
|
|
if (Block.byId[l].isTicking()) {
|
|
|
|
++cntTicking;
|
2012-08-09 08:10:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
off++;
|
|
|
|
off2++;
|
|
|
|
}
|
|
|
|
}
|
2012-10-25 05:53:23 +02:00
|
|
|
this.nonEmptyBlockCount = cntNonEmpty;
|
|
|
|
this.tickingBlockCount = cntTicking;
|
2012-08-09 08:10:12 +02:00
|
|
|
}
|
2012-09-14 07:03:47 +02:00
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
public void old_recalcBlockCounts() {
|
2012-08-09 08:10:12 +02:00
|
|
|
// CraftBukkit end
|
2012-10-25 05:53:23 +02:00
|
|
|
this.nonEmptyBlockCount = 0;
|
|
|
|
this.tickingBlockCount = 0;
|
2012-03-09 06:49:05 +01:00
|
|
|
|
|
|
|
for (int i = 0; i < 16; ++i) {
|
|
|
|
for (int j = 0; j < 16; ++j) {
|
|
|
|
for (int k = 0; k < 16; ++k) {
|
|
|
|
int l = this.a(i, j, k);
|
|
|
|
|
|
|
|
if (l > 0) {
|
|
|
|
if (Block.byId[l] == null) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.blockIds[j << 8 | k << 4 | i] = 0;
|
|
|
|
if (this.extBlockIds != null) {
|
|
|
|
this.extBlockIds.a(i, j, k, 0);
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
} else {
|
2012-10-25 05:53:23 +02:00
|
|
|
++this.nonEmptyBlockCount;
|
|
|
|
if (Block.byId[l].isTicking()) {
|
|
|
|
++this.tickingBlockCount;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public byte[] g() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.blockIds;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public NibbleArray i() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.extBlockIds;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public NibbleArray j() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.blockData;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public NibbleArray k() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.blockLight;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
2012-07-29 09:33:13 +02:00
|
|
|
public NibbleArray l() {
|
2012-10-25 05:53:23 +02:00
|
|
|
return this.skyLight;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(byte[] abyte) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.blockIds = abyte;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void a(NibbleArray nibblearray) {
|
2012-11-14 18:22:15 +01:00
|
|
|
// CraftBukkit start - don't hang on to an empty nibble array
|
|
|
|
boolean empty = true;
|
|
|
|
for (int i = 0; i < nibblearray.a.length; i++) {
|
|
|
|
if (nibblearray.a[i] != 0) {
|
|
|
|
empty = false;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
// CraftBukkit end
|
|
|
|
|
2012-10-25 05:53:23 +02:00
|
|
|
this.extBlockIds = nibblearray;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void b(NibbleArray nibblearray) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.blockData = nibblearray;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void c(NibbleArray nibblearray) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.blockLight = nibblearray;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public void d(NibbleArray nibblearray) {
|
2012-10-25 05:53:23 +02:00
|
|
|
this.skyLight = nibblearray;
|
2012-03-09 06:49:05 +01:00
|
|
|
}
|
|
|
|
}
|