Java Code Examples for us.myles.ViaVersion.api.minecraft.chunks.ChunkSection#getPaletteSize()
The following examples show how to use
us.myles.ViaVersion.api.minecraft.chunks.ChunkSection#getPaletteSize() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ChunkSectionType1_16.java From ViaVersion with MIT License | 5 votes |
@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); } }
Example 2
Source File: ChunkSectionType1_13.java From ViaVersion with MIT License | 5 votes |
@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); } }
Example 3
Source File: ChunkSectionType1_9.java From ViaVersion with MIT License | 5 votes |
@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); } }
Example 4
Source File: ConnectionData.java From ViaVersion with MIT License | 5 votes |
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); } } } } } }