Java Code Examples for protocolsupport.protocol.serializer.ArraySerializer#writeVarIntTArray()

The following examples show how to use protocolsupport.protocol.serializer.ArraySerializer#writeVarIntTArray() . 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: Advancements.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
protected static void writeAdvanvement(ByteBuf to, ProtocolVersion version, String locale, Advancement advancement) {
	if (advancement.parentId != null) {
		to.writeBoolean(true);
		StringSerializer.writeVarIntUTF8String(to, advancement.parentId);
	} else {
		to.writeBoolean(false);
	}
	if (advancement.display != null) {
		to.writeBoolean(true);
		writeAdvancementDisplay(to, version, locale, advancement.display);
	} else {
		to.writeBoolean(false);
	}
	ArraySerializer.writeVarIntVarIntUTF8StringArray(to, advancement.criteria);
	ArraySerializer.writeVarIntTArray(to, advancement.requirements, ArraySerializer::writeVarIntVarIntUTF8StringArray);
}
 
Example 2
Source File: AbstractDeclareRecipes.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData declarerecipes = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_DECLARE_RECIPES);
	ArraySerializer.writeVarIntTArray(declarerecipes, to -> {
		int writtenRecipeCount = 0;
		for (Recipe recipe : recipes) {
			RecipeWriter<Recipe> writer = getRecipeWriter(recipe.getType());
			if (writer == null) {
				throw new IllegalArgumentException(MessageFormat.format("Missing recipe writer for recipe type {0}", recipe.getType()));
			}
			if (writer.writeRecipe(to, version, recipe)) {
				writtenRecipeCount++;
			}
		}
		return writtenRecipeCount;
	});
	codec.write(declarerecipes);
}
 
Example 3
Source File: UpdateMap.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData updatemap = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_UPDATE_MAP);
	VarNumberSerializer.writeVarInt(updatemap, id);
	updatemap.writeByte(scale);
	updatemap.writeBoolean(showIcons);
	ArraySerializer.writeVarIntTArray(updatemap, icons, (to, icon) -> {
		to.writeByte(((icon.type <= 9 ? icon.type : 0) << 4) | icon.direction);
		to.writeByte(icon.x);
		to.writeByte(icon.z);
	});
	updatemap.writeByte(columns);
	if (columns > 0) {
		ArrayBasedIdRemappingTable colorRemapper = MapColorRemapper.REMAPPER.getTable(version);
		for (int i = 0; i < colors.length; i++) {
			colors[i] = (byte) colorRemapper.getRemap(colors[i] & 0xFF);
		}
		updatemap.writeByte(rows);
		updatemap.writeByte(xstart);
		updatemap.writeByte(zstart);
		ArraySerializer.writeVarIntByteArray(updatemap, colors);
	}
	codec.write(updatemap);
}
 
Example 4
Source File: ScoreboardTeam.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData scoreboardteam = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SCOREBOARD_TEAM);
	StringSerializer.writeVarIntUTF8String(scoreboardteam, name);
	MiscSerializer.writeByteEnum(scoreboardteam, mode);
	if ((mode == Mode.CREATE) || (mode == Mode.UPDATE)) {
		StringSerializer.writeVarIntUTF8String(scoreboardteam, LegacyChat.clampLegacyText(displayName.toLegacyText(clientCache.getLocale()), 32));
		Any<String, String> nfix = formatPrefixSuffix();
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nfix.getObj1());
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nfix.getObj2());
		scoreboardteam.writeByte(friendlyFire);
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nameTagVisibility);
		scoreboardteam.writeByte(format.isColor() ? format.ordinal() : -1);
	}
	if ((mode == Mode.CREATE) || (mode == Mode.PLAYERS_ADD) || (mode == Mode.PLAYERS_REMOVE)) {
		ArraySerializer.writeVarIntTArray(scoreboardteam, players, (to, element) -> StringSerializer.writeVarIntUTF8String(to, Utils.clampString(element, 16)));
	}
	codec.write(scoreboardteam);
}
 
Example 5
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 6
Source File: BlockChangeMulti.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData blockchangemulti = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_BLOCK_CHANGE_MULTI);
	PositionSerializer.writeIntChunkCoord(blockchangemulti, chunkCoord);
	ArraySerializer.writeVarIntTArray(blockchangemulti, records, (to, record) -> {
		to.writeShort(record.coord);
		VarNumberSerializer.writeVarInt(to, BlockRemappingHelper.remapFlatteningBlockDataId(blockDataRemappingTable, flatteningBlockDataTable, record.id));
	});
	codec.write(blockchangemulti);
}
 
Example 7
Source File: Statistics.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData statisticsupdate = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_STATISTICS);
	ArraySerializer.writeVarIntTArray(statisticsupdate, statistics, (to, statistic) -> {
		VarNumberSerializer.writeVarInt(to, statistic.category);
		VarNumberSerializer.writeVarInt(to, statistic.id);
		VarNumberSerializer.writeVarInt(to, statistic.value);
	});
	codec.write(statisticsupdate);
}
 
Example 8
Source File: BlockChangeMulti.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData blockchangemulti = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_BLOCK_CHANGE_MULTI);
	PositionSerializer.writeIntChunkCoord(blockchangemulti, chunkCoord);
	ArraySerializer.writeVarIntTArray(blockchangemulti, records, (to, record) -> {
		to.writeShort(record.coord);
		VarNumberSerializer.writeVarInt(to, BlockRemappingHelper.remapFlatteningBlockDataId(blockDataRemappingTable, flatteningBlockDataTable, record.id));
	});
	codec.write(blockchangemulti);
}
 
Example 9
Source File: Advancements.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData advancements = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_ADVANCEMENTS);
	advancements.writeBoolean(reset);
	ArraySerializer.writeVarIntTArray(advancements, advancementsMapping, (to, element) -> {
		StringSerializer.writeVarIntUTF8String(to, element.getObj1());
		writeAdvanvement(to, version, cache.getClientCache().getLocale(), element.getObj2());
	});
	ArraySerializer.writeVarIntVarIntUTF8StringArray(advancements, removeAdvancements);
	ArraySerializer.writeVarIntTArray(advancements, advancementsProgress, (to, element) -> {
		StringSerializer.writeVarIntUTF8String(to, element.getObj1());
		wrtieAdvancementProgress(to, element.getObj2());
	});
	codec.write(advancements);
}
 
Example 10
Source File: UpdateMap.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData updatemap = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_UPDATE_MAP);
	VarNumberSerializer.writeVarInt(updatemap, id);
	updatemap.writeByte(scale);
	updatemap.writeBoolean(showIcons);
	ArraySerializer.writeVarIntTArray(updatemap, icons, (to, icon) -> {
		VarNumberSerializer.writeVarInt(to, icon.type);
		to.writeByte(icon.x);
		to.writeByte(icon.z);
		to.writeByte(icon.direction);
		to.writeBoolean(icon.displayName != null);
		if (icon.displayName != null) {
			StringSerializer.writeVarIntUTF8String(to, icon.displayName);
		}
	});
	updatemap.writeByte(columns);
	if (columns > 0) {
		ArrayBasedIdRemappingTable colorRemapper = MapColorRemapper.REMAPPER.getTable(version);
		for (int i = 0; i < colors.length; i++) {
			colors[i] = (byte) colorRemapper.getRemap(colors[i] & 0xFF);
		}
		updatemap.writeByte(rows);
		updatemap.writeByte(xstart);
		updatemap.writeByte(zstart);
		ArraySerializer.writeVarIntByteArray(updatemap, colors);
	}
	codec.write(updatemap);
}
 
Example 11
Source File: Advancements.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
protected void wrtieAdvancementProgress(ByteBuf to, AdvancementProgress obj2) {
	ArraySerializer.writeVarIntTArray(to, obj2.criterionsProgress, (lTo, element) -> {
		StringSerializer.writeVarIntUTF8String(lTo, element.getObj1());
		if (element.getObj2() != null) {
			lTo.writeBoolean(true);
			lTo.writeLong(element.getObj2());
		} else {
			lTo.writeBoolean(false);
		}
	});
}
 
Example 12
Source File: TabComplete.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	String prefix = start <= 1 ? "/" : "";
	ClientBoundPacketData serializer = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_TAB_COMPLETE);
	ArraySerializer.writeVarIntTArray(serializer, matches, (to, match) -> StringSerializer.writeVarIntUTF8String(to, prefix + match.getMatch()));
	codec.write(serializer);
}
 
Example 13
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));
	ArraySerializer.writeVarIntByteArray(chunkdata, to -> {
		ChunkWriterVaries.writeSectionsCompact(
			to, blockMask, 14,
			blockDataRemappingTable,
			flatteningBlockDataTable,
			sections
		);
		if (full) {
			int[] legacyBiomeData = LegacyBiomeData.toLegacyBiomeData(biomes);
			for (int biomeId : legacyBiomeData) {
				to.writeInt(biomeRemappingTable.getRemap(biomeId));
			}
		}
	});
	ArraySerializer.writeVarIntTArray(
		chunkdata,
		tiles,
		(to, tile) -> ItemStackSerializer.writeDirectTag(to, tileRemapper.remap(tile).getNBT())
	);
	codec.write(chunkdata);
}
 
Example 14
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);
	chunkdata.writeBoolean(useExistingLight);
	VarNumberSerializer.writeVarInt(chunkdata, blockMask);
	ItemStackSerializer.writeDirectTag(chunkdata, heightmaps);
	if (full) {
		for (int biome : biomes) {
			chunkdata.writeInt(biomeRemappingTable.getRemap(biome));
		}
	}
	ArraySerializer.writeVarIntByteArray(chunkdata, to -> {
		ChunkWriterVaries.writeSectionsPadded(
			to, blockMask, 14,
			blockDataRemappingTable,
			flatteningBlockDataTable,
			sections
		);
	});
	ArraySerializer.writeVarIntTArray(
		chunkdata,
		tiles,
		(to, tile) -> ItemStackSerializer.writeDirectTag(to, tileRemapper.remap(tile).getNBT())
	);
	codec.write(chunkdata);
}
 
Example 15
Source File: SpawnNamed.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData spawnnamed = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_SPAWN_NAMED);
	VarNumberSerializer.writeVarInt(spawnnamed, entity.getId());
	UUID uuid = entity.getUUID();
	StringSerializer.writeVarIntUTF8String(spawnnamed, version == ProtocolVersion.MINECRAFT_1_7_10 ? uuid.toString() : uuid.toString().replace("-", ""));
	PlayerListEntry entry = playerlistCache.getEntry(uuid);
	if (entry != null) {
		StringSerializer.writeVarIntUTF8String(spawnnamed, Utils.clampString(entry.getUserName(), 16));
		if (version == ProtocolVersion.MINECRAFT_1_7_10) {
			ArraySerializer.writeVarIntTArray(spawnnamed, entry.getProperties(true), (to, property) -> {
				StringSerializer.writeVarIntUTF8String(to, property.getName());
				StringSerializer.writeVarIntUTF8String(to, property.getValue());
				StringSerializer.writeVarIntUTF8String(to, property.getSignature());
			});
		}
	} else {
		StringSerializer.writeVarIntUTF8String(spawnnamed, "UNKNOWN");
		if (version == ProtocolVersion.MINECRAFT_1_7_10) {
			VarNumberSerializer.writeVarInt(spawnnamed, 0);
		}
	}
	spawnnamed.writeInt((int) (x * 32));
	spawnnamed.writeInt((int) (y * 32));
	spawnnamed.writeInt((int) (z * 32));
	spawnnamed.writeByte(yaw);
	spawnnamed.writeByte(pitch);
	spawnnamed.writeShort(0);
	NetworkEntityMetadataSerializer.writeLegacyData(spawnnamed, version, I18NData.DEFAULT_LOCALE, NetworkEntityMetadataList.EMPTY);
	codec.write(spawnnamed);
}
 
Example 16
Source File: TabComplete.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData tabcomplete = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_TAB_COMPLETE);
	VarNumberSerializer.writeVarInt(tabcomplete, id);
	VarNumberSerializer.writeVarInt(tabcomplete, start);
	VarNumberSerializer.writeVarInt(tabcomplete, length);
	ArraySerializer.writeVarIntTArray(tabcomplete, matches, (to, match) -> {
		StringSerializer.writeVarIntUTF8String(to, match.getMatch());
		to.writeBoolean(match.hasTooltip());
		if (match.hasTooltip()) {
			StringSerializer.writeVarIntUTF8String(to, match.getTooltip());
		}
	});
	codec.write(tabcomplete);
}
 
Example 17
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 18
Source File: UpdateMap.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData updatemap = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_UPDATE_MAP);
	VarNumberSerializer.writeVarInt(updatemap, id);
	updatemap.writeByte(scale);
	updatemap.writeBoolean(showIcons);
	updatemap.writeBoolean(locked);
	ArraySerializer.writeVarIntTArray(updatemap, icons, (to, icon) -> {
		VarNumberSerializer.writeVarInt(to, icon.type);
		to.writeByte(icon.x);
		to.writeByte(icon.z);
		to.writeByte(icon.direction);
		to.writeBoolean(icon.displayName != null);
		if (icon.displayName != null) {
			StringSerializer.writeVarIntUTF8String(to, icon.displayName);
		}
	});
	updatemap.writeByte(columns);
	if (columns > 0) {
		ArrayBasedIdRemappingTable colorRemapper = MapColorRemapper.REMAPPER.getTable(version);
		for (int i = 0; i < colors.length; i++) {
			colors[i] = (byte) colorRemapper.getRemap(colors[i] & 0xFF);
		}
		updatemap.writeByte(rows);
		updatemap.writeByte(xstart);
		updatemap.writeByte(zstart);
		ArraySerializer.writeVarIntByteArray(updatemap, colors);
	}
	codec.write(updatemap);
}
 
Example 19
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.writeSectionsCompactFlattening(
			to, blockMask, 14,
			blockDataRemappingTable, flatteningBlockDataTable,
			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 20
Source File: AbstractDeclareRecipes.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void writeRecipeData(ByteBuf to, ProtocolVersion version, ShapelessRecipe recipe) {
	StringSerializer.writeVarIntUTF8String(to, recipe.getGroup());
	ArraySerializer.writeVarIntTArray(to, recipe.getIngredients(), (lTo, ingredient) -> writeIngredient(lTo, version, ingredient));
	ItemStackSerializer.writeItemStack(to, version, I18NData.DEFAULT_LOCALE, recipe.getResult());
}