Paper/src/main/java/net/minecraft/server/Chunk.java

1071 Zeilen
33 KiB
Java

2011-02-01 23:49:28 +01:00
package net.minecraft.server;
2012-07-29 09:33:13 +02:00
import java.util.ArrayList;
2011-09-15 02:23:52 +02:00
import java.util.Arrays;
2011-02-01 23:49:28 +01:00
import java.util.HashMap;
2011-06-30 00:02:25 +02:00
import java.util.Iterator;
2011-02-01 23:49:28 +01:00
import java.util.List;
import java.util.Map;
import java.util.Random;
2013-11-04 14:07:38 +01:00
import java.util.concurrent.Callable;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
2013-03-25 05:22:32 +01:00
import org.bukkit.Bukkit; // CraftBukkit
2011-02-01 23:49:28 +01:00
public class Chunk {
2013-11-04 14:07:38 +01:00
private static final Logger t = LogManager.getLogger();
2011-02-01 23:49:28 +01:00
public static boolean a;
2012-03-01 11:49:23 +01:00
private ChunkSection[] sections;
2013-11-04 14:07:38 +01:00
private byte[] v;
2012-03-01 11:49:23 +01:00
public int[] b;
public boolean[] c;
public boolean d;
public World world;
2012-03-01 11:49:23 +01:00
public int[] heightMap;
2013-11-04 14:07:38 +01:00
public final int locX;
public final int locZ;
private boolean w;
public Map tileEntities;
public List[] entitySlices;
public boolean done;
2013-11-04 14:07:38 +01:00
public boolean lit;
2012-03-01 11:49:23 +01:00
public boolean m;
2013-11-04 14:07:38 +01:00
public boolean n;
public boolean o;
public long p;
public boolean q;
public int r;
public long s;
private int x;
2011-02-01 23:49:28 +01:00
public Chunk(World world, int i, int j) {
2012-03-01 11:49:23 +01:00
this.sections = new ChunkSection[16];
2013-11-04 14:07:38 +01:00
this.v = new byte[256];
2012-03-01 11:49:23 +01:00
this.b = new int[256];
this.c = new boolean[256];
this.tileEntities = new HashMap();
2013-11-04 14:07:38 +01:00
this.x = 4096;
2012-03-01 11:49:23 +01:00
this.entitySlices = new List[16];
this.world = world;
2013-11-04 14:07:38 +01:00
this.locX = i;
this.locZ = j;
2012-03-01 11:49:23 +01:00
this.heightMap = new int[256];
2011-02-01 23:49:28 +01:00
for (int k = 0; k < this.entitySlices.length; ++k) {
this.entitySlices[k] = new org.bukkit.craftbukkit.util.UnsafeList(); // CraftBukkit - ArrayList -> UnsafeList
2011-02-01 23:49:28 +01:00
}
2012-03-01 11:49:23 +01:00
Arrays.fill(this.b, -999);
2013-11-04 14:07:38 +01:00
Arrays.fill(this.v, (byte) -1);
2011-09-15 02:23:52 +02:00
2011-02-01 23:49:28 +01:00
// CraftBukkit start
if (!(this instanceof EmptyChunk)) {
this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
}
2011-02-01 23:49:28 +01:00
}
public org.bukkit.Chunk bukkitChunk;
public boolean mustSave;
2011-02-01 23:49:28 +01:00
// CraftBukkit end
2013-11-04 14:07:38 +01:00
public Chunk(World world, Block[] ablock, int i, int j) {
2011-02-01 23:49:28 +01:00
this(world, i, j);
2013-11-04 14:07:38 +01:00
int k = ablock.length / 256;
boolean flag = !world.worldProvider.g;
2012-03-01 11:49:23 +01:00
for (int l = 0; l < 16; ++l) {
for (int i1 = 0; i1 < 16; ++i1) {
for (int j1 = 0; j1 < k; ++j1) {
2013-11-04 14:07:38 +01:00
Block block = ablock[l << 11 | i1 << 7 | j1];
2012-03-01 11:49:23 +01:00
2013-11-04 14:07:38 +01:00
if (block != null && block.getMaterial() != Material.AIR) {
2012-03-01 11:49:23 +01:00
int k1 = j1 >> 4;
if (this.sections[k1] == null) {
2013-11-04 14:07:38 +01:00
this.sections[k1] = new ChunkSection(k1 << 4, flag);
}
this.sections[k1].setTypeId(l, j1 & 15, i1, block);
}
}
}
}
}
public Chunk(World world, Block[] ablock, byte[] abyte, int i, int j) {
this(world, i, j);
int k = ablock.length / 256;
boolean flag = !world.worldProvider.g;
for (int l = 0; l < 16; ++l) {
for (int i1 = 0; i1 < 16; ++i1) {
for (int j1 = 0; j1 < k; ++j1) {
int k1 = l * k * 16 | i1 * k | j1;
Block block = ablock[k1];
if (block != null && block != Blocks.AIR) {
int l1 = j1 >> 4;
if (this.sections[l1] == null) {
this.sections[l1] = new ChunkSection(l1 << 4, flag);
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
this.sections[l1].setTypeId(l, j1 & 15, i1, block);
this.sections[l1].setData(l, j1 & 15, i1, abyte[k1]);
2012-03-01 11:49:23 +01:00
}
}
}
}
2011-02-01 23:49:28 +01:00
}
public boolean a(int i, int j) {
2013-11-04 14:07:38 +01:00
return i == this.locX && j == this.locZ;
2011-02-01 23:49:28 +01:00
}
public int b(int i, int j) {
2012-03-01 11:49:23 +01:00
return this.heightMap[j << 4 | i];
2011-02-01 23:49:28 +01:00
}
2012-07-29 09:33:13 +02:00
public int h() {
2012-03-01 11:49:23 +01:00
for (int i = this.sections.length - 1; i >= 0; --i) {
if (this.sections[i] != null) {
2013-04-27 11:40:05 +02:00
return this.sections[i].getYPosition();
2012-03-01 11:49:23 +01:00
}
}
return 0;
}
2012-07-29 09:33:13 +02:00
public ChunkSection[] i() {
2012-03-01 11:49:23 +01:00
return this.sections;
}
2011-02-01 23:49:28 +01:00
public void initLighting() {
2012-07-29 09:33:13 +02:00
int i = this.h();
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
this.r = Integer.MAX_VALUE;
2013-11-04 14:07:38 +01:00
for (int j = 0; j < 16; ++j) {
int k = 0;
2011-09-15 05:13:14 +02:00
2012-03-01 11:49:23 +01:00
while (k < 16) {
this.b[j + (k << 4)] = -999;
int l = i + 16 - 1;
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
while (true) {
if (l > 0) {
if (this.b(j, l - 1, k) == 0) {
--l;
continue;
}
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
this.heightMap[k << 4 | j] = l;
2013-11-04 14:07:38 +01:00
if (l < this.r) {
this.r = l;
}
2012-03-01 11:49:23 +01:00
}
2011-02-01 23:49:28 +01:00
2013-07-01 13:03:00 +02:00
if (!this.world.worldProvider.g) {
2012-03-01 11:49:23 +01:00
l = 15;
int i1 = i + 16 - 1;
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
do {
2013-11-04 14:07:38 +01:00
int j1 = this.b(j, i1, k);
if (j1 == 0 && l != 15) {
j1 = 1;
}
l -= j1;
2012-03-01 11:49:23 +01:00
if (l > 0) {
ChunkSection chunksection = this.sections[i1 >> 4];
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
if (chunksection != null) {
2013-04-27 11:40:05 +02:00
chunksection.setSkyLight(j, i1 & 15, k, l);
2013-11-04 14:07:38 +01:00
this.world.m((this.locX << 4) + j, i1, (this.locZ << 4) + k);
2012-03-01 11:49:23 +01:00
}
}
--i1;
} while (i1 > 0 && l > 0);
}
++k;
break;
2011-02-01 23:49:28 +01:00
}
}
}
2013-11-04 14:07:38 +01:00
this.n = true;
2011-02-01 23:49:28 +01:00
}
2012-03-01 11:49:23 +01:00
private void e(int i, int j) {
this.c[i + j * 16] = true;
2013-11-04 14:07:38 +01:00
this.w = true;
2011-11-20 09:01:14 +01:00
}
2013-11-04 14:07:38 +01:00
private void c(boolean flag) {
2012-07-29 09:33:13 +02:00
this.world.methodProfiler.a("recheckGaps");
2013-11-04 14:07:38 +01:00
if (this.world.areChunksLoaded(this.locX * 16 + 8, 0, this.locZ * 16 + 8, 16)) {
2011-11-20 09:01:14 +01:00
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
2012-03-01 11:49:23 +01:00
if (this.c[i + j * 16]) {
this.c[i + j * 16] = false;
2011-11-20 09:01:14 +01:00
int k = this.b(i, j);
2013-11-04 14:07:38 +01:00
int l = this.locX * 16 + i;
int i1 = this.locZ * 16 + j;
int j1 = this.world.g(l - 1, i1);
int k1 = this.world.g(l + 1, i1);
int l1 = this.world.g(l, i1 - 1);
int i2 = this.world.g(l, i1 + 1);
2011-11-20 09:01:14 +01:00
if (k1 < j1) {
j1 = k1;
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
if (l1 < j1) {
j1 = l1;
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
if (i2 < j1) {
j1 = i2;
2011-09-15 02:23:52 +02:00
}
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
this.g(l, i1, j1);
this.g(l - 1, i1, k);
this.g(l + 1, i1, k);
this.g(l, i1 - 1, k);
this.g(l, i1 + 1, k);
2013-11-04 14:07:38 +01:00
if (flag) {
this.world.methodProfiler.b();
return;
}
2011-09-15 02:23:52 +02:00
}
}
}
2012-03-01 11:49:23 +01:00
2013-11-04 14:07:38 +01:00
this.w = false;
2011-09-15 02:23:52 +02:00
}
2012-03-01 11:49:23 +01:00
2012-07-29 09:33:13 +02:00
this.world.methodProfiler.b();
2011-02-01 23:49:28 +01:00
}
2012-03-01 11:49:23 +01:00
private void g(int i, int j, int k) {
int l = this.world.getHighestBlockYAt(i, j);
2011-02-01 23:49:28 +01:00
if (l > k) {
2013-11-04 14:07:38 +01:00
this.c(i, j, k, l + 1);
2011-02-01 23:49:28 +01:00
} else if (l < k) {
2013-11-04 14:07:38 +01:00
this.c(i, j, l, k + 1);
2011-09-15 02:23:52 +02:00
}
}
2013-11-04 14:07:38 +01:00
private void c(int i, int j, int k, int l) {
2012-03-01 11:49:23 +01:00
if (l > k && this.world.areChunksLoaded(i, 0, j, 16)) {
2011-11-20 09:01:14 +01:00
for (int i1 = k; i1 < l; ++i1) {
2012-07-29 09:33:13 +02:00
this.world.c(EnumSkyBlock.SKY, i, i1, j);
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
2013-11-04 14:07:38 +01:00
this.n = true;
2011-02-01 23:49:28 +01:00
}
}
2012-03-01 11:49:23 +01:00
private void h(int i, int j, int k) {
int l = this.heightMap[k << 4 | i] & 255;
2011-02-01 23:49:28 +01:00
int i1 = l;
if (j > l) {
i1 = j;
}
2011-09-15 02:23:52 +02:00
2012-03-01 11:49:23 +01:00
while (i1 > 0 && this.b(i, i1 - 1, k) == 0) {
--i1;
2011-02-01 23:49:28 +01:00
}
if (i1 != l) {
2013-11-04 14:07:38 +01:00
this.world.b(i + this.locX * 16, k + this.locZ * 16, i1, l);
2012-03-01 11:49:23 +01:00
this.heightMap[k << 4 | i] = i1;
2013-11-04 14:07:38 +01:00
int j1 = this.locX * 16 + i;
int k1 = this.locZ * 16 + k;
2011-02-01 23:49:28 +01:00
int l1;
int i2;
2013-07-01 13:03:00 +02:00
if (!this.world.worldProvider.g) {
2012-03-01 11:49:23 +01:00
ChunkSection chunksection;
2011-02-01 23:49:28 +01:00
2011-11-20 09:01:14 +01:00
if (i1 < l) {
2012-03-01 11:49:23 +01:00
for (l1 = i1; l1 < l; ++l1) {
chunksection = this.sections[l1 >> 4];
if (chunksection != null) {
2013-04-27 11:40:05 +02:00
chunksection.setSkyLight(i, l1 & 15, k, 15);
2013-11-04 14:07:38 +01:00
this.world.m((this.locX << 4) + i, l1, (this.locZ << 4) + k);
2012-03-01 11:49:23 +01:00
}
2011-11-20 09:01:14 +01:00
}
} else {
2012-03-01 11:49:23 +01:00
for (l1 = l; l1 < i1; ++l1) {
chunksection = this.sections[l1 >> 4];
if (chunksection != null) {
2013-04-27 11:40:05 +02:00
chunksection.setSkyLight(i, l1 & 15, k, 0);
2013-11-04 14:07:38 +01:00
this.world.m((this.locX << 4) + i, l1, (this.locZ << 4) + k);
2012-03-01 11:49:23 +01:00
}
2011-11-20 09:01:14 +01:00
}
2011-02-01 23:49:28 +01:00
}
2012-03-01 11:49:23 +01:00
l1 = 15;
while (i1 > 0 && l1 > 0) {
2011-11-20 09:01:14 +01:00
--i1;
2012-03-01 11:49:23 +01:00
i2 = this.b(i, i1, k);
if (i2 == 0) {
i2 = 1;
}
l1 -= i2;
if (l1 < 0) {
l1 = 0;
2011-11-20 09:01:14 +01:00
}
2012-03-01 11:49:23 +01:00
ChunkSection chunksection1 = this.sections[i1 >> 4];
if (chunksection1 != null) {
2013-04-27 11:40:05 +02:00
chunksection1.setSkyLight(i, i1 & 15, k, l1);
2011-11-20 09:01:14 +01:00
}
2011-02-01 23:49:28 +01:00
}
}
2012-03-01 11:49:23 +01:00
l1 = this.heightMap[k << 4 | i];
i2 = l;
int j2 = l1;
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
if (l1 < l) {
i2 = l1;
j2 = l;
2011-11-20 09:01:14 +01:00
}
2013-11-04 14:07:38 +01:00
if (l1 < this.r) {
this.r = l1;
}
2013-07-01 13:03:00 +02:00
if (!this.world.worldProvider.g) {
2013-11-04 14:07:38 +01:00
this.c(j1 - 1, k1, i2, j2);
this.c(j1 + 1, k1, i2, j2);
this.c(j1, k1 - 1, i2, j2);
this.c(j1, k1 + 1, i2, j2);
this.c(j1, k1, i2, j2);
2011-02-01 23:49:28 +01:00
}
2013-11-04 14:07:38 +01:00
this.n = true;
2011-02-01 23:49:28 +01:00
}
}
2012-03-01 11:49:23 +01:00
public int b(int i, int j, int k) {
2013-11-04 14:07:38 +01:00
return this.getType(i, j, k).k();
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
public Block getType(int i, int j, int k) {
Block block = Blocks.AIR;
if (j >> 4 < this.sections.length) {
ChunkSection chunksection = this.sections[j >> 4];
2012-03-01 11:49:23 +01:00
2013-11-04 14:07:38 +01:00
if (chunksection != null) {
try {
block = chunksection.getTypeId(i, j & 15, k);
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Getting block");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Block being got");
crashreportsystemdetails.a("Location", (Callable) (new CrashReportLocation(this, i, j, k)));
throw new ReportedException(crashreport);
}
}
}
2013-11-04 14:07:38 +01:00
return block;
2012-03-01 11:49:23 +01:00
}
public int getData(int i, int j, int k) {
if (j >> 4 >= this.sections.length) {
return 0;
} else {
ChunkSection chunksection = this.sections[j >> 4];
2012-03-01 11:49:23 +01:00
2013-04-27 11:40:05 +02:00
return chunksection != null ? chunksection.getData(i, j & 15, k) : 0;
}
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
public boolean a(int i, int j, int k, Block block, int l) {
int i1 = k << 4 | i;
2011-09-15 02:23:52 +02:00
2013-11-04 14:07:38 +01:00
if (j >= this.b[i1] - 1) {
this.b[i1] = -999;
2011-09-15 02:23:52 +02:00
}
2013-11-04 14:07:38 +01:00
int j1 = this.heightMap[i1];
Block block1 = this.getType(i, j, k);
int k1 = this.getData(i, j, k);
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
if (block1 == block && k1 == l) {
2011-02-01 23:49:28 +01:00
return false;
} else {
2012-03-01 11:49:23 +01:00
ChunkSection chunksection = this.sections[j >> 4];
boolean flag = false;
if (chunksection == null) {
2013-11-04 14:07:38 +01:00
if (block == Blocks.AIR) {
2012-03-01 11:49:23 +01:00
return false;
}
2013-07-01 13:03:00 +02:00
chunksection = this.sections[j >> 4] = new ChunkSection(j >> 4 << 4, !this.world.worldProvider.g);
2013-11-04 14:07:38 +01:00
flag = j >= j1;
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
int l1 = this.locX * 16 + i;
int i2 = this.locZ * 16 + k;
2012-07-29 09:33:13 +02:00
2013-11-04 14:07:38 +01:00
if (!this.world.isStatic) {
block1.f(this.world, l1, j, i2, k1);
2012-07-29 09:33:13 +02:00
}
2011-09-15 05:13:14 +02:00
// CraftBukkit start - Delay removing containers until after they're cleaned up
if (!(block1 instanceof IContainer)) {
chunksection.setTypeId(i, j & 15, k, block);
}
// CraftBukkit end
2013-11-04 14:07:38 +01:00
if (!this.world.isStatic) {
block1.remove(this.world, l1, j, i2, block1, k1);
} else if (block1 instanceof IContainer && block1 != block) {
this.world.p(l1, j, i2);
2011-02-01 23:49:28 +01:00
}
// CraftBukkit start - Remove containers now after cleanup
if (block1 instanceof IContainer) {
chunksection.setTypeId(i, j & 15, k, block);
}
// CraftBukkit end
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
if (chunksection.getTypeId(i, j & 15, k) != block) {
return false;
2012-03-01 11:49:23 +01:00
} else {
2013-11-04 14:07:38 +01:00
chunksection.setData(i, j & 15, k, l);
if (flag) {
this.initLighting();
} else {
2013-11-04 14:07:38 +01:00
int j2 = block.k();
int k2 = block1.k();
if (j2 > 0) {
if (j >= j1) {
this.h(i, j + 1, k);
}
2013-11-04 14:07:38 +01:00
} else if (j == j1 - 1) {
this.h(i, j, k);
2011-02-01 23:49:28 +01:00
}
2013-11-04 14:07:38 +01:00
if (j2 != k2 && (j2 < k2 || this.getBrightness(EnumSkyBlock.SKY, i, j, k) > 0 || this.getBrightness(EnumSkyBlock.BLOCK, i, j, k) > 0)) {
this.e(i, k);
}
2011-02-01 23:49:28 +01:00
}
TileEntity tileentity;
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
if (block1 instanceof IContainer) {
tileentity = this.e(i, j, k);
if (tileentity != null) {
tileentity.u();
}
2013-11-04 14:07:38 +01:00
}
2011-09-15 02:23:52 +02:00
2013-11-04 14:07:38 +01:00
// CraftBukkit - Don't place while processing the BlockPlaceEvent, unless it's a BlockContainer
if (!this.world.isStatic && (!this.world.callingPlaceEvent || (block instanceof BlockContainer))) {
block.onPlace(this.world, l1, j, i2);
}
2011-09-15 02:23:52 +02:00
2013-11-04 14:07:38 +01:00
if (block instanceof IContainer) {
// CraftBukkit start - Don't create tile entity if placement failed
if (this.getType(i, j, k) != block) {
return false;
2011-09-15 02:23:52 +02:00
}
2013-11-04 14:07:38 +01:00
// CraftBukkit end
tileentity = this.e(i, j, k);
2013-11-04 14:07:38 +01:00
if (tileentity == null) {
tileentity = ((IContainer) block).a(this.world, l);
this.world.setTileEntity(l1, j, i2, tileentity);
}
2011-09-15 02:23:52 +02:00
if (tileentity != null) {
2013-11-04 14:07:38 +01:00
tileentity.u();
2011-09-15 02:23:52 +02:00
}
}
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
this.n = true;
return true;
}
2011-02-01 23:49:28 +01:00
}
}
2013-11-04 14:07:38 +01:00
public boolean a(int i, int j, int k, int l) {
2012-03-01 11:49:23 +01:00
ChunkSection chunksection = this.sections[j >> 4];
2011-09-15 02:23:52 +02:00
2012-03-01 11:49:23 +01:00
if (chunksection == null) {
2011-02-01 23:49:28 +01:00
return false;
} else {
2013-04-27 11:40:05 +02:00
int i1 = chunksection.getData(i, j & 15, k);
2011-09-15 02:23:52 +02:00
2012-03-01 11:49:23 +01:00
if (i1 == l) {
return false;
} else {
2013-11-04 14:07:38 +01:00
this.n = true;
2013-04-27 11:40:05 +02:00
chunksection.setData(i, j & 15, k, l);
2013-11-04 14:07:38 +01:00
if (chunksection.getTypeId(i, j & 15, k) instanceof IContainer) {
2012-03-01 11:49:23 +01:00
TileEntity tileentity = this.e(i, j, k);
2011-09-15 02:23:52 +02:00
if (tileentity != null) {
2013-11-04 14:07:38 +01:00
tileentity.u();
tileentity.g = l;
2011-09-15 02:23:52 +02:00
}
}
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
return true;
2011-09-15 02:23:52 +02:00
}
}
2011-02-01 23:49:28 +01:00
}
2012-02-29 22:31:04 +01:00
public int getBrightness(EnumSkyBlock enumskyblock, int i, int j, int k) {
2012-03-01 11:49:23 +01:00
ChunkSection chunksection = this.sections[j >> 4];
2013-07-01 13:03:00 +02:00
return chunksection == null ? (this.d(i, j, k) ? enumskyblock.c : 0) : (enumskyblock == EnumSkyBlock.SKY ? (this.world.worldProvider.g ? 0 : chunksection.getSkyLight(i, j & 15, k)) : (enumskyblock == EnumSkyBlock.BLOCK ? chunksection.getEmittedLight(i, j & 15, k) : enumskyblock.c));
2011-02-01 23:49:28 +01:00
}
public void a(EnumSkyBlock enumskyblock, int i, int j, int k, int l) {
2012-03-01 11:49:23 +01:00
ChunkSection chunksection = this.sections[j >> 4];
if (chunksection == null) {
2013-07-01 13:03:00 +02:00
chunksection = this.sections[j >> 4] = new ChunkSection(j >> 4 << 4, !this.world.worldProvider.g);
2012-03-01 11:49:23 +01:00
this.initLighting();
}
2013-11-04 14:07:38 +01:00
this.n = true;
2011-02-01 23:49:28 +01:00
if (enumskyblock == EnumSkyBlock.SKY) {
2013-07-01 13:03:00 +02:00
if (!this.world.worldProvider.g) {
2013-04-27 11:40:05 +02:00
chunksection.setSkyLight(i, j & 15, k, l);
2011-11-20 09:01:14 +01:00
}
2012-07-29 09:33:13 +02:00
} else if (enumskyblock == EnumSkyBlock.BLOCK) {
2013-04-27 11:40:05 +02:00
chunksection.setEmittedLight(i, j & 15, k, l);
2011-02-01 23:49:28 +01:00
}
}
2013-11-04 14:07:38 +01:00
public int b(int i, int j, int k, int l) {
2012-03-01 11:49:23 +01:00
ChunkSection chunksection = this.sections[j >> 4];
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
if (chunksection == null) {
2013-07-01 13:03:00 +02:00
return !this.world.worldProvider.g && l < EnumSkyBlock.SKY.c ? EnumSkyBlock.SKY.c - l : 0;
2012-03-01 11:49:23 +01:00
} else {
2013-07-01 13:03:00 +02:00
int i1 = this.world.worldProvider.g ? 0 : chunksection.getSkyLight(i, j & 15, k);
2012-03-01 11:49:23 +01:00
if (i1 > 0) {
a = true;
}
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
i1 -= l;
2013-04-27 11:40:05 +02:00
int j1 = chunksection.getEmittedLight(i, j & 15, k);
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
if (j1 > i1) {
i1 = j1;
}
2011-02-01 23:49:28 +01:00
2012-03-01 11:49:23 +01:00
return i1;
}
2011-02-01 23:49:28 +01:00
}
public void a(Entity entity) {
2013-11-04 14:07:38 +01:00
this.o = true;
int i = MathHelper.floor(entity.locX / 16.0D);
int j = MathHelper.floor(entity.locZ / 16.0D);
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
if (i != this.locX || j != this.locZ) {
// CraftBukkit start
Bukkit.getLogger().warning("Wrong location for " + entity + " in world '" + world.getWorld().getName() + "'!");
2013-11-04 14:07:38 +01:00
// t.error("Wrong location! " + entity);
// Thread.dumpStack();
2013-11-04 14:07:38 +01:00
Bukkit.getLogger().warning("Entity is at " + entity.locX + "," + entity.locZ + " (chunk " + i + "," + j + ") but was stored in chunk " + this.locX + "," + this.locZ);
// CraftBukkit end
2011-02-01 23:49:28 +01:00
}
int k = MathHelper.floor(entity.locY / 16.0D);
2011-02-01 23:49:28 +01:00
if (k < 0) {
k = 0;
}
if (k >= this.entitySlices.length) {
k = this.entitySlices.length - 1;
2011-02-01 23:49:28 +01:00
}
2013-11-04 14:07:38 +01:00
entity.ah = true;
entity.ai = this.locX;
entity.aj = k;
entity.ak = this.locZ;
this.entitySlices[k].add(entity);
2011-02-01 23:49:28 +01:00
}
public void b(Entity entity) {
2013-11-04 14:07:38 +01:00
this.a(entity, entity.aj);
2011-02-01 23:49:28 +01:00
}
public void a(Entity entity, int i) {
if (i < 0) {
i = 0;
}
if (i >= this.entitySlices.length) {
i = this.entitySlices.length - 1;
2011-02-01 23:49:28 +01:00
}
this.entitySlices[i].remove(entity);
2011-02-01 23:49:28 +01:00
}
2012-03-01 11:49:23 +01:00
public boolean d(int i, int j, int k) {
return j >= this.heightMap[k << 4 | i];
2011-02-01 23:49:28 +01:00
}
2012-03-01 11:49:23 +01:00
public TileEntity e(int i, int j, int k) {
2011-02-01 23:49:28 +01:00
ChunkPosition chunkposition = new ChunkPosition(i, j, k);
TileEntity tileentity = (TileEntity) this.tileEntities.get(chunkposition);
2011-02-01 23:49:28 +01:00
if (tileentity == null) {
2013-11-04 14:07:38 +01:00
Block block = this.getType(i, j, k);
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
if (!block.isTileEntity()) {
2011-02-01 23:49:28 +01:00
return null;
}
2013-11-04 14:07:38 +01:00
tileentity = ((IContainer) block).a(this.world, this.getData(i, j, k));
this.world.setTileEntity(this.locX * 16 + i, j, this.locZ * 16 + k, tileentity);
2011-02-01 23:49:28 +01:00
}
if (tileentity != null && tileentity.r()) {
2011-06-30 00:02:25 +02:00
this.tileEntities.remove(chunkposition);
return null;
} else {
return tileentity;
}
2011-02-01 23:49:28 +01:00
}
public void a(TileEntity tileentity) {
2013-11-04 14:07:38 +01:00
int i = tileentity.x - this.locX * 16;
int j = tileentity.y;
2013-11-04 14:07:38 +01:00
int k = tileentity.z - this.locZ * 16;
2011-02-01 23:49:28 +01:00
this.a(i, j, k, tileentity);
2012-03-01 11:49:23 +01:00
if (this.d) {
this.world.tileEntityList.add(tileentity);
2011-06-30 00:02:25 +02:00
}
2011-02-01 23:49:28 +01:00
}
public void a(int i, int j, int k, TileEntity tileentity) {
ChunkPosition chunkposition = new ChunkPosition(i, j, k);
2013-11-04 14:07:38 +01:00
tileentity.a(this.world);
tileentity.x = this.locX * 16 + i;
tileentity.y = j;
2013-11-04 14:07:38 +01:00
tileentity.z = this.locZ * 16 + k;
if (this.getType(i, j, k) instanceof IContainer) {
2013-03-13 23:33:27 +01:00
if (this.tileEntities.containsKey(chunkposition)) {
2013-11-04 14:07:38 +01:00
((TileEntity) this.tileEntities.get(chunkposition)).s();
2013-03-13 23:33:27 +01:00
}
2013-11-04 14:07:38 +01:00
tileentity.t();
this.tileEntities.put(chunkposition, tileentity);
// CraftBukkit start
2011-02-01 23:49:28 +01:00
} else {
System.out.println("Attempted to place a tile entity (" + tileentity + ") at " + tileentity.x + "," + tileentity.y + "," + tileentity.z
2013-11-04 14:07:38 +01:00
+ " (" + org.bukkit.Material.getMaterial(Block.b(getType(i, j, k))) + ") where there was no entity tile!");
System.out.println("Chunk coordinates: " + (this.locX * 16) + "," + (this.locZ * 16));
new Exception().printStackTrace();
// CraftBukkit end
2011-02-01 23:49:28 +01:00
}
}
2012-03-01 11:49:23 +01:00
public void f(int i, int j, int k) {
2011-02-01 23:49:28 +01:00
ChunkPosition chunkposition = new ChunkPosition(i, j, k);
2012-03-01 11:49:23 +01:00
if (this.d) {
2011-06-30 00:02:25 +02:00
TileEntity tileentity = (TileEntity) this.tileEntities.remove(chunkposition);
if (tileentity != null) {
2013-11-04 14:07:38 +01:00
tileentity.s();
2011-06-30 00:02:25 +02:00
}
2011-02-01 23:49:28 +01:00
}
}
public void addEntities() {
2012-03-01 11:49:23 +01:00
this.d = true;
2011-06-30 00:02:25 +02:00
this.world.a(this.tileEntities.values());
2011-02-01 23:49:28 +01:00
2012-11-06 13:05:28 +01:00
for (int i = 0; i < this.entitySlices.length; ++i) {
2013-07-01 13:03:00 +02:00
Iterator iterator = this.entitySlices[i].iterator();
while (iterator.hasNext()) {
Entity entity = (Entity) iterator.next();
2013-11-04 14:07:38 +01:00
entity.X();
2013-07-01 13:03:00 +02:00
}
2012-11-06 13:05:28 +01:00
this.world.a(this.entitySlices[i]);
2011-02-01 23:49:28 +01:00
}
}
public void removeEntities() {
2012-03-01 11:49:23 +01:00
this.d = false;
2011-06-30 00:02:25 +02:00
Iterator iterator = this.tileEntities.values().iterator();
while (iterator.hasNext()) {
TileEntity tileentity = (TileEntity) iterator.next();
2011-09-15 02:23:52 +02:00
this.world.a(tileentity);
2011-06-30 00:02:25 +02:00
}
2012-11-06 13:05:28 +01:00
for (int i = 0; i < this.entitySlices.length; ++i) {
2011-05-14 16:29:42 +02:00
// CraftBukkit start
2012-11-06 13:05:28 +01:00
java.util.Iterator<Object> iter = this.entitySlices[i].iterator();
while (iter.hasNext()) {
Entity entity = (Entity) iter.next();
2011-05-14 16:29:42 +02:00
// Do not pass along players, as doing so can get them stuck outside of time.
// (which for example disables inventory icon updates and prevents block breaking)
if (entity instanceof EntityPlayer) {
2011-05-14 16:29:42 +02:00
iter.remove();
}
}
2011-05-14 16:29:42 +02:00
// CraftBukkit end
2012-11-06 13:05:28 +01:00
this.world.b(this.entitySlices[i]);
2011-02-01 23:49:28 +01:00
}
}
2012-03-01 11:49:23 +01:00
public void e() {
2013-11-04 14:07:38 +01:00
this.n = true;
2011-02-01 23:49:28 +01:00
}
2013-03-13 23:33:27 +01:00
public void a(Entity entity, AxisAlignedBB axisalignedbb, List list, IEntitySelector ientityselector) {
int i = MathHelper.floor((axisalignedbb.b - 2.0D) / 16.0D);
int j = MathHelper.floor((axisalignedbb.e + 2.0D) / 16.0D);
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
i = MathHelper.a(i, 0, this.entitySlices.length - 1);
j = MathHelper.a(j, 0, this.entitySlices.length - 1);
2011-02-01 23:49:28 +01:00
for (int k = i; k <= j; ++k) {
2012-07-29 09:33:13 +02:00
List list1 = this.entitySlices[k];
2011-02-01 23:49:28 +01:00
2012-11-06 13:05:28 +01:00
for (int l = 0; l < list1.size(); ++l) {
Entity entity1 = (Entity) list1.get(l);
2011-02-01 23:49:28 +01:00
2013-07-01 13:03:00 +02:00
if (entity1 != entity && entity1.boundingBox.b(axisalignedbb) && (ientityselector == null || ientityselector.a(entity1))) {
2011-02-01 23:49:28 +01:00
list.add(entity1);
2013-11-04 14:07:38 +01:00
Entity[] aentity = entity1.at();
2011-11-20 09:01:14 +01:00
if (aentity != null) {
2012-11-06 13:05:28 +01:00
for (int i1 = 0; i1 < aentity.length; ++i1) {
entity1 = aentity[i1];
2013-07-01 13:03:00 +02:00
if (entity1 != entity && entity1.boundingBox.b(axisalignedbb) && (ientityselector == null || ientityselector.a(entity1))) {
2011-11-20 09:01:14 +01:00
list.add(entity1);
}
}
}
2011-02-01 23:49:28 +01:00
}
}
}
}
public void a(Class oclass, AxisAlignedBB axisalignedbb, List list, IEntitySelector ientityselector) {
int i = MathHelper.floor((axisalignedbb.b - 2.0D) / 16.0D);
int j = MathHelper.floor((axisalignedbb.e + 2.0D) / 16.0D);
2011-02-01 23:49:28 +01:00
2013-11-04 14:07:38 +01:00
i = MathHelper.a(i, 0, this.entitySlices.length - 1);
j = MathHelper.a(j, 0, this.entitySlices.length - 1);
2011-02-01 23:49:28 +01:00
for (int k = i; k <= j; ++k) {
2012-07-29 09:33:13 +02:00
List list1 = this.entitySlices[k];
2011-02-01 23:49:28 +01:00
2012-11-06 13:05:28 +01:00
for (int l = 0; l < list1.size(); ++l) {
Entity entity = (Entity) list1.get(l);
2011-02-01 23:49:28 +01:00
2013-07-01 13:03:00 +02:00
if (oclass.isAssignableFrom(entity.getClass()) && entity.boundingBox.b(axisalignedbb) && (ientityselector == null || ientityselector.a(entity))) {
2011-02-01 23:49:28 +01:00
list.add(entity);
}
}
}
}
public boolean a(boolean flag) {
2012-03-01 11:49:23 +01:00
if (flag) {
2013-11-04 14:07:38 +01:00
if (this.o && this.world.getTime() != this.p || this.n) {
2011-02-01 23:49:28 +01:00
return true;
}
2013-11-04 14:07:38 +01:00
} else if (this.o && this.world.getTime() >= this.p + 600L) {
2012-03-01 11:49:23 +01:00
return true;
2011-02-01 23:49:28 +01:00
}
2013-11-04 14:07:38 +01:00
return this.n;
2011-02-01 23:49:28 +01:00
}
public Random a(long i) {
2013-11-04 14:07:38 +01:00
return new Random(this.world.getSeed() + (long) (this.locX * this.locX * 4987142) + (long) (this.locX * 5947611) + (long) (this.locZ * this.locZ) * 4392871L + (long) (this.locZ * 389711) ^ i);
2011-02-01 23:49:28 +01:00
}
2011-11-20 09:01:14 +01:00
public boolean isEmpty() {
return false;
}
2011-09-15 02:23:52 +02:00
public void a(IChunkProvider ichunkprovider, IChunkProvider ichunkprovider1, int i, int j) {
if (!this.done && ichunkprovider.isChunkLoaded(i + 1, j + 1) && ichunkprovider.isChunkLoaded(i, j + 1) && ichunkprovider.isChunkLoaded(i + 1, j)) {
ichunkprovider.getChunkAt(ichunkprovider1, i, j);
}
if (ichunkprovider.isChunkLoaded(i - 1, j) && !ichunkprovider.getOrCreateChunk(i - 1, j).done && ichunkprovider.isChunkLoaded(i - 1, j + 1) && ichunkprovider.isChunkLoaded(i, j + 1) && ichunkprovider.isChunkLoaded(i - 1, j + 1)) {
ichunkprovider.getChunkAt(ichunkprovider1, i - 1, j);
}
if (ichunkprovider.isChunkLoaded(i, j - 1) && !ichunkprovider.getOrCreateChunk(i, j - 1).done && ichunkprovider.isChunkLoaded(i + 1, j - 1) && ichunkprovider.isChunkLoaded(i + 1, j - 1) && ichunkprovider.isChunkLoaded(i + 1, j)) {
ichunkprovider.getChunkAt(ichunkprovider1, i, j - 1);
}
if (ichunkprovider.isChunkLoaded(i - 1, j - 1) && !ichunkprovider.getOrCreateChunk(i - 1, j - 1).done && ichunkprovider.isChunkLoaded(i, j - 1) && ichunkprovider.isChunkLoaded(i - 1, j)) {
ichunkprovider.getChunkAt(ichunkprovider1, i - 1, j - 1);
}
}
2012-03-01 11:49:23 +01:00
public int d(int i, int j) {
2011-09-15 02:23:52 +02:00
int k = i | j << 4;
2012-03-01 11:49:23 +01:00
int l = this.b[k];
2011-09-15 02:23:52 +02:00
if (l == -999) {
2012-07-29 09:33:13 +02:00
int i1 = this.h() + 15;
2011-09-15 02:23:52 +02:00
l = -1;
while (i1 > 0 && l == -1) {
2013-11-04 14:07:38 +01:00
Block block = this.getType(i, i1, j);
Material material = block.getMaterial();
2011-09-15 02:23:52 +02:00
if (!material.isSolid() && !material.isLiquid()) {
--i1;
} else {
l = i1 + 1;
}
}
2012-03-01 11:49:23 +01:00
this.b[k] = l;
2011-09-15 02:23:52 +02:00
}
return l;
2011-02-01 23:49:28 +01:00
}
2011-03-31 22:40:00 +02:00
2013-11-04 14:07:38 +01:00
public void b(boolean flag) {
if (this.w && !this.world.worldProvider.g && !flag) {
this.c(this.world.isStatic);
}
this.m = true;
if (!this.lit && this.done) {
this.p();
2011-11-20 09:01:14 +01:00
}
}
2013-11-04 14:07:38 +01:00
public boolean k() {
return this.m && this.done && this.lit;
}
2012-07-29 09:33:13 +02:00
public ChunkCoordIntPair l() {
2013-11-04 14:07:38 +01:00
return new ChunkCoordIntPair(this.locX, this.locZ);
2011-03-31 22:40:00 +02:00
}
2012-03-01 11:49:23 +01:00
public boolean c(int i, int j) {
if (i < 0) {
i = 0;
}
if (j >= 256) {
j = 255;
}
for (int k = i; k <= j; k += 16) {
ChunkSection chunksection = this.sections[k >> 4];
2013-04-27 11:40:05 +02:00
if (chunksection != null && !chunksection.isEmpty()) {
2012-03-01 11:49:23 +01:00
return false;
}
}
return true;
}
public void a(ChunkSection[] achunksection) {
this.sections = achunksection;
}
public BiomeBase a(int i, int j, WorldChunkManager worldchunkmanager) {
2013-11-04 14:07:38 +01:00
int k = this.v[j << 4 | i] & 255;
2012-03-01 11:49:23 +01:00
if (k == 255) {
2013-11-04 14:07:38 +01:00
BiomeBase biomebase = worldchunkmanager.getBiome((this.locX << 4) + i, (this.locZ << 4) + j);
2012-03-01 11:49:23 +01:00
k = biomebase.id;
2013-11-04 14:07:38 +01:00
this.v[j << 4 | i] = (byte) (k & 255);
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
return BiomeBase.getBiome(k) == null ? BiomeBase.PLAINS : BiomeBase.getBiome(k);
2012-03-01 11:49:23 +01:00
}
2012-07-29 09:33:13 +02:00
public byte[] m() {
2013-11-04 14:07:38 +01:00
return this.v;
2012-03-01 11:49:23 +01:00
}
public void a(byte[] abyte) {
2013-11-04 14:07:38 +01:00
this.v = abyte;
2012-03-01 11:49:23 +01:00
}
2012-07-29 09:33:13 +02:00
public void n() {
2013-11-04 14:07:38 +01:00
this.x = 0;
2012-03-01 11:49:23 +01:00
}
2012-07-29 09:33:13 +02:00
public void o() {
2012-03-01 11:49:23 +01:00
for (int i = 0; i < 8; ++i) {
2013-11-04 14:07:38 +01:00
if (this.x >= 4096) {
2012-03-01 11:49:23 +01:00
return;
}
2013-11-04 14:07:38 +01:00
int j = this.x % 16;
int k = this.x / 16 % 16;
int l = this.x / 256;
2012-03-01 11:49:23 +01:00
2013-11-04 14:07:38 +01:00
++this.x;
int i1 = (this.locX << 4) + k;
int j1 = (this.locZ << 4) + l;
2012-03-01 11:49:23 +01:00
for (int k1 = 0; k1 < 16; ++k1) {
int l1 = (j << 4) + k1;
2013-11-04 14:07:38 +01:00
if (this.sections[j] == null && (k1 == 0 || k1 == 15 || k == 0 || k == 15 || l == 0 || l == 15) || this.sections[j] != null && this.sections[j].getTypeId(k, k1, l).getMaterial() == Material.AIR) {
if (this.world.getType(i1, l1 - 1, j1).m() > 0) {
this.world.t(i1, l1 - 1, j1);
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.world.getType(i1, l1 + 1, j1).m() > 0) {
this.world.t(i1, l1 + 1, j1);
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.world.getType(i1 - 1, l1, j1).m() > 0) {
this.world.t(i1 - 1, l1, j1);
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.world.getType(i1 + 1, l1, j1).m() > 0) {
this.world.t(i1 + 1, l1, j1);
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.world.getType(i1, l1, j1 - 1).m() > 0) {
this.world.t(i1, l1, j1 - 1);
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
if (this.world.getType(i1, l1, j1 + 1).m() > 0) {
this.world.t(i1, l1, j1 + 1);
2012-03-01 11:49:23 +01:00
}
2013-11-04 14:07:38 +01:00
this.world.t(i1, l1, j1);
2012-03-01 11:49:23 +01:00
}
}
}
}
2013-11-04 14:07:38 +01:00
public void p() {
this.done = true;
this.lit = true;
if (!this.world.worldProvider.g) {
if (this.world.b(this.locX * 16 - 1, 0, this.locZ * 16 - 1, this.locX * 16 + 1, 63, this.locZ * 16 + 1)) {
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
if (!this.f(i, j)) {
this.lit = false;
break;
}
}
}
if (this.lit) {
Chunk chunk = this.world.getChunkAtWorldCoords(this.locX * 16 - 1, this.locZ * 16);
chunk.a(3);
chunk = this.world.getChunkAtWorldCoords(this.locX * 16 + 16, this.locZ * 16);
chunk.a(1);
chunk = this.world.getChunkAtWorldCoords(this.locX * 16, this.locZ * 16 - 1);
chunk.a(0);
chunk = this.world.getChunkAtWorldCoords(this.locX * 16, this.locZ * 16 + 16);
chunk.a(2);
}
} else {
this.lit = false;
}
}
}
private void a(int i) {
if (this.done) {
int j;
if (i == 3) {
for (j = 0; j < 16; ++j) {
this.f(15, j);
}
} else if (i == 1) {
for (j = 0; j < 16; ++j) {
this.f(0, j);
}
} else if (i == 0) {
for (j = 0; j < 16; ++j) {
this.f(j, 15);
}
} else if (i == 2) {
for (j = 0; j < 16; ++j) {
this.f(j, 0);
}
}
}
}
private boolean f(int i, int j) {
int k = this.h();
boolean flag = false;
boolean flag1 = false;
int l;
for (l = k + 16 - 1; l > 63 || l > 0 && !flag1; --l) {
int i1 = this.b(i, l, j);
if (i1 == 255 && l < 63) {
flag1 = true;
}
if (!flag && i1 > 0) {
flag = true;
} else if (flag && i1 == 0 && !this.world.t(this.locX * 16 + i, l, this.locZ * 16 + j)) {
return false;
}
}
for (; l > 0; --l) {
if (this.getType(i, l, j).m() > 0) {
this.world.t(this.locX * 16 + i, l, this.locZ * 16 + j);
}
}
return true;
}
2011-02-01 23:49:28 +01:00
}