Java源码示例:us.myles.ViaVersion.api.minecraft.chunks.ChunkSection
示例1
public ChunkSection read(ByteBuf buffer) throws Exception {
ChunkSection chunkSection = new ChunkSection();
chunkSection.clearPalette();
byte[] blockData = new byte[8192];
buffer.readBytes(blockData);
ShortBuffer blockBuf = ByteBuffer.wrap(blockData).order(ByteOrder.LITTLE_ENDIAN).asShortBuffer();
for(int i = 0; i < 4096; ++i) {
int mask = blockBuf.get();
int type = mask >> 4;
int data = mask & 15;
chunkSection.setBlock(i, type, data);
}
return chunkSection;
}
示例2
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
ChunkSection chunkSection = new ChunkSection();
// Don't clear palette because 0 index needs to be air in 1.9 version
ByteBuf littleEndianView = buffer.order(ByteOrder.LITTLE_ENDIAN);
for (int i = 0; i < ChunkSection.SIZE; i++) {
int mask = littleEndianView.readShort();
int type = mask >> 4;
int data = mask & 0xF;
chunkSection.setBlock(i, type, data);
}
return chunkSection;
}
示例3
public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception {
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int block = chunkSection.getFlatBlock(x, y, z);
buffer.writeByte(block);
buffer.writeByte(block >> 8);
}
}
}
}
示例4
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
ChunkSection chunkSection = new ChunkSection();
// Reaad bits per block
int bitsPerBlock = buffer.readUnsignedByte();
int originalBitsPerBlock = bitsPerBlock;
if (bitsPerBlock == 0 || bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
int paletteLength = bitsPerBlock == GLOBAL_PALETTE ? 0 : Type.VAR_INT.readPrimitive(buffer);
// Read palette
chunkSection.clearPalette();
for (int i = 0; i < paletteLength; i++) {
chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer));
}
// Read blocks
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
if (blockData.length > 0) {
char valuesPerLong = (char) (64 / bitsPerBlock);
int expectedLength = (ChunkSection.SIZE + valuesPerLong - 1) / valuesPerLong;
if (blockData.length != expectedLength) {
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
}
for (int i = 0; i < blockData.length; i++) {
blockData[i] = buffer.readLong();
}
CompactArrayUtil.iterateCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE, blockData,
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
}
return chunkSection;
}
示例5
@Override
public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception {
int bitsPerBlock = 4;
while (chunkSection.getPaletteSize() > 1 << bitsPerBlock) {
bitsPerBlock += 1;
}
if (bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
buffer.writeByte(bitsPerBlock);
// Write pallet (or not)
if (bitsPerBlock != GLOBAL_PALETTE) {
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize());
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteEntry(i));
}
}
long[] data = CompactArrayUtil.createCompactArrayWithPadding(bitsPerBlock, ChunkSection.SIZE,
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex);
Type.VAR_INT.writePrimitive(buffer, data.length);
for (long l : data) {
buffer.writeLong(l);
}
}
示例6
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
ChunkSection chunkSection = new ChunkSection();
// Reaad bits per block
int bitsPerBlock = buffer.readUnsignedByte();
int originalBitsPerBlock = bitsPerBlock;
if (bitsPerBlock == 0 || bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
int paletteLength = bitsPerBlock == GLOBAL_PALETTE ? 0 : Type.VAR_INT.readPrimitive(buffer);
// Read palette
chunkSection.clearPalette();
for (int i = 0; i < paletteLength; i++) {
chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer));
}
// Read blocks
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
if (blockData.length > 0) {
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
if (blockData.length != expectedLength) {
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
}
for (int i = 0; i < blockData.length; i++) {
blockData[i] = buffer.readLong();
}
CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData,
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock : chunkSection::setPaletteIndex);
}
return chunkSection;
}
示例7
@Override
public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception {
int bitsPerBlock = 4;
while (chunkSection.getPaletteSize() > 1 << bitsPerBlock) {
bitsPerBlock += 1;
}
if (bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
buffer.writeByte(bitsPerBlock);
// Write pallet (or not)
if (bitsPerBlock != GLOBAL_PALETTE) {
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize());
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteEntry(i));
}
}
long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE,
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex);
Type.VAR_INT.writePrimitive(buffer, data.length);
for (long l : data) {
buffer.writeLong(l);
}
}
示例8
@Override
public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception {
int bitsPerBlock = 4;
while (chunkSection.getPaletteSize() > 1 << bitsPerBlock) {
bitsPerBlock += 1;
}
if (bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
long maxEntryValue = (1L << bitsPerBlock) - 1;
buffer.writeByte(bitsPerBlock);
// Write pallet (or not)
if (bitsPerBlock != GLOBAL_PALETTE) {
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteSize());
for (int i = 0; i < chunkSection.getPaletteSize(); i++) {
Type.VAR_INT.writePrimitive(buffer, chunkSection.getPaletteEntry(i));
}
} else {
Type.VAR_INT.writePrimitive(buffer, 0);
}
long[] data = CompactArrayUtil.createCompactArray(bitsPerBlock, ChunkSection.SIZE,
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::getFlatBlock : chunkSection::getPaletteIndex);
Type.VAR_INT.writePrimitive(buffer, data.length);
for (long l : data) {
buffer.writeLong(l);
}
}
示例9
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NBT.write(output, chunk.getHeightMap());
// Write biome data
if (chunk.isBiomeData()) {
for (int value : chunk.getBiomeData()) {
output.writeInt(value);
}
}
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set
buf.writeShort(section.getNonAirBlocksCount());
Types1_13.CHUNK_SECTION.write(buf, section);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes());
output.writeBytes(buf);
} finally {
buf.release(); // release buffer
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
示例10
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set
Types1_9.CHUNK_SECTION.write(buf, section);
section.writeBlockLight(buf);
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
section.writeSkyLight(buf);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
output.writeBytes(buf);
} finally {
buf.release(); // release buffer
}
// Write biome data
if (chunk.isBiomeData()) {
for (int biome : chunk.getBiomeData()) {
output.writeByte((byte) biome);
}
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
示例11
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NBT.write(output, chunk.getHeightMap());
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set
buf.writeShort(section.getNonAirBlocksCount());
Types1_13.CHUNK_SECTION.write(buf, section);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0)); // 256 * 4
output.writeBytes(buf);
} finally {
buf.release(); // release buffer
}
// Write biome data
if (chunk.isBiomeData()) {
for (int value : chunk.getBiomeData()) {
output.writeInt(value & 0xFF); // This is a temporary workaround, we'll look into fixing this soon :)
}
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
示例12
@Override
public void write(ByteBuf output, ClientChunks param, Chunk input) throws Exception {
if (!(input instanceof Chunk1_8)) throw new Exception("Incompatible chunk, " + input.getClass());
Chunk1_8 chunk = (Chunk1_8) input;
// Write primary info
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
if (chunk.isUnloadPacket()) return;
output.writeByte(chunk.isFullChunk() ? 0x01 : 0x00);
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < SECTION_COUNT; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set
Types1_9.CHUNK_SECTION.write(buf, section);
section.writeBlockLight(buf);
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
section.writeSkyLight(buf);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.hasBiomeData() ? 256 : 0));
output.writeBytes(buf);
} finally {
buf.release(); // release buffer
}
// Write biome data
if (chunk.hasBiomeData()) {
for (int biome : chunk.getBiomeData()) {
output.writeByte((byte) biome);
}
}
}
示例13
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());
output.writeBoolean(chunk.isIgnoreOldLightData());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
Type.NBT.write(output, chunk.getHeightMap());
// Write biome data
if (chunk.isBiomeData()) {
for (int value : chunk.getBiomeData()) {
output.writeInt(value);
}
}
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set
buf.writeShort(section.getNonAirBlocksCount());
Types1_16.CHUNK_SECTION.write(buf, section);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes());
output.writeBytes(buf);
} finally {
buf.release(); // release buffer
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(EMPTY_COMPOUNDS));
}
示例14
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set
Types1_13.CHUNK_SECTION.write(buf, section);
section.writeBlockLight(buf);
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
section.writeSkyLight(buf);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 1024 : 0));
output.writeBytes(buf);
} finally {
buf.release(); // release buffer
}
// Write biome data
if (chunk.isBiomeData()) {
for (int value : chunk.getBiomeData()) {
output.writeInt(value);
}
}
// Write Block Entities
Type.NBT_ARRAY.write(output, chunk.getBlockEntities().toArray(new CompoundTag[0]));
}
示例15
public static void connectBlocks(UserConnection user, Chunk chunk) {
long xOff = chunk.getX() << 4;
long zOff = chunk.getZ() << 4;
for (int i = 0; i < chunk.getSections().length; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue;
boolean willConnect = false;
for (int p = 0; p < section.getPaletteSize(); p++) {
int id = section.getPaletteEntry(p);
if (ConnectionData.connects(id)) {
willConnect = true;
break;
}
}
if (!willConnect) continue;
long yOff = i << 4;
for (int y = 0; y < 16; y++) {
for (int z = 0; z < 16; z++) {
for (int x = 0; x < 16; x++) {
int block = section.getFlatBlock(x, y, z);
ConnectionHandler handler = ConnectionData.getConnectionHandler(block);
if (handler != null) {
block = handler.connect(user, new Position(
(int) (xOff + x),
(short) (yOff + y),
(int) (zOff + z)
), block);
section.setFlatBlock(x, y, z, block);
}
}
}
}
}
}
示例16
@Override
public void write(ByteBuf output, ClientWorld world, Chunk chunk) throws Exception {
output.writeInt(chunk.getX());
output.writeInt(chunk.getZ());
output.writeBoolean(chunk.isFullChunk());
Type.VAR_INT.writePrimitive(output, chunk.getBitmask());
ByteBuf buf = output.alloc().buffer();
try {
for (int i = 0; i < 16; i++) {
ChunkSection section = chunk.getSections()[i];
if (section == null) continue; // Section not set
Types1_9.CHUNK_SECTION.write(buf, section);
section.writeBlockLight(buf);
if (!section.hasSkyLight()) continue; // No sky light, we're done here.
section.writeSkyLight(buf);
}
buf.readerIndex(0);
Type.VAR_INT.writePrimitive(output, buf.readableBytes() + (chunk.isBiomeData() ? 256 : 0));
output.writeBytes(buf);
} finally {
buf.release(); // release buffer
}
// Write biome data
if (chunk.isBiomeData()) {
for (int biome : chunk.getBiomeData()) {
output.writeByte((byte) biome);
}
}
}
示例17
public static void register(Protocol protocol) {
BlockRewriter blockRewriter = new BlockRewriter(protocol, Type.POSITION, Protocol1_13To1_13_1::getNewBlockStateId, Protocol1_13To1_13_1::getNewBlockId);
protocol.registerOutgoing(ClientboundPackets1_13.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(new PacketHandler() {
@Override
public void handle(PacketWrapper wrapper) throws Exception {
ClientWorld clientWorld = wrapper.user().get(ClientWorld.class);
Chunk chunk = wrapper.passthrough(new Chunk1_13Type(clientWorld));
for (ChunkSection section : chunk.getSections()) {
if (section != null) {
for (int i = 0; i < section.getPaletteSize(); i++) {
section.setPaletteEntry(i, Protocol1_13To1_13_1.getNewBlockStateId(section.getPaletteEntry(i)));
}
}
}
}
});
}
});
blockRewriter.registerBlockAction(ClientboundPackets1_13.BLOCK_ACTION);
blockRewriter.registerBlockChange(ClientboundPackets1_13.BLOCK_CHANGE);
blockRewriter.registerMultiBlockChange(ClientboundPackets1_13.MULTI_BLOCK_CHANGE);
blockRewriter.registerEffect(ClientboundPackets1_13.EFFECT, 1010, 2001, InventoryPackets1_13_1::getOldItemId);
blockRewriter.registerSpawnParticle(ClientboundPackets1_13.SPAWN_PARTICLE, 3, 20, 27, InventoryPackets1_13_1::toClient, Type.FLAT_ITEM, Type.FLOAT);
}
示例18
@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
// Copied from ViaVersion, removed some things
int chunkX = input.readInt();
int chunkZ = input.readInt();
boolean groundUp = input.readByte() != 0;
int bitmask = input.readUnsignedShort();
int dataLength = Type.VAR_INT.read(input);
if (bitmask == 0 && groundUp) {
// This is a chunks unload packet
if (dataLength >= 256) { //1.8 likes to send biome data in unload packets?!
input.readerIndex(input.readerIndex() + 256);
}
return new Chunk1_8(chunkX, chunkZ);
}
// Data to be read
ChunkSection[] sections = new ChunkSection[16];
int[] biomeData = null;
int startIndex = input.readerIndex();
// Read blocks
for (int i = 0; i < 16; i++) {
if ((bitmask & 1 << i) == 0) continue;
sections[i] = CHUNK_SECTION_TYPE.read(input);
}
// Read block light
for (int i = 0; i < 16; i++) {
if ((bitmask & 1 << i) == 0) continue;
sections[i].readBlockLight(input);
}
// Read sky light
int bytesLeft = dataLength - (input.readerIndex() - startIndex);
if (bytesLeft >= ChunkSection.LIGHT_LENGTH) {
for (int i = 0; i < 16; i++) {
if ((bitmask & 1 << i) == 0) continue;
sections[i].readSkyLight(input);
bytesLeft -= ChunkSection.LIGHT_LENGTH;
}
}
// Read biome data
if (bytesLeft >= 256) {
biomeData = new int[256];
for (int i = 0; i < 256; i++) {
biomeData[i] = input.readByte() & 0xFF;
}
bytesLeft -= 256;
}
// Check remaining bytes
if (bytesLeft > 0) {
Via.getPlatform().getLogger().log(Level.WARNING, bytesLeft + " Bytes left after reading chunks! (" + groundUp + ")");
}
// Return chunks
return new Chunk1_8(chunkX, chunkZ, groundUp, bitmask, sections, biomeData, new ArrayList<>());
}
示例19
public ChunkSectionType1_8() {
super("Chunk Section Type", ChunkSection.class);
}
示例20
public ChunkSectionType1_16() {
super("Chunk Section Type", ChunkSection.class);
}
示例21
public ChunkSectionType1_13() {
super("Chunk Section Type", ChunkSection.class);
}
示例22
public ChunkSectionType1_8() {
super("Chunk Section Type", ChunkSection.class);
}
示例23
@Override
public void write(ByteBuf buffer, ChunkSection chunkSection) throws Exception {
throw new UnsupportedOperationException();
}
示例24
public ChunkSectionType1_9() {
super("Chunk Section Type", ChunkSection.class);
}
示例25
@Override
public ChunkSection read(ByteBuf buffer) throws Exception {
ChunkSection chunkSection = new ChunkSection();
// Reaad bits per block
int bitsPerBlock = buffer.readUnsignedByte();
int originalBitsPerBlock = bitsPerBlock;
if (bitsPerBlock == 0) {
bitsPerBlock = GLOBAL_PALETTE;
}
if (bitsPerBlock < 4) {
bitsPerBlock = 4;
}
if (bitsPerBlock > 8) {
bitsPerBlock = GLOBAL_PALETTE;
}
int paletteLength = Type.VAR_INT.readPrimitive(buffer);
// Read palette
chunkSection.clearPalette();
for (int i = 0; i < paletteLength; i++) {
if (bitsPerBlock != GLOBAL_PALETTE) {
chunkSection.addPaletteEntry(Type.VAR_INT.readPrimitive(buffer));
} else {
Type.VAR_INT.readPrimitive(buffer);
}
}
// Read blocks
long[] blockData = new long[Type.VAR_INT.readPrimitive(buffer)];
if (blockData.length > 0) {
int expectedLength = (int) Math.ceil(ChunkSection.SIZE * bitsPerBlock / 64.0);
if (blockData.length != expectedLength) {
throw new IllegalStateException("Block data length (" + blockData.length + ") does not match expected length (" + expectedLength + ")! bitsPerBlock=" + bitsPerBlock + ", originalBitsPerBlock=" + originalBitsPerBlock);
}
for (int i = 0; i < blockData.length; i++) {
blockData[i] = buffer.readLong();
}
CompactArrayUtil.iterateCompactArray(bitsPerBlock, ChunkSection.SIZE, blockData,
bitsPerBlock == GLOBAL_PALETTE ? chunkSection::setFlatBlock
: chunkSection::setPaletteIndex);
}
return chunkSection;
}
示例26
@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
int chunkX = input.readInt();
int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NBT.read(input);
int[] biomeData = fullChunk ? new int[1024] : null;
if (fullChunk) {
for (int i = 0; i < 1024; i++) {
biomeData[i] = input.readInt();
}
}
Type.VAR_INT.readPrimitive(input); // data size in bytes
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_13.CHUNK_SECTION.read(input);
section.setNonAirBlocksCount(nonAirBlocksCount);
sections[i] = section;
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
}
示例27
@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
int chunkX = input.readInt();
int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
Type.VAR_INT.readPrimitive(input);
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
ChunkSection section = Types1_9.CHUNK_SECTION.read(input);
sections[i] = section;
section.readBlockLight(input);
if (world.getEnvironment() == Environment.NORMAL) {
section.readSkyLight(input);
}
}
int[] biomeData = fullChunk ? new int[256] : null;
if (fullChunk) {
for (int i = 0; i < 256; i++) {
biomeData[i] = input.readByte() & 0xFF;
}
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, nbtData);
}
示例28
@Override
public Chunk read(ByteBuf input, ClientWorld world) throws Exception {
int chunkX = input.readInt();
int chunkZ = input.readInt();
boolean fullChunk = input.readBoolean();
int primaryBitmask = Type.VAR_INT.readPrimitive(input);
CompoundTag heightMap = Type.NBT.read(input);
Type.VAR_INT.readPrimitive(input);
// Read sections
ChunkSection[] sections = new ChunkSection[16];
for (int i = 0; i < 16; i++) {
if ((primaryBitmask & (1 << i)) == 0) continue; // Section not set
short nonAirBlocksCount = input.readShort();
ChunkSection section = Types1_13.CHUNK_SECTION.read(input);
section.setNonAirBlocksCount(nonAirBlocksCount);
sections[i] = section;
}
int[] biomeData = fullChunk ? new int[256] : null;
if (fullChunk) {
for (int i = 0; i < 256; i++) {
biomeData[i] = input.readInt();
}
}
List<CompoundTag> nbtData = new ArrayList<>(Arrays.asList(Type.NBT_ARRAY.read(input)));
// Read all the remaining bytes (workaround for #681)
if (input.readableBytes() > 0) {
byte[] array = Type.REMAINING_BYTES.read(input);
if (Via.getManager().isDebug()) {
Via.getPlatform().getLogger().warning("Found " + array.length + " more bytes than expected while reading the chunk: " + chunkX + "/" + chunkZ);
}
}
return new BaseChunk(chunkX, chunkZ, fullChunk, false, primaryBitmask, sections, biomeData, heightMap, nbtData);
}
示例29
private static void setNonFullLight(Chunk chunk, ChunkSection section, int ySection, int x, int y, int z) {
int skyLight = 0;
int blockLight = 0;
for (BlockFace blockFace : BlockFace.values()) {
NibbleArray skyLightArray = section.getSkyLightNibbleArray();
NibbleArray blockLightArray = section.getBlockLightNibbleArray();
int neighbourX = x + blockFace.getModX();
int neighbourY = y + blockFace.getModY();
int neighbourZ = z + blockFace.getModZ();
if (blockFace.getModX() != 0) {
// Another chunk, nothing we can do without an unnecessary amount of caching
if (neighbourX == 16 || neighbourX == -1) continue;
} else if (blockFace.getModY() != 0) {
if (neighbourY == 16 || neighbourY == -1) {
if (neighbourY == 16) {
ySection += 1;
neighbourY = 0;
} else {
ySection -= 1;
neighbourY = 15;
}
if (ySection == 16 || ySection == -1) continue;
ChunkSection newSection = chunk.getSections()[ySection];
if (newSection == null) continue;
skyLightArray = newSection.getSkyLightNibbleArray();
blockLightArray = newSection.getBlockLightNibbleArray();
}
} else if (blockFace.getModZ() != 0) {
// Another chunk, nothing we can do without an unnecessary amount of caching
if (neighbourZ == 16 || neighbourZ == -1) continue;
}
if (blockLightArray != null && blockLight != 15) {
int neighbourBlockLight = blockLightArray.get(neighbourX, neighbourY, neighbourZ);
if (neighbourBlockLight == 15) {
blockLight = 14;
} else if (neighbourBlockLight > blockLight) {
blockLight = neighbourBlockLight - 1; // lower light level by one
}
}
if (skyLightArray != null && skyLight != 15) {
int neighbourSkyLight = skyLightArray.get(neighbourX, neighbourY, neighbourZ);
if (neighbourSkyLight == 15) {
if (blockFace.getModY() == 1) {
// Keep 15 if block is exposed to sky
skyLight = 15;
continue;
}
skyLight = 14;
} else if (neighbourSkyLight > skyLight) {
skyLight = neighbourSkyLight - 1; // lower light level by one
}
}
}
if (skyLight != 0) {
if (!section.hasSkyLight()) {
byte[] newSkyLight = new byte[2028];
section.setSkyLight(newSkyLight);
}
section.getSkyLightNibbleArray().set(x, y, z, skyLight);
}
if (blockLight != 0) {
section.getBlockLightNibbleArray().set(x, y, z, blockLight);
}
}
示例30
@Override
public Chunk read(ByteBuf input, ClientChunks param) throws Exception {
boolean replacePistons = param.getUser().getProtocolInfo().getPipeline().contains(Protocol1_10To1_9_3_4.class) && Via.getConfig().isReplacePistons();
int replacementId = Via.getConfig().getPistonReplacementId();
int chunkX = input.readInt();
int chunkZ = input.readInt();
long chunkHash = toLong(chunkX, chunkZ);
boolean fullChunk = input.readByte() != 0;
int bitmask = input.readUnsignedShort();
int dataLength = Type.VAR_INT.readPrimitive(input);
// Data to be read
BitSet usedSections = new BitSet(16);
ChunkSection[] sections = new ChunkSection[16];
int[] biomeData = null;
// Calculate section count from bitmask
for (int i = 0; i < 16; i++) {
if ((bitmask & (1 << i)) != 0) {
usedSections.set(i);
}
}
int sectionCount = usedSections.cardinality(); // the amount of sections set
// If the chunks is from a chunks bulk, it is never an unload packet
// Other wise, if it has no data, it is :)
boolean isBulkPacket = param.getBulkChunks().remove(chunkHash);
if (sectionCount == 0 && fullChunk && !isBulkPacket && param.getLoadedChunks().contains(chunkHash)) {
// This is a chunks unload packet
param.getLoadedChunks().remove(chunkHash);
return new Chunk1_8(chunkX, chunkZ);
}
int startIndex = input.readerIndex();
param.getLoadedChunks().add(chunkHash); // mark chunks as loaded
// Read blocks
for (int i = 0; i < SECTION_COUNT; i++) {
if (!usedSections.get(i)) continue; // Section not set
ChunkSection section = Types1_8.CHUNK_SECTION.read(input);
sections[i] = section;
if (replacePistons) {
section.replacePaletteEntry(36, replacementId);
}
}
// Read block light
for (int i = 0; i < SECTION_COUNT; i++) {
if (!usedSections.get(i)) continue; // Section not set, has no light
sections[i].readBlockLight(input);
}
// Read sky light
int bytesLeft = dataLength - (input.readerIndex() - startIndex);
if (bytesLeft >= ChunkSection.LIGHT_LENGTH) {
for (int i = 0; i < SECTION_COUNT; i++) {
if (!usedSections.get(i)) continue; // Section not set, has no light
sections[i].readSkyLight(input);
bytesLeft -= ChunkSection.LIGHT_LENGTH;
}
}
// Read biome data
if (bytesLeft >= BIOME_DATA_LENGTH) {
biomeData = new int[BIOME_DATA_LENGTH];
for (int i = 0; i < BIOME_DATA_LENGTH; i++) {
biomeData[i] = input.readByte() & 0xFF;
}
bytesLeft -= BIOME_DATA_LENGTH;
}
// Check remaining bytes
if (bytesLeft > 0) {
Via.getPlatform().getLogger().log(Level.WARNING, bytesLeft + " Bytes left after reading chunks! (" + fullChunk + ")");
}
// Return chunks
return new Chunk1_8(chunkX, chunkZ, fullChunk, bitmask, sections, biomeData, new ArrayList<CompoundTag>());
}