下面列出了org.bukkit.ChunkSnapshot#getBlockData ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
public MaterialData getOriginalMaterial(int x, int y, int z) {
if (y < 0 || y >= 256) return new MaterialData(Material.AIR);
ChunkVector chunkVector = ChunkVector.ofBlock(x, y, z);
ChunkSnapshot chunkSnapshot = chunkSnapshots.get(chunkVector);
if (chunkSnapshot != null) {
BlockVector chunkPos = chunkVector.worldToChunk(x, y, z);
return new MaterialData(
chunkSnapshot.getBlockTypeId(
chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()),
(byte)
chunkSnapshot.getBlockData(
chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()));
} else {
return match.getWorld().getBlockAt(x, y, z).getState().getMaterialData();
}
}
public MaterialData getOriginalMaterial(int x, int y, int z) {
if(y < 0 || y >= 256) return new MaterialData(Material.AIR);
ChunkVector chunkVector = ChunkVector.ofBlock(x, y, z);
ChunkSnapshot chunkSnapshot = chunkSnapshots.get(chunkVector);
if(chunkSnapshot != null) {
BlockVector chunkPos = chunkVector.worldToChunk(x, y, z);
return new MaterialData(chunkSnapshot.getBlockTypeId(chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()),
(byte) chunkSnapshot.getBlockData(chunkPos.getBlockX(), chunkPos.getBlockY(), chunkPos.getBlockZ()));
} else {
return getMatch().getWorld().getBlockAt(x, y, z).getState().getMaterialData();
}
}
@Override
public int getCombinedId4Data(ChunkSnapshot chunk, int x, int y, int z) {
if (chunk.isSectionEmpty(y >> 4)) {
return 0;
}
int id = chunk.getBlockTypeId(x & 15, y, z & 15);
if (FaweCache.hasData(id)) {
int data = chunk.getBlockData(x & 15, y, z & 15);
return (id << 4) + data;
} else {
return id << 4;
}
}
@SuppressWarnings("deprecation")
public static int getBlockData(ChunkSnapshot snapshot, int x, int y, int z) {
return snapshot.getBlockData(x, y, z);
}
private void gzipChunk(ChunkSnapshot chunk, ByteBuf out) {
int mask = 0;
int count = 0;
for (int i = 0; i < 16; i++) {
if (!chunk.isSectionEmpty(i)) {
mask |= 1 << i;
count++;
}
}
ByteBuf data = allocator.buffer(16 * 16 * 16 * 4 * count + 3 + 256);
data.writeByte(1); // The chunk exists
data.writeShort(mask);
int offset = 0;
int blockDataOffset = 16 * 16 * 16 * 2 * count;
int skyDataOffset = blockDataOffset + 16 * 16 * 16 * count;
for (int i = 0; i < 16; i++) {
if (!chunk.isSectionEmpty(i)) {
for (int oy = 0; oy < 16; oy++) {
for (int oz = 0; oz < 16; oz++) {
for (int ox = 0; ox < 16; ox++) {
int y = oy + (i << 4);
int id = chunk.getBlockTypeId(ox, y, oz);
int dValue = chunk.getBlockData(ox, y, oz);
data.setShort((offset << 1) + 3, (id << 4) | dValue);
data.setByte(blockDataOffset + offset + 3, chunk.getBlockEmittedLight(ox, y, oz));
data.setByte(skyDataOffset + offset + 3, chunk.getBlockSkyLight(ox, y, oz));
offset++;
}
}
}
}
}
for (int x = 0; x < 16; x++) {
for (int z = 0; z < 16; z++) {
data.setByte(skyDataOffset + offset + 3 + x + z * 16, ThinkBiome.bukkitToId(chunk.getBiome(x, z)));
}
}
data.writerIndex(data.capacity());
try {
GZIPOutputStream gzip = new GZIPOutputStream(new ByteBufOutputStream(out));
byte[] bytes = new byte[data.readableBytes()];
data.readBytes(bytes);
gzip.write(bytes);
gzip.close();
} catch (IOException e) {
throw new RuntimeException();
} finally {
data.release();
}
}