use of com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1 in project ViaVersion by ViaVersion.
the class WorldPackets method register.
public static void register(final Protocol1_18To1_17_1 protocol) {
protocol.registerClientbound(ClientboundPackets1_17_1.BLOCK_ENTITY_DATA, new PacketRemapper() {
@Override
public void registerMap() {
map(Type.POSITION1_14);
handler(wrapper -> {
final short id = wrapper.read(Type.UNSIGNED_BYTE);
final int newId = BlockEntityIds.newId(id);
wrapper.write(Type.VAR_INT, newId);
handleSpawners(newId, wrapper.passthrough(Type.NBT));
});
}
});
protocol.registerClientbound(ClientboundPackets1_17_1.UPDATE_LIGHT, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final int chunkX = wrapper.passthrough(Type.VAR_INT);
final int chunkZ = wrapper.passthrough(Type.VAR_INT);
if (wrapper.user().get(ChunkLightStorage.class).isLoaded(chunkX, chunkZ)) {
if (!Via.getConfig().cache1_17Light()) {
// Light packets updating already sent chunks are the same as before
return;
}
// Pass through and cache light data
} else {
// Cancel and cache the light data
wrapper.cancel();
}
final boolean trustEdges = wrapper.passthrough(Type.BOOLEAN);
final long[] skyLightMask = wrapper.passthrough(Type.LONG_ARRAY_PRIMITIVE);
final long[] blockLightMask = wrapper.passthrough(Type.LONG_ARRAY_PRIMITIVE);
final long[] emptySkyLightMask = wrapper.passthrough(Type.LONG_ARRAY_PRIMITIVE);
final long[] emptyBlockLightMask = wrapper.passthrough(Type.LONG_ARRAY_PRIMITIVE);
final int skyLightLenght = wrapper.passthrough(Type.VAR_INT);
final byte[][] skyLight = new byte[skyLightLenght][];
for (int i = 0; i < skyLightLenght; i++) {
skyLight[i] = wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE);
}
final int blockLightLength = wrapper.passthrough(Type.VAR_INT);
final byte[][] blockLight = new byte[blockLightLength][];
for (int i = 0; i < blockLightLength; i++) {
blockLight[i] = wrapper.passthrough(Type.BYTE_ARRAY_PRIMITIVE);
}
final ChunkLightStorage lightStorage = wrapper.user().get(ChunkLightStorage.class);
lightStorage.storeLight(chunkX, chunkZ, new ChunkLightStorage.ChunkLight(trustEdges, skyLightMask, blockLightMask, emptySkyLightMask, emptyBlockLightMask, skyLight, blockLight));
});
}
});
protocol.registerClientbound(ClientboundPackets1_17_1.CHUNK_DATA, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final EntityTracker tracker = protocol.getEntityRewriter().tracker(wrapper.user());
final Chunk oldChunk = wrapper.read(new Chunk1_17Type(tracker.currentWorldSectionHeight()));
final List<BlockEntity> blockEntities = new ArrayList<>(oldChunk.getBlockEntities().size());
for (final CompoundTag tag : oldChunk.getBlockEntities()) {
final NumberTag xTag = tag.get("x");
final NumberTag yTag = tag.get("y");
final NumberTag zTag = tag.get("z");
final StringTag idTag = tag.get("id");
if (xTag == null || yTag == null || zTag == null || idTag == null) {
continue;
}
final String id = idTag.getValue();
final int typeId = protocol.getMappingData().blockEntityIds().getInt(id.replace("minecraft:", ""));
if (typeId == -1) {
Via.getPlatform().getLogger().warning("Unknown block entity: " + id);
}
handleSpawners(typeId, tag);
final byte packedXZ = (byte) ((xTag.asInt() & 15) << 4 | (zTag.asInt() & 15));
blockEntities.add(new BlockEntityImpl(packedXZ, yTag.asShort(), typeId, tag));
}
final int[] biomeData = oldChunk.getBiomeData();
final ChunkSection[] sections = oldChunk.getSections();
for (int i = 0; i < sections.length; i++) {
ChunkSection section = sections[i];
if (section == null) {
// There's no section mask anymore
section = new ChunkSectionImpl();
sections[i] = section;
section.setNonAirBlocksCount(0);
final DataPaletteImpl blockPalette = new DataPaletteImpl(ChunkSection.SIZE);
blockPalette.addId(0);
section.addPalette(PaletteType.BLOCKS, blockPalette);
}
// Fill biome palette
final DataPaletteImpl biomePalette = new DataPaletteImpl(ChunkSection.BIOME_SIZE);
section.addPalette(PaletteType.BIOMES, biomePalette);
final int offset = i * ChunkSection.BIOME_SIZE;
for (int biomeIndex = 0, biomeArrayIndex = offset; biomeIndex < ChunkSection.BIOME_SIZE; biomeIndex++, biomeArrayIndex++) {
// Also catch invalid biomes with id -1
final int biome = biomeData[biomeArrayIndex];
biomePalette.setIdAt(biomeIndex, biome != -1 ? biome : 0);
}
}
final Chunk chunk = new Chunk1_18(oldChunk.getX(), oldChunk.getZ(), sections, oldChunk.getHeightMap(), blockEntities);
wrapper.write(new Chunk1_18Type(tracker.currentWorldSectionHeight(), MathUtil.ceilLog2(protocol.getMappingData().getBlockStateMappings().mappedSize()), MathUtil.ceilLog2(tracker.biomesSent())), chunk);
final ChunkLightStorage lightStorage = wrapper.user().get(ChunkLightStorage.class);
final boolean alreadyLoaded = !lightStorage.addLoadedChunk(chunk.getX(), chunk.getZ());
// Append light data to chunk packet
final ChunkLightStorage.ChunkLight light = Via.getConfig().cache1_17Light() ? lightStorage.getLight(chunk.getX(), chunk.getZ()) : lightStorage.removeLight(chunk.getX(), chunk.getZ());
if (light == null) {
Via.getPlatform().getLogger().warning("No light data found for chunk at " + chunk.getX() + ", " + chunk.getZ() + ". Chunk was already loaded: " + alreadyLoaded);
final BitSet emptyLightMask = new BitSet();
emptyLightMask.set(0, tracker.currentWorldSectionHeight() + 2);
wrapper.write(Type.BOOLEAN, false);
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, new long[0]);
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, new long[0]);
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, emptyLightMask.toLongArray());
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, emptyLightMask.toLongArray());
wrapper.write(Type.VAR_INT, 0);
wrapper.write(Type.VAR_INT, 0);
} else {
wrapper.write(Type.BOOLEAN, light.trustEdges());
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.skyLightMask());
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.blockLightMask());
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.emptySkyLightMask());
wrapper.write(Type.LONG_ARRAY_PRIMITIVE, light.emptyBlockLightMask());
wrapper.write(Type.VAR_INT, light.skyLight().length);
for (final byte[] skyLight : light.skyLight()) {
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, skyLight);
}
wrapper.write(Type.VAR_INT, light.blockLight().length);
for (final byte[] blockLight : light.blockLight()) {
wrapper.write(Type.BYTE_ARRAY_PRIMITIVE, blockLight);
}
}
});
}
});
protocol.registerClientbound(ClientboundPackets1_17_1.UNLOAD_CHUNK, new PacketRemapper() {
@Override
public void registerMap() {
handler(wrapper -> {
final int chunkX = wrapper.passthrough(Type.INT);
final int chunkZ = wrapper.passthrough(Type.INT);
wrapper.user().get(ChunkLightStorage.class).clear(chunkX, chunkZ);
});
}
});
}
use of com.viaversion.viaversion.protocols.protocol1_18to1_17_1.Protocol1_18To1_17_1 in project ViaVersion by ViaVersion.
the class ProtocolManagerImpl method registerProtocols.
public void registerProtocols() {
// Base Protocol
registerBaseProtocol(BASE_PROTOCOL, Range.lessThan(Integer.MIN_VALUE));
registerBaseProtocol(new BaseProtocol1_7(), Range.lessThan(ProtocolVersion.v1_16.getVersion()));
registerBaseProtocol(new BaseProtocol1_16(), Range.atLeast(ProtocolVersion.v1_16.getVersion()));
registerProtocol(new Protocol1_9To1_8(), ProtocolVersion.v1_9, ProtocolVersion.v1_8);
registerProtocol(new Protocol1_9_1To1_9(), Arrays.asList(ProtocolVersion.v1_9_1.getVersion(), ProtocolVersion.v1_9_2.getVersion()), ProtocolVersion.v1_9.getVersion());
registerProtocol(new Protocol1_9_3To1_9_1_2(), ProtocolVersion.v1_9_3, ProtocolVersion.v1_9_2);
registerProtocol(new Protocol1_9To1_9_1(), ProtocolVersion.v1_9, ProtocolVersion.v1_9_1);
registerProtocol(new Protocol1_9_1_2To1_9_3_4(), Arrays.asList(ProtocolVersion.v1_9_1.getVersion(), ProtocolVersion.v1_9_2.getVersion()), ProtocolVersion.v1_9_3.getVersion());
registerProtocol(new Protocol1_10To1_9_3_4(), ProtocolVersion.v1_10, ProtocolVersion.v1_9_3);
registerProtocol(new Protocol1_11To1_10(), ProtocolVersion.v1_11, ProtocolVersion.v1_10);
registerProtocol(new Protocol1_11_1To1_11(), ProtocolVersion.v1_11_1, ProtocolVersion.v1_11);
registerProtocol(new Protocol1_12To1_11_1(), ProtocolVersion.v1_12, ProtocolVersion.v1_11_1);
registerProtocol(new Protocol1_12_1To1_12(), ProtocolVersion.v1_12_1, ProtocolVersion.v1_12);
registerProtocol(new Protocol1_12_2To1_12_1(), ProtocolVersion.v1_12_2, ProtocolVersion.v1_12_1);
registerProtocol(new Protocol1_13To1_12_2(), ProtocolVersion.v1_13, ProtocolVersion.v1_12_2);
registerProtocol(new Protocol1_13_1To1_13(), ProtocolVersion.v1_13_1, ProtocolVersion.v1_13);
registerProtocol(new Protocol1_13_2To1_13_1(), ProtocolVersion.v1_13_2, ProtocolVersion.v1_13_1);
registerProtocol(new Protocol1_14To1_13_2(), ProtocolVersion.v1_14, ProtocolVersion.v1_13_2);
registerProtocol(new Protocol1_14_1To1_14(), ProtocolVersion.v1_14_1, ProtocolVersion.v1_14);
registerProtocol(new Protocol1_14_2To1_14_1(), ProtocolVersion.v1_14_2, ProtocolVersion.v1_14_1);
registerProtocol(new Protocol1_14_3To1_14_2(), ProtocolVersion.v1_14_3, ProtocolVersion.v1_14_2);
registerProtocol(new Protocol1_14_4To1_14_3(), ProtocolVersion.v1_14_4, ProtocolVersion.v1_14_3);
registerProtocol(new Protocol1_15To1_14_4(), ProtocolVersion.v1_15, ProtocolVersion.v1_14_4);
registerProtocol(new Protocol1_15_1To1_15(), ProtocolVersion.v1_15_1, ProtocolVersion.v1_15);
registerProtocol(new Protocol1_15_2To1_15_1(), ProtocolVersion.v1_15_2, ProtocolVersion.v1_15_1);
registerProtocol(new Protocol1_16To1_15_2(), ProtocolVersion.v1_16, ProtocolVersion.v1_15_2);
registerProtocol(new Protocol1_16_1To1_16(), ProtocolVersion.v1_16_1, ProtocolVersion.v1_16);
registerProtocol(new Protocol1_16_2To1_16_1(), ProtocolVersion.v1_16_2, ProtocolVersion.v1_16_1);
registerProtocol(new Protocol1_16_3To1_16_2(), ProtocolVersion.v1_16_3, ProtocolVersion.v1_16_2);
registerProtocol(new Protocol1_16_4To1_16_3(), ProtocolVersion.v1_16_4, ProtocolVersion.v1_16_3);
registerProtocol(new Protocol1_17To1_16_4(), ProtocolVersion.v1_17, ProtocolVersion.v1_16_4);
registerProtocol(new Protocol1_17_1To1_17(), ProtocolVersion.v1_17_1, ProtocolVersion.v1_17);
registerProtocol(new Protocol1_18To1_17_1(), ProtocolVersion.v1_18, ProtocolVersion.v1_17_1);
registerProtocol(new Protocol1_18_2To1_18(), ProtocolVersion.v1_18_2, ProtocolVersion.v1_18);
}
Aggregations