Java Code Examples for protocolsupport.protocol.serializer.VarNumberSerializer#writeVarInt()

The following examples show how to use protocolsupport.protocol.serializer.VarNumberSerializer#writeVarInt() . 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: ChunkLight.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData chunklight = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHUNK_LIGHT);
	PositionSerializer.writeVarIntChunkCoord(chunklight, coord);
	chunklight.writeBoolean(trustEdges);
	VarNumberSerializer.writeVarInt(chunklight, setSkyLightMask);
	VarNumberSerializer.writeVarInt(chunklight, setBlockLightMask);
	VarNumberSerializer.writeVarInt(chunklight, emptySkyLightMask);
	VarNumberSerializer.writeVarInt(chunklight, emptyBlockLightMask);
	for (int i = 0; i < ChunkConstants.SECTION_COUNT_LIGHT; i++) {
		if (BitUtils.isIBitSet(setSkyLightMask, i)) {
			ArraySerializer.writeVarIntByteArray(chunklight, skyLight[i]);
		}
	}
	for (int i = 0; i < ChunkConstants.SECTION_COUNT_LIGHT; i++) {
		if (BitUtils.isIBitSet(setBlockLightMask, i)) {
			ArraySerializer.writeVarIntByteArray(chunklight, blockLight[i]);
		}
	}
	codec.write(chunklight);
}
 
Example 2
Source File: MiddleUseEntity.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
public static ServerBoundPacketData create(int entityId, Action action, Vector interactedAt, UsedHand hand, boolean sneaking) {
	ServerBoundPacketData useentity = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_USE_ENTITY);
	VarNumberSerializer.writeVarInt(useentity, entityId);
	MiscSerializer.writeVarIntEnum(useentity, action);
	switch (action) {
		case INTERACT: {
			MiscSerializer.writeVarIntEnum(useentity, hand);
			break;
		}
		case INTERACT_AT: {
			useentity.writeFloat((float) interactedAt.getX());
			useentity.writeFloat((float) interactedAt.getY());
			useentity.writeFloat((float) interactedAt.getZ());
			MiscSerializer.writeVarIntEnum(useentity, hand);
			break;
		}
		case ATTACK: {
			break;
		}
	}
	useentity.writeBoolean(sneaking);
	return useentity;
}
 
Example 3
Source File: SpawnObject.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeSpawnObject() {
	ClientBoundPacketData spawnobject = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_OBJECT);
	VarNumberSerializer.writeVarInt(spawnobject, entity.getId());
	UUIDSerializer.writeUUID2L(spawnobject, entity.getUUID());
	spawnobject.writeByte(LegacyEntityId.getObjectIntId(rType));
	spawnobject.writeDouble(x);
	spawnobject.writeDouble(y);
	spawnobject.writeDouble(z);
	spawnobject.writeByte(pitch);
	spawnobject.writeByte(yaw);
	spawnobject.writeInt(rObjectdata);
	spawnobject.writeShort(motX);
	spawnobject.writeShort(motY);
	spawnobject.writeShort(motZ);
	codec.write(spawnobject);
}
 
Example 4
Source File: WorldParticle.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	particle = remapper.getRemap(particle.getClass()).apply(particle);
	if (particle != null) {
		ClientBoundPacketData spawnparticle = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WORLD_PARTICLES);
		spawnparticle.writeInt(LegacyParticle.IntId.getId(particle));
		spawnparticle.writeBoolean(longdist);
		spawnparticle.writeFloat((float) x);
		spawnparticle.writeFloat((float) y);
		spawnparticle.writeFloat((float) z);
		spawnparticle.writeFloat(particle.getOffsetX());
		spawnparticle.writeFloat(particle.getOffsetY());
		spawnparticle.writeFloat(particle.getOffsetZ());
		spawnparticle.writeFloat(particle.getData());
		spawnparticle.writeInt(particle.getCount());
		for (int data : LegacyParticle.IntId.getData(particle)) {
			VarNumberSerializer.writeVarInt(spawnparticle, data);
		}
		codec.write(spawnparticle);
	}
}
 
Example 5
Source File: ChunkData.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData chunkdata = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHUNK_SINGLE);
	PositionSerializer.writeIntChunkCoord(chunkdata, coord);
	chunkdata.writeBoolean(full);
	VarNumberSerializer.writeVarInt(chunkdata, blockMask);
	ItemStackSerializer.writeDirectTag(chunkdata, HeightMapTransformer.transform(heightmaps));
	if (full) {
		for (int biome : biomes) {
			chunkdata.writeInt(biomeRemappingTable.getRemap(biome));
		}
	}
	ArraySerializer.writeVarIntByteArray(chunkdata, to -> {
		ChunkWriterVaries.writeSectionsCompact(
			to, blockMask, 14,
			blockDataRemappingTable,
			flatteningBlockDataTable,
			sections
		);
	});
	ArraySerializer.writeVarIntTArray(
		chunkdata,
		tiles,
		(to, tile) -> ItemStackSerializer.writeDirectTag(to, tileRemapper.remap(tile).getNBT())
	);
	codec.write(chunkdata);
}
 
Example 6
Source File: ChunkLight.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	int blockMask = ((setSkyLightMask | setBlockLightMask | emptySkyLightMask | emptyBlockLightMask) >> 1) & 0xFFFF;
	boolean hasSkyLight = cache.getClientCache().hasSkyLightInCurrentDimension();
	List<Collection<TileEntity>> resendTiles = new ArrayList<>();

	ClientBoundPacketData chunkdata = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHUNK_SINGLE);
	PositionSerializer.writeIntChunkCoord(chunkdata, coord);
	chunkdata.writeBoolean(false); //full
	VarNumberSerializer.writeVarInt(chunkdata, blockMask);
	ArraySerializer.writeVarIntByteArray(chunkdata, to -> {
		ChunkWriterVariesWithLight.writeSectionsCompactPreFlattening(
			to, blockMask, 13,
			blockDataRemappingTable,
			cachedChunk, hasSkyLight,
			sectionNumber -> resendTiles.add(cachedChunk.getTiles(sectionNumber).values())
		);
	});
	ArraySerializer.writeVarIntTArray(chunkdata, lTo -> {
		int count = 0;
		for (Collection<TileEntity> sectionTiles : resendTiles) {
			for (TileEntity tile : sectionTiles) {
				ItemStackSerializer.writeDirectTag(lTo, tile.getNBT());
			}
			count += sectionTiles.size();
		}
		return count;
	});
	codec.write(chunkdata);
}
 
Example 7
Source File: MiddleQueryBlockNBT.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToServer() {
	ServerBoundPacketData queryblocknbt = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_QUERY_BLOCK_NBT);
	VarNumberSerializer.writeVarInt(queryblocknbt, id);
	PositionSerializer.writePosition(queryblocknbt, position);
	codec.read(queryblocknbt);
}
 
Example 8
Source File: KeepAlive.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData keepalive = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_KEEP_ALIVE);
	if (version.isBeforeOrEq(ProtocolVersion.MINECRAFT_1_12_1)) {
		VarNumberSerializer.writeVarInt(keepalive, keepAliveId);
	} else {
		keepalive.writeLong(keepAliveId);
	}
	codec.write(keepalive);
}
 
Example 9
Source File: CollectEffect.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData collecteffect = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_COLLECT_EFFECT);
	VarNumberSerializer.writeVarInt(collecteffect, entityId);
	VarNumberSerializer.writeVarInt(collecteffect, collectorId);
	codec.write(collecteffect);
}
 
Example 10
Source File: Title.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	if (action != Action.SET_ACTION_BAR) {
		ClientBoundPacketData title = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_TITLE);
		int actionId = action.ordinal();
		VarNumberSerializer.writeVarInt(title, actionId > 2 ? actionId - 1 : actionId);
		switch (action) {
			case SET_TITLE:
			case SET_SUBTITLE: {
				StringSerializer.writeVarIntUTF8String(title, ChatAPI.toJSON(LegacyChatJson.convert(version, clientCache.getLocale(), message)));
				break;
			}
			case SET_TIMES: {
				title.writeInt(fadeIn);
				title.writeInt(stay);
				title.writeInt(fadeOut);
				break;
			}
			case HIDE:
			case RESET: {
				break;
			}
			default: {
				throw new EncoderException("Should not reach here");
			}
		}
		codec.write(title);
	} else {
		codec.write(Chat.create(MessagePosition.HOTBAR, LegacyChatJson.convert(version, clientCache.getLocale(), message)));
	}
}
 
Example 11
Source File: ChunkData.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData chunkdata = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHUNK_SINGLE);
	PositionSerializer.writeIntChunkCoord(chunkdata, coord);
	chunkdata.writeBoolean(full);
	VarNumberSerializer.writeVarInt(chunkdata, blockMask);
	boolean hasSkyLight = cache.getClientCache().hasSkyLightInCurrentDimension();
	ArraySerializer.writeVarIntByteArray(chunkdata, to -> {
		ChunkWriterVariesWithLight.writeSectionsCompactPreFlattening(
			to, blockMask, 13,
			blockDataRemappingTable,
			cachedChunk, hasSkyLight,
			sectionNumber -> {}
		);
		if (full) {
			int[] legacyBiomeData = LegacyBiomeData.toLegacyBiomeData(biomes);
			for (int biomeId : legacyBiomeData) {
				to.writeByte(biomeRemappingTable.getRemap(biomeId));
			}
		}
	});
	ArraySerializer.writeVarIntTArray(chunkdata, lTo -> {
		int count = 0;
		for (Map<Position, TileEntity> sectionTiles : cachedChunk.getTiles()) {
			for (TileEntity tile : sectionTiles.values()) {
				ItemStackSerializer.writeDirectTag(lTo, tile.getNBT());
			}
			count += sectionTiles.size();
		}
		return count;
	});
	codec.write(chunkdata);
}
 
Example 12
Source File: SpawnPainting.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData spawnpainting = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_PAINTING);
	VarNumberSerializer.writeVarInt(spawnpainting, entity.getId());
	UUIDSerializer.writeUUID2L(spawnpainting, entity.getUUID());
	VarNumberSerializer.writeVarInt(spawnpainting, type);
	PositionSerializer.writePosition(spawnpainting, position);
	spawnpainting.writeByte(direction);
	codec.write(spawnpainting);
}
 
Example 13
Source File: SpawnPainting.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	switch (direction) {
		case 0: {
			position.modifyZ(-1);
			break;
		}
		case 1: {
			position.modifyX(1);
			break;
		}
		case 2: {
			position.modifyZ(1);
			break;
		}
		case 3: {
			position.modifyX(-1);
			break;
		}
	}
	ClientBoundPacketData spawnpainting = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_PAINTING);
	VarNumberSerializer.writeVarInt(spawnpainting, entity.getId());
	StringSerializer.writeVarIntUTF8String(spawnpainting, LegacyPainting.getName(type));
	PositionSerializer.writeLegacyPositionI(spawnpainting, position);
	spawnpainting.writeInt(direction);
	codec.write(spawnpainting);
}
 
Example 14
Source File: EntityEquipment.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	String locale = clientCache.getLocale();

	ClientBoundPacketData entityequipment = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_ENTITY_EQUIPMENT);
	VarNumberSerializer.writeVarInt(entityequipment, entityId);
	int lastEntryIndex = entries.size() - 1;
	for (int entryIndex = 0; entryIndex <= lastEntryIndex; entryIndex++) {
		Entry entry = entries.get(entryIndex);
		entityequipment.writeByte(entry.getSlot().ordinal() | (entryIndex != lastEntryIndex ? Byte.MIN_VALUE : 0));
		ItemStackSerializer.writeItemStack(entityequipment, version, locale, entry.getItemStack());
	}
	codec.write(entityequipment);
}
 
Example 15
Source File: EntityRelMove.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData entityrelmove = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_ENTITY_REL_MOVE);
	VarNumberSerializer.writeVarInt(entityrelmove, entityId);
	entityrelmove.writeShort(relX);
	entityrelmove.writeShort(relY);
	entityrelmove.writeShort(relZ);
	entityrelmove.writeBoolean(onGround);
	codec.write(entityrelmove);
}
 
Example 16
Source File: EntityEquipment.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ClientBoundPacketData create(
	ProtocolVersion version, String locale,
	int entityId, Slot slot, NetworkItemStack itemstack
) {
	ClientBoundPacketData entityequipment = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_ENTITY_EQUIPMENT);
	VarNumberSerializer.writeVarInt(entityequipment, entityId);
	entityequipment.writeShort(getSlotId(slot));
	ItemStackSerializer.writeItemStack(entityequipment, version, locale, itemstack);
	return entityequipment;
}
 
Example 17
Source File: NetworkEntityMetadataObjectBlockData.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void writeToStream(ByteBuf to, ProtocolVersion version, String locale) {
	VarNumberSerializer.writeVarInt(to, value);
}
 
Example 18
Source File: NetworkEntityMetadataObjectParticle.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
public void writeToStream(ByteBuf to, ProtocolVersion version, String locale) {
	value = ParticleRemapper.REGISTRY.getTable(version).getRemap(value.getClass()).apply(value);
	VarNumberSerializer.writeVarInt(to, FlatteningParticleId.REGISTRY.getTable(version).getRemap(ParticleRegistry.getId(value)));
	ParticleDataSerializer.INSTANCE.get(version).write(to, value);
}
 
Example 19
Source File: ChunkWriterVariesWithLight.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static void writeSectionsCompactFlattening(
	ByteBuf buffer, int mask, int globalPaletteBitsPerBlock,
	IdRemappingTable blockDataRemappingTable,
	FlatteningBlockDataTable flatteningBlockDataTable,
	CachedChunk chunk, boolean hasSkyLight,
	IntConsumer sectionPresentConsumer
) {
	for (int sectionNumber = 0; sectionNumber < ChunkConstants.SECTION_COUNT_BLOCKS; sectionNumber++) {
		if (BitUtils.isIBitSet(mask, sectionNumber)) {
			CachedChunkSectionBlockStorage section = chunk.getBlocksSection(sectionNumber);

			if (section != null) {
				BlockStorage blockstorage = section.getBlockStorage();
				if (blockstorage instanceof BlockStorageBytePaletted) {
					BlockStorageBytePaletted blockstoragePaletted = (BlockStorageBytePaletted) blockstorage;
					buffer.writeByte(8);
					BlockStorageBytePaletted.Palette paletteObject = blockstoragePaletted.getPalette();
					short[] palette = paletteObject.getPalette();
					int paletteSize = Math.min(palette.length, paletteObject.getPaletteSize());
					VarNumberSerializer.writeVarInt(buffer, paletteSize);
					for (int i = 0; i < paletteSize; i++) {
						VarNumberSerializer.writeVarInt(buffer, BlockRemappingHelper.remapFlatteningBlockDataId(blockDataRemappingTable, flatteningBlockDataTable, palette[i]));
					}
					int blockdataLength = ChunkConstants.BLOCKS_IN_SECTION >> 3;
					VarNumberSerializer.writeVarInt(buffer, blockdataLength);
					for (int i = 0; i < blockdataLength; i++) {
						for (int j = 1; j <= Long.BYTES; j++) {
							buffer.writeByte(blockstoragePaletted.getRuntimeId((i << 3) + (Long.BYTES - j)));
						}
					}
				} else {
					buffer.writeByte(globalPaletteBitsPerBlock);
					VarNumberSerializer.writeVarInt(buffer, 0);
					NumberBitsStorageCompact writer = new NumberBitsStorageCompact(globalPaletteBitsPerBlock, ChunkConstants.BLOCKS_IN_SECTION);
					for (int blockIndex = 0; blockIndex < ChunkConstants.BLOCKS_IN_SECTION; blockIndex++) {
						writer.setNumber(blockIndex, BlockRemappingHelper.remapFlatteningBlockDataId(blockDataRemappingTable, flatteningBlockDataTable, section.getBlockData(blockIndex)));
					}
					ArraySerializer.writeVarIntLongArray(buffer, writer.getStorage());
				}
			} else {
				ChunkWriterUtils.writeBBEmptySection(buffer);
			}

			ChunkWriterUtils.writeBBLight(buffer, chunk.getBlockLight(sectionNumber));
			if (hasSkyLight) {
				ChunkWriterUtils.writeBBLight(buffer, chunk.getSkyLight(sectionNumber));
			}

			sectionPresentConsumer.accept(sectionNumber);
		}
	}
}
 
Example 20
Source File: MiddleTeleportAccept.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ServerBoundPacketData create(int teleportId) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_TELEPORT_ACCEPT);
	VarNumberSerializer.writeVarInt(creator, teleportId);
	return creator;
}