3
0
Mirror von https://github.com/PaperMC/Paper.git synchronisiert 2024-12-22 06:20:06 +01:00
Paper/src/main/java/net/minecraft/server/Chunk.java

866 Zeilen
26 KiB
Java

2011-02-01 23:49:28 +01:00
package net.minecraft.server;
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;
2011-11-20 09:01:14 +01:00
import org.bukkit.Bukkit; // CraftBukkit
2011-02-01 23:49:28 +01:00
public class Chunk {
public static boolean a;
2012-02-29 22:31:04 +01:00
public byte[] blocks;
2011-09-15 02:23:52 +02:00
public int[] c;
public boolean[] d;
public boolean e;
public World world;
2011-02-01 23:49:28 +01:00
public NibbleArray g;
2011-09-15 02:23:52 +02:00
public NibbleArray h;
public NibbleArray i;
public byte[] heightMap;
2011-09-15 02:23:52 +02:00
public int k;
public final int x;
public final int z;
2011-11-20 09:01:14 +01:00
private boolean v;
public Map tileEntities;
public List[] entitySlices;
public boolean done;
2011-02-01 23:49:28 +01:00
public boolean q;
2011-09-15 02:23:52 +02:00
public boolean r;
public boolean s;
public long t;
boolean u;
2011-02-01 23:49:28 +01:00
public Chunk(World world, int i, int j) {
2011-09-15 02:23:52 +02:00
this.c = new int[256];
this.d = new boolean[256];
2011-11-20 09:01:14 +01:00
this.v = false;
this.tileEntities = new HashMap();
this.done = false;
2011-02-01 23:49:28 +01:00
this.q = false;
2011-09-15 02:23:52 +02:00
this.s = false;
this.t = 0L;
this.u = false;
2011-11-20 09:01:14 +01:00
this.entitySlices = new List[world.height / 16];
this.world = world;
this.x = i;
this.z = j;
this.heightMap = new byte[256];
2011-02-01 23:49:28 +01:00
for (int k = 0; k < this.entitySlices.length; ++k) {
this.entitySlices[k] = new ArrayList();
2011-02-01 23:49:28 +01:00
}
2011-09-15 02:23:52 +02:00
Arrays.fill(this.c, -999);
2011-02-01 23:49:28 +01:00
// CraftBukkit start
if (!(this instanceof EmptyChunk)) {
org.bukkit.craftbukkit.CraftWorld cworld = this.world.getWorld();
this.bukkitChunk = (cworld == null) ? null : cworld.popPreservedChunk(i, j);
if (this.bukkitChunk == null) {
this.bukkitChunk = new org.bukkit.craftbukkit.CraftChunk(this);
}
}
2011-02-01 23:49:28 +01:00
}
public org.bukkit.Chunk bukkitChunk;
// CraftBukkit end
public Chunk(World world, byte[] abyte, int i, int j) {
this(world, i, j);
2012-02-29 22:31:04 +01:00
this.blocks = abyte;
2011-11-20 09:01:14 +01:00
this.g = new NibbleArray(abyte.length, world.heightBits);
this.h = new NibbleArray(abyte.length, world.heightBits);
this.i = new NibbleArray(abyte.length, world.heightBits);
2011-02-01 23:49:28 +01:00
}
public boolean a(int i, int j) {
return i == this.x && j == this.z;
2011-02-01 23:49:28 +01:00
}
public int b(int i, int j) {
return this.heightMap[j << 4 | i] & 255;
2011-02-01 23:49:28 +01:00
}
public void a() {}
public void initLighting() {
2011-11-20 09:01:14 +01:00
int i = this.world.height - 1;
2011-02-01 23:49:28 +01:00
int j;
int k;
for (j = 0; j < 16; ++j) {
for (k = 0; k < 16; ++k) {
2011-11-20 09:01:14 +01:00
int l = this.world.height - 1;
2011-09-15 05:13:14 +02:00
2011-11-20 09:01:14 +01:00
int i1;
2011-02-01 23:49:28 +01:00
2012-02-29 22:31:04 +01:00
for (i1 = j << this.world.heightBitsPlusFour | k << this.world.heightBits; l > 0 && Block.lightBlock[this.blocks[i1 + l - 1] & 255] == 0; --l) {
2011-02-01 23:49:28 +01:00
;
}
this.heightMap[k << 4 | j] = (byte) l;
2011-02-01 23:49:28 +01:00
if (l < i) {
i = l;
}
2012-01-12 23:10:13 +01:00
if (!this.world.worldProvider.f) {
2011-11-20 09:01:14 +01:00
int j1 = 15;
int k1 = this.world.height - 1;
2011-02-01 23:49:28 +01:00
do {
2012-02-29 22:31:04 +01:00
j1 -= Block.lightBlock[this.blocks[i1 + k1] & 255];
2011-11-20 09:01:14 +01:00
if (j1 > 0) {
this.h.a(j, k1, k, j1);
2011-02-01 23:49:28 +01:00
}
2011-11-20 09:01:14 +01:00
--k1;
} while (k1 > 0 && j1 > 0);
2011-02-01 23:49:28 +01:00
}
}
}
2011-09-15 02:23:52 +02:00
this.k = i;
2011-02-01 23:49:28 +01:00
for (j = 0; j < 16; ++j) {
for (k = 0; k < 16; ++k) {
2011-09-15 02:23:52 +02:00
this.d(j, k);
2011-02-01 23:49:28 +01:00
}
}
2011-09-15 02:23:52 +02:00
this.q = true;
2011-02-01 23:49:28 +01:00
}
public void loadNOP() {}
2011-02-01 23:49:28 +01:00
2011-09-15 02:23:52 +02:00
private void d(int i, int j) {
this.d[i + j * 16] = true;
2011-11-20 09:01:14 +01:00
this.v = true;
}
private void k() {
if (this.world.areChunksLoaded(this.x * 16 + 8, this.world.height / 2, this.z * 16 + 8, 16)) {
for (int i = 0; i < 16; ++i) {
for (int j = 0; j < 16; ++j) {
if (this.d[i + j * 16]) {
this.d[i + j * 16] = false;
int k = this.b(i, j);
int l = this.x * 16 + i;
int i1 = this.z * 16 + j;
int j1 = this.world.getHighestBlockYAt(l - 1, i1);
int k1 = this.world.getHighestBlockYAt(l + 1, i1);
int l1 = this.world.getHighestBlockYAt(l, i1 - 1);
int i2 = this.world.getHighestBlockYAt(l, i1 + 1);
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
2011-11-20 09:01:14 +01:00
this.f(l, i1, j1);
this.f(l - 1, i1, k);
this.f(l + 1, i1, k);
this.f(l, i1 - 1, k);
this.f(l, i1 + 1, k);
this.v = false;
2011-09-15 02:23:52 +02:00
}
}
}
}
2011-02-01 23:49:28 +01:00
}
private void f(int i, int j, int k) {
int l = this.world.getHighestBlockYAt(i, j);
2011-02-01 23:49:28 +01:00
if (l > k) {
2011-09-15 02:23:52 +02:00
this.d(i, j, k, l + 1);
2011-02-01 23:49:28 +01:00
} else if (l < k) {
2011-09-15 02:23:52 +02:00
this.d(i, j, l, k + 1);
}
}
private void d(int i, int j, int k, int l) {
2011-11-20 09:01:14 +01:00
if (l > k && this.world.areChunksLoaded(i, this.world.height / 2, j, 16)) {
for (int i1 = k; i1 < l; ++i1) {
this.world.b(EnumSkyBlock.SKY, i, i1, j);
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +01:00
this.q = true;
2011-02-01 23:49:28 +01:00
}
}
private void g(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-02-29 22:31:04 +01:00
for (int j1 = i << this.world.heightBitsPlusFour | k << this.world.heightBits; i1 > 0 && Block.lightBlock[this.blocks[j1 + i1 - 1] & 255] == 0; --i1) {
2011-02-01 23:49:28 +01:00
;
}
if (i1 != l) {
this.world.g(i, k, i1, l);
this.heightMap[k << 4 | i] = (byte) i1;
2011-11-20 09:01:14 +01:00
int k1;
2011-02-01 23:49:28 +01:00
int l1;
int i2;
2011-09-15 02:23:52 +02:00
if (i1 < this.k) {
this.k = i1;
2011-02-01 23:49:28 +01:00
} else {
2011-11-20 09:01:14 +01:00
k1 = this.world.height - 1;
2011-09-15 05:13:14 +02:00
2011-11-20 09:01:14 +01:00
for (l1 = 0; l1 < 16; ++l1) {
for (i2 = 0; i2 < 16; ++i2) {
if ((this.heightMap[i2 << 4 | l1] & 255) < k1) {
k1 = this.heightMap[i2 << 4 | l1] & 255;
2011-02-01 23:49:28 +01:00
}
}
}
2011-11-20 09:01:14 +01:00
this.k = k1;
2011-02-01 23:49:28 +01:00
}
2011-11-20 09:01:14 +01:00
k1 = this.x * 16 + i;
l1 = this.z * 16 + k;
int j2;
2011-02-01 23:49:28 +01:00
2012-01-12 23:10:13 +01:00
if (!this.world.worldProvider.f) {
2011-11-20 09:01:14 +01:00
if (i1 < l) {
for (i2 = i1; i2 < l; ++i2) {
this.h.a(i, i2, k, 15);
}
} else {
for (i2 = l; i2 < i1; ++i2) {
this.h.a(i, i2, k, 0);
}
2011-02-01 23:49:28 +01:00
}
2011-11-20 09:01:14 +01:00
for (i2 = 15; i1 > 0 && i2 > 0; this.h.a(i, i1, k, i2)) {
--i1;
j2 = Block.lightBlock[this.getTypeId(i, i1, k)];
2011-11-20 09:01:14 +01:00
if (j2 == 0) {
j2 = 1;
}
i2 -= j2;
if (i2 < 0) {
i2 = 0;
}
2011-02-01 23:49:28 +01:00
}
}
2011-09-15 02:23:52 +02:00
byte b0 = this.heightMap[k << 4 | i];
2011-11-20 09:01:14 +01:00
j2 = l;
int k2 = b0;
2011-02-01 23:49:28 +01:00
2011-09-15 02:23:52 +02:00
if (b0 < l) {
2011-11-20 09:01:14 +01:00
j2 = b0;
k2 = l;
}
2012-01-12 23:10:13 +01:00
if (!this.world.worldProvider.f) {
2011-11-20 09:01:14 +01:00
this.d(k1 - 1, l1, j2, k2);
this.d(k1 + 1, l1, j2, k2);
this.d(k1, l1 - 1, j2, k2);
this.d(k1, l1 + 1, j2, k2);
this.d(k1, l1, j2, k2);
2011-02-01 23:49:28 +01:00
}
2011-09-15 02:23:52 +02:00
this.q = true;
2011-02-01 23:49:28 +01:00
}
}
public int getTypeId(int i, int j, int k) {
2012-02-29 22:31:04 +01:00
return this.blocks[i << this.world.heightBitsPlusFour | k << this.world.heightBits | j] & 255;
2011-02-01 23:49:28 +01:00
}
public boolean a(int i, int j, int k, int l, int i1) {
byte b0 = (byte) l;
2011-09-15 02:23:52 +02:00
int j1 = k << 4 | i;
if (j >= this.c[j1] - 1) {
this.c[j1] = -999;
}
int k1 = this.heightMap[k << 4 | i] & 255;
2012-02-29 22:31:04 +01:00
int l1 = this.blocks[i << this.world.heightBitsPlusFour | k << this.world.heightBits | j] & 255;
2011-02-01 23:49:28 +01:00
2011-11-20 09:01:14 +01:00
if (l1 == l && this.g.a(i, j, k) == i1) {
2011-02-01 23:49:28 +01:00
return false;
} else {
2011-11-20 09:01:14 +01:00
int i2 = this.x * 16 + i;
int j2 = this.z * 16 + k;
2011-09-15 05:13:14 +02:00
2012-02-29 22:31:04 +01:00
this.blocks[i << this.world.heightBitsPlusFour | k << this.world.heightBits | j] = (byte) (b0 & 255);
2011-11-20 09:01:14 +01:00
if (l1 != 0) {
if (!this.world.isStatic) {
Block.byId[l1].remove(this.world, i2, j, j2);
} else if (Block.byId[l1] instanceof BlockContainer && l1 != l) {
this.world.n(i2, j, j2);
2011-11-20 09:01:14 +01:00
}
2011-02-01 23:49:28 +01:00
}
2012-02-29 22:31:04 +01:00
if ((this.blocks[i << this.world.heightBitsPlusFour | k << this.world.heightBits | j] & 255) != l) return false; // CraftBukkit
2011-09-15 02:23:52 +02:00
this.g.a(i, j, k, i1);
2012-01-12 23:10:13 +01:00
if (!this.world.worldProvider.f) {
if (Block.lightBlock[b0 & 255] != 0) {
2011-09-15 02:23:52 +02:00
if (j >= k1) {
2011-02-01 23:49:28 +01:00
this.g(i, j + 1, k);
}
2011-09-15 02:23:52 +02:00
} else if (j == k1 - 1) {
2011-02-01 23:49:28 +01:00
this.g(i, j, k);
}
2011-11-20 09:01:14 +01:00
this.world.a(EnumSkyBlock.SKY, i2, j, j2, i2, j, j2);
2011-02-01 23:49:28 +01:00
}
2011-11-20 09:01:14 +01:00
this.world.a(EnumSkyBlock.BLOCK, i2, j, j2, i2, j, j2);
2011-09-15 02:23:52 +02:00
this.d(i, k);
this.g.a(i, j, k, i1);
TileEntity tileentity;
2011-02-01 23:49:28 +01:00
if (l != 0) {
2011-09-15 02:23:52 +02:00
if (!this.world.isStatic) {
Block.byId[l].onPlace(this.world, i2, j, j2);
2011-09-15 02:23:52 +02:00
}
if (Block.byId[l] instanceof BlockContainer) {
tileentity = this.d(i, j, k);
if (tileentity == null) {
tileentity = ((BlockContainer) Block.byId[l]).a_();
2012-01-12 23:10:13 +01:00
this.world.setTileEntity(i2, j, j2, tileentity);
2011-09-15 02:23:52 +02:00
}
if (tileentity != null) {
2011-11-20 09:01:14 +01:00
tileentity.d();
2011-09-15 02:23:52 +02:00
}
}
2011-11-20 09:01:14 +01:00
} else if (l1 > 0 && Block.byId[l1] instanceof BlockContainer) {
2011-09-15 02:23:52 +02:00
tileentity = this.d(i, j, k);
if (tileentity != null) {
2011-11-20 09:01:14 +01:00
tileentity.d();
2011-09-15 02:23:52 +02:00
}
2011-02-01 23:49:28 +01:00
}
2011-09-15 02:23:52 +02:00
this.q = true;
2011-02-01 23:49:28 +01:00
return true;
}
}
public boolean a(int i, int j, int k, int l) {
byte b0 = (byte) l;
2011-09-15 02:23:52 +02:00
int i1 = k << 4 | i;
if (j >= this.c[i1] - 1) {
this.c[i1] = -999;
}
int j1 = this.heightMap[i1] & 255;
2012-02-29 22:31:04 +01:00
int k1 = this.blocks[i << this.world.heightBitsPlusFour | k << this.world.heightBits | j] & 255;
2011-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
if (k1 == l) {
2011-02-01 23:49:28 +01:00
return false;
} else {
2011-11-20 09:01:14 +01:00
int l1 = this.x * 16 + i;
int i2 = this.z * 16 + k;
2011-09-15 05:13:14 +02:00
2012-02-29 22:31:04 +01:00
this.blocks[i << this.world.heightBitsPlusFour | k << this.world.heightBits | j] = (byte) (b0 & 255);
2011-11-20 09:01:14 +01:00
if (k1 != 0) {
Block.byId[k1].remove(this.world, l1, j, i2);
2011-02-01 23:49:28 +01:00
}
2012-02-29 22:31:04 +01:00
if ((this.blocks[i << this.world.heightBitsPlusFour | k << this.world.heightBits | j] & 255) != l) return false; // CraftBukkit
2011-09-15 02:23:52 +02:00
this.g.a(i, j, k, 0);
if (Block.lightBlock[b0 & 255] != 0) {
2011-09-15 02:23:52 +02:00
if (j >= j1) {
2011-02-01 23:49:28 +01:00
this.g(i, j + 1, k);
}
2011-09-15 02:23:52 +02:00
} else if (j == j1 - 1) {
2011-02-01 23:49:28 +01:00
this.g(i, j, k);
}
2011-11-20 09:01:14 +01:00
this.world.a(EnumSkyBlock.SKY, l1, j, i2, l1, j, i2);
this.world.a(EnumSkyBlock.BLOCK, l1, j, i2, l1, j, i2);
2011-09-15 02:23:52 +02:00
this.d(i, k);
TileEntity tileentity;
if (l != 0) {
if (!this.world.isStatic) {
Block.byId[l].onPlace(this.world, l1, j, i2);
2011-09-15 02:23:52 +02:00
}
if (l > 0 && Block.byId[l] instanceof BlockContainer) {
tileentity = this.d(i, j, k);
if (tileentity == null) {
tileentity = ((BlockContainer) Block.byId[l]).a_();
2012-01-12 23:10:13 +01:00
this.world.setTileEntity(l1, j, i2, tileentity);
2011-09-15 02:23:52 +02:00
}
if (tileentity != null) {
2011-11-20 09:01:14 +01:00
tileentity.d();
2011-09-15 02:23:52 +02:00
}
}
2011-11-20 09:01:14 +01:00
} else if (k1 > 0 && Block.byId[k1] instanceof BlockContainer) {
2011-09-15 02:23:52 +02:00
tileentity = this.d(i, j, k);
if (tileentity != null) {
2011-11-20 09:01:14 +01:00
tileentity.d();
2011-09-15 02:23:52 +02:00
}
2011-02-01 23:49:28 +01:00
}
2011-09-15 02:23:52 +02:00
this.q = true;
2011-02-01 23:49:28 +01:00
return true;
}
}
public int getData(int i, int j, int k) {
2011-09-15 02:23:52 +02:00
return this.g.a(i, j, k);
2011-02-01 23:49:28 +01:00
}
2011-11-20 09:01:14 +01:00
public boolean b(int i, int j, int k, int l) {
2011-09-15 02:23:52 +02:00
this.q = true;
2011-11-20 09:01:14 +01:00
int i1 = this.g.a(i, j, k);
if (i1 == l) {
return false;
} else {
this.g.a(i, j, k, l);
int j1 = this.getTypeId(i, j, k);
2011-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
if (j1 > 0 && Block.byId[j1] instanceof BlockContainer) {
TileEntity tileentity = this.d(i, j, k);
2011-09-15 02:23:52 +02:00
2011-11-20 09:01:14 +01:00
if (tileentity != null) {
tileentity.d();
tileentity.p = l;
}
2011-09-15 02:23:52 +02:00
}
2011-11-20 09:01:14 +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) {
2011-09-15 02:23:52 +02:00
return enumskyblock == EnumSkyBlock.SKY ? this.h.a(i, j, k) : (enumskyblock == EnumSkyBlock.BLOCK ? this.i.a(i, j, k) : 0);
2011-02-01 23:49:28 +01:00
}
public void a(EnumSkyBlock enumskyblock, int i, int j, int k, int l) {
2011-09-15 02:23:52 +02:00
this.q = true;
2011-02-01 23:49:28 +01:00
if (enumskyblock == EnumSkyBlock.SKY) {
2012-01-12 23:10:13 +01:00
if (!this.world.worldProvider.f) {
2011-11-20 09:01:14 +01:00
this.h.a(i, j, k, l);
}
2011-02-01 23:49:28 +01:00
} else {
if (enumskyblock != EnumSkyBlock.BLOCK) {
return;
}
2011-09-15 02:23:52 +02:00
this.i.a(i, j, k, l);
2011-02-01 23:49:28 +01:00
}
}
public int c(int i, int j, int k, int l) {
2012-01-12 23:10:13 +01:00
int i1 = this.world.worldProvider.f ? 0 : this.h.a(i, j, k);
2011-02-01 23:49:28 +01:00
if (i1 > 0) {
a = true;
}
i1 -= l;
2011-09-15 02:23:52 +02:00
int j1 = this.i.a(i, j, k);
2011-02-01 23:49:28 +01:00
if (j1 > i1) {
i1 = j1;
}
return i1;
}
public void a(Entity entity) {
2011-09-15 02:23:52 +02:00
this.s = 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
if (i != this.x || j != this.z) {
// CraftBukkit start
Bukkit.getLogger().warning("Wrong location for " + entity + " in world '" + world.getWorld().getName() + "'!");
// Thread.dumpStack();
Bukkit.getLogger().warning("Entity is at " + entity.locX + "," + entity.locZ + " (chunk " + i + "," + j + ") but was stored in chunk " + this.x + "," + this.z);
// 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
}
2012-01-12 23:10:13 +01:00
entity.bZ = true;
entity.ca = this.x;
entity.cb = k;
entity.cc = this.z;
this.entitySlices[k].add(entity);
2011-02-01 23:49:28 +01:00
}
public void b(Entity entity) {
2012-01-12 23:10:13 +01:00
this.a(entity, entity.cb);
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
}
public boolean c(int i, int j, int k) {
return j >= (this.heightMap[k << 4 | i] & 255);
2011-02-01 23:49:28 +01:00
}
public TileEntity d(int i, int j, int k) {
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) {
int l = this.getTypeId(i, j, k);
2011-02-01 23:49:28 +01:00
if (!Block.isTileEntity[l]) {
2011-02-01 23:49:28 +01:00
return null;
}
2011-09-15 02:23:52 +02:00
if (tileentity == null) {
tileentity = ((BlockContainer) Block.byId[l]).a_();
this.world.setTileEntity(this.x * 16 + i, j, this.z * 16 + k, tileentity);
}
2011-02-01 23:49:28 +01:00
tileentity = (TileEntity) this.tileEntities.get(chunkposition);
2011-02-01 23:49:28 +01:00
}
2011-11-20 09:01:14 +01:00
if (tileentity != null && tileentity.l()) {
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) {
int i = tileentity.x - this.x * 16;
int j = tileentity.y;
int k = tileentity.z - this.z * 16;
2011-02-01 23:49:28 +01:00
this.a(i, j, k, tileentity);
2011-09-15 02:23:52 +02:00
if (this.e) {
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);
tileentity.world = this.world;
tileentity.x = this.x * 16 + i;
tileentity.y = j;
tileentity.z = this.z * 16 + k;
if (this.getTypeId(i, j, k) != 0 && Block.byId[this.getTypeId(i, j, k)] instanceof BlockContainer) {
2011-11-20 09:01:14 +01:00
tileentity.m();
this.tileEntities.put(chunkposition, tileentity);
2011-11-20 09:01:14 +01:00
// 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
+ " (" + org.bukkit.Material.getMaterial(getTypeId(i, j, k)) + ") where there was no entity tile!");
System.out.println("Chunk coordinates: " + (this.x * 16) + "," + (this.z * 16));
new Exception().printStackTrace();
// CraftBukkit end
2011-02-01 23:49:28 +01:00
}
}
public void e(int i, int j, int k) {
ChunkPosition chunkposition = new ChunkPosition(i, j, k);
2011-09-15 02:23:52 +02:00
if (this.e) {
2011-06-30 00:02:25 +02:00
TileEntity tileentity = (TileEntity) this.tileEntities.remove(chunkposition);
if (tileentity != null) {
2011-09-15 02:23:52 +02:00
tileentity.i();
2011-06-30 00:02:25 +02:00
}
2011-02-01 23:49:28 +01:00
}
}
public void addEntities() {
2011-09-15 02:23:52 +02:00
this.e = true;
2011-06-30 00:02:25 +02:00
this.world.a(this.tileEntities.values());
2011-02-01 23:49:28 +01:00
for (int i = 0; i < this.entitySlices.length; ++i) {
this.world.a(this.entitySlices[i]);
2011-02-01 23:49:28 +01:00
}
}
public void removeEntities() {
2011-09-15 02:23:52 +02:00
this.e = 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
}
for (int i = 0; i < this.entitySlices.length; ++i) {
2011-05-14 16:29:42 +02:00
// CraftBukkit start
java.util.Iterator<Object> iter = this.entitySlices[i].iterator();
while (iter.hasNext()) {
Entity entity = (Entity) iter.next();
int cx = org.bukkit.Location.locToBlock(entity.locX) >> 4;
int cz = org.bukkit.Location.locToBlock(entity.locZ) >> 4;
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 && (cx != this.x || cz != this.z)) {
iter.remove();
}
}
2011-05-14 16:29:42 +02:00
// CraftBukkit end
this.world.b(this.entitySlices[i]);
2011-02-01 23:49:28 +01:00
}
}
public void f() {
2011-09-15 02:23:52 +02:00
this.q = true;
2011-02-01 23:49:28 +01:00
}
public void a(Entity entity, AxisAlignedBB axisalignedbb, List list) {
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
if (i < 0) {
i = 0;
}
if (j >= this.entitySlices.length) {
j = this.entitySlices.length - 1;
2011-02-01 23:49:28 +01:00
}
for (int k = i; k <= j; ++k) {
List list1 = this.entitySlices[k];
2011-02-01 23:49:28 +01:00
for (int l = 0; l < list1.size(); ++l) {
Entity entity1 = (Entity) list1.get(l);
if (entity1 != entity && entity1.boundingBox.a(axisalignedbb)) {
list.add(entity1);
2012-01-12 23:10:13 +01:00
Entity[] aentity = entity1.aR();
2011-11-20 09:01:14 +01:00
if (aentity != null) {
for (int i1 = 0; i1 < aentity.length; ++i1) {
entity1 = aentity[i1];
if (entity1 != entity && entity1.boundingBox.a(axisalignedbb)) {
list.add(entity1);
}
}
}
2011-02-01 23:49:28 +01:00
}
}
}
}
public void a(Class oclass, AxisAlignedBB axisalignedbb, List list) {
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
if (i < 0) {
i = 0;
2011-11-20 09:01:14 +01:00
} else if (i >= this.entitySlices.length) {
i = this.entitySlices.length - 1;
2011-02-01 23:49:28 +01:00
}
if (j >= this.entitySlices.length) {
j = this.entitySlices.length - 1;
2011-11-20 09:01:14 +01:00
} else if (j < 0) {
j = 0;
2011-02-01 23:49:28 +01:00
}
for (int k = i; k <= j; ++k) {
List list1 = this.entitySlices[k];
2011-02-01 23:49:28 +01:00
for (int l = 0; l < list1.size(); ++l) {
Entity entity = (Entity) list1.get(l);
if (oclass.isAssignableFrom(entity.getClass()) && entity.boundingBox.a(axisalignedbb)) {
list.add(entity);
}
}
}
}
public boolean a(boolean flag) {
2011-09-15 02:23:52 +02:00
if (this.r) {
2011-02-01 23:49:28 +01:00
return false;
} else {
if (flag) {
2011-09-15 02:23:52 +02:00
if (this.s && this.world.getTime() != this.t) {
2011-02-01 23:49:28 +01:00
return true;
}
2011-09-15 02:23:52 +02:00
} else if (this.s && this.world.getTime() >= this.t + 600L) {
2011-02-01 23:49:28 +01:00
return true;
}
2011-09-15 02:23:52 +02:00
return this.q;
2011-02-01 23:49:28 +01:00
}
}
public int getData(byte[] abyte, int i, int j, int k, int l, int i1, int j1, int k1) {
2011-05-26 14:48:22 +02:00
int l1 = l - i;
int i2 = i1 - j;
int j2 = j1 - k;
2012-02-29 22:31:04 +01:00
if (l1 * i2 * j2 == this.blocks.length) {
System.arraycopy(this.blocks, 0, abyte, k1, this.blocks.length);
k1 += this.blocks.length;
2011-05-26 14:48:22 +02:00
System.arraycopy(this.g.a, 0, abyte, k1, this.g.a.length);
k1 += this.g.a.length;
2011-09-15 02:23:52 +02:00
System.arraycopy(this.i.a, 0, abyte, k1, this.i.a.length);
k1 += this.i.a.length;
System.arraycopy(this.h.a, 0, abyte, k1, this.h.a.length);
k1 += this.h.a.length;
2011-05-26 14:48:22 +02:00
return k1;
} else {
int k2;
int l2;
int i3;
int j3;
for (k2 = i; k2 < l; ++k2) {
2011-11-20 09:01:14 +01:00
for (l2 = k; l2 < j1; ++l2) {
i3 = k2 << this.world.heightBitsPlusFour | l2 << this.world.heightBits | j;
j3 = i1 - j;
2012-02-29 22:31:04 +01:00
System.arraycopy(this.blocks, i3, abyte, k1, j3);
2011-11-20 09:01:14 +01:00
k1 += j3;
2011-05-26 14:48:22 +02:00
}
2011-02-01 23:49:28 +01:00
}
2011-05-26 14:48:22 +02:00
for (k2 = i; k2 < l; ++k2) {
2011-11-20 09:01:14 +01:00
for (l2 = k; l2 < j1; ++l2) {
i3 = (k2 << this.world.heightBitsPlusFour | l2 << this.world.heightBits | j) >> 1;
j3 = (i1 - j) / 2;
System.arraycopy(this.g.a, i3, abyte, k1, j3);
k1 += j3;
2011-05-26 14:48:22 +02:00
}
2011-02-01 23:49:28 +01:00
}
2011-05-26 14:48:22 +02:00
for (k2 = i; k2 < l; ++k2) {
2011-11-20 09:01:14 +01:00
for (l2 = k; l2 < j1; ++l2) {
i3 = (k2 << this.world.heightBitsPlusFour | l2 << this.world.heightBits | j) >> 1;
j3 = (i1 - j) / 2;
System.arraycopy(this.i.a, i3, abyte, k1, j3);
k1 += j3;
2011-05-26 14:48:22 +02:00
}
2011-02-01 23:49:28 +01:00
}
2011-05-26 14:48:22 +02:00
for (k2 = i; k2 < l; ++k2) {
2011-11-20 09:01:14 +01:00
for (l2 = k; l2 < j1; ++l2) {
i3 = (k2 << this.world.heightBitsPlusFour | l2 << this.world.heightBits | j) >> 1;
j3 = (i1 - j) / 2;
System.arraycopy(this.h.a, i3, abyte, k1, j3);
k1 += j3;
2011-05-26 14:48:22 +02:00
}
2011-02-01 23:49:28 +01:00
}
2011-05-26 14:48:22 +02:00
return k1;
}
2011-02-01 23:49:28 +01:00
}
public Random a(long i) {
return new Random(this.world.getSeed() + (long) (this.x * this.x * 4987142) + (long) (this.x * 5947611) + (long) (this.z * this.z) * 4392871L + (long) (this.z * 389711) ^ i);
2011-02-01 23:49:28 +01:00
}
2011-11-20 09:01:14 +01:00
public boolean isEmpty() {
return false;
}
public void h() {
2012-02-29 22:31:04 +01:00
BlockRegister.a(this.blocks);
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);
}
}
public int c(int i, int j) {
int k = i | j << 4;
int l = this.c[k];
if (l == -999) {
2011-11-20 09:01:14 +01:00
int i1 = this.world.height - 1;
2011-09-15 02:23:52 +02:00
l = -1;
while (i1 > 0 && l == -1) {
int j1 = this.getTypeId(i, i1, j);
Material material = j1 == 0 ? Material.AIR : Block.byId[j1].material;
if (!material.isSolid() && !material.isLiquid()) {
--i1;
} else {
l = i1 + 1;
}
}
this.c[k] = l;
}
return l;
2011-02-01 23:49:28 +01:00
}
2011-03-31 22:40:00 +02:00
2011-11-20 09:01:14 +01:00
public void i() {
2012-01-12 23:10:13 +01:00
if (this.v && !this.world.worldProvider.f) {
2011-11-20 09:01:14 +01:00
this.k();
}
}
public ChunkCoordIntPair j() {
return new ChunkCoordIntPair(this.x, this.z);
2011-03-31 22:40:00 +02:00
}
2011-02-01 23:49:28 +01:00
}