protocolsupport.protocol.serializer.ArraySerializer Java Examples

The following examples show how to use protocolsupport.protocol.serializer.ArraySerializer. 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: MiddleChunkLight.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void readServerData(ByteBuf serverdata) {
	coord = PositionSerializer.readVarIntChunkCoord(serverdata);
	trustEdges = serverdata.readBoolean();

	setSkyLightMask = VarNumberSerializer.readVarInt(serverdata);
	setBlockLightMask = VarNumberSerializer.readVarInt(serverdata);
	emptySkyLightMask = VarNumberSerializer.readVarInt(serverdata);
	emptyBlockLightMask = VarNumberSerializer.readVarInt(serverdata);

	for (int sectionNumber = 0; sectionNumber < ChunkConstants.SECTION_COUNT_LIGHT; sectionNumber++) {
		skyLight[sectionNumber] = BitUtils.isIBitSet(setSkyLightMask, sectionNumber) ? ArraySerializer.readVarIntByteArray(serverdata) : null;
	}
	for (int sectionNumber = 0; sectionNumber < ChunkConstants.SECTION_COUNT_LIGHT; sectionNumber++) {
		blockLight[sectionNumber] = BitUtils.isIBitSet(setBlockLightMask, sectionNumber) ? ArraySerializer.readVarIntByteArray(serverdata) : null;
	}
}
 
Example #3
Source File: MiddleStartGame.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void readServerData(ByteBuf serverdata) {
	player = NetworkEntity.createPlayer(serverdata.readInt());
	int gmdata = serverdata.readByte();
	gamemodeCurrent = GameMode.getById(gmdata & 0xFFFFFFF7);
	hardcore = (gmdata & 0x8) == 0x8;
	gamemodePrevious = GameMode.getById(serverdata.readByte());
	worlds = ArraySerializer.readVarIntVarIntUTF8StringArray(serverdata);
	dimensions = ItemStackSerializer.readDirectTag(serverdata);
	dimension = StringSerializer.readVarIntUTF8String(serverdata);
	world = StringSerializer.readVarIntUTF8String(serverdata);
	hashedSeed = serverdata.readLong();
	serverdata.readByte();
	maxplayers = TabAPI.getMaxTabSize();
	renderDistance = VarNumberSerializer.readVarInt(serverdata);
	reducedDebugInfo = serverdata.readBoolean();
	respawnScreenEnabled = serverdata.readBoolean();
	worldDebug = serverdata.readBoolean();
	worldFlat = serverdata.readBoolean();
}
 
Example #4
Source File: MiddleChunkData.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void readServerData(ByteBuf serverdata) {
	coord = PositionSerializer.readIntChunkCoord(serverdata);
	full = serverdata.readBoolean();
	useExistingLight = serverdata.readBoolean();

	blockMask = VarNumberSerializer.readVarInt(serverdata);
	heightmaps = ItemStackSerializer.readDirectTag(serverdata);
	if (full) {
		for (int i = 0; i < biomes.length; i++) {
			biomes[i] = serverdata.readInt();
		}
	}

	{
		ByteBuf chunkdata = ArraySerializer.readVarIntByteArraySlice(serverdata);
		for (int sectionNumber = 0; sectionNumber < ChunkConstants.SECTION_COUNT_BLOCKS; sectionNumber++) {
			if (BitUtils.isIBitSet(blockMask, sectionNumber)) {
				sections[sectionNumber] = ChunkSectonBlockData.readFromStream(chunkdata);
			}
		}
	}

	tiles = ArraySerializer.readVarIntTArray(serverdata, TileEntity.class, from -> new TileEntity(ItemStackSerializer.readDirectTag(serverdata)));
}
 
Example #5
Source File: MiddleUpdateMap.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void readServerData(ByteBuf serverdata) {
	id = VarNumberSerializer.readVarInt(serverdata);
	scale = serverdata.readUnsignedByte();
	showIcons = serverdata.readBoolean();
	locked = serverdata.readBoolean();
	icons = ArraySerializer.readVarIntTArray(
		serverdata, Icon.class,
		from -> new Icon(
			VarNumberSerializer.readVarInt(from),
			from.readUnsignedByte(),
			from.readUnsignedByte(),
			from.readByte(),
			from.readBoolean() ? StringSerializer.readVarIntUTF8String(serverdata) : null
		)
	);
	columns = serverdata.readUnsignedByte();
	if (columns > 0) {
		rows = serverdata.readUnsignedByte();
		xstart = serverdata.readUnsignedByte();
		zstart = serverdata.readUnsignedByte();
		colors = ArraySerializer.readVarIntByteArray(serverdata);
	}
}
 
Example #6
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 #7
Source File: ScoreboardTeam.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	String locale = clientCache.getLocale();

	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, ChatAPI.toJSON(LegacyChatJson.convert(version, locale, displayName)));
		scoreboardteam.writeByte(friendlyFire);
		StringSerializer.writeVarIntUTF8String(scoreboardteam, nameTagVisibility);
		StringSerializer.writeVarIntUTF8String(scoreboardteam, collisionRule);
		MiscSerializer.writeVarIntEnum(scoreboardteam, format);
		StringSerializer.writeVarIntUTF8String(scoreboardteam, ChatAPI.toJSON(LegacyChatJson.convert(version, locale, prefix)));
		StringSerializer.writeVarIntUTF8String(scoreboardteam, ChatAPI.toJSON(LegacyChatJson.convert(version, locale, suffix)));
	}
	if ((mode == Mode.CREATE) || (mode == Mode.PLAYERS_ADD) || (mode == Mode.PLAYERS_REMOVE)) {
		ArraySerializer.writeVarIntVarIntUTF8StringArray(scoreboardteam, players);
	}
	codec.write(scoreboardteam);
}
 
Example #8
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.writeString(scoreboardteam, version, name);
	MiscSerializer.writeByteEnum(scoreboardteam, mode);
	if ((mode == Mode.CREATE) || (mode == Mode.UPDATE)) {
		StringSerializer.writeString(scoreboardteam, version, LegacyChat.clampLegacyText(displayName.toLegacyText(clientCache.getLocale()), 32));
		Any<String, String> nfix = formatPrefixSuffix();
		StringSerializer.writeString(scoreboardteam, version, nfix.getObj1());
		StringSerializer.writeString(scoreboardteam, version, nfix.getObj2());
		scoreboardteam.writeByte(friendlyFire);
	}
	if ((mode == Mode.CREATE) || (mode == Mode.PLAYERS_ADD) || (mode == Mode.PLAYERS_REMOVE)) {
		ArraySerializer.writeShortTArray(scoreboardteam, players, (to, element) -> StringSerializer.writeString(to, version, Utils.clampString(element, 16)));
	}
	codec.write(scoreboardteam);
}
 
Example #9
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);
	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 #10
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 #11
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);
	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 #12
Source File: ChunkLight.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	int blockMask = ((setSkyLightMask | setBlockLightMask | emptySkyLightMask | emptyBlockLightMask) >> 1) & 0xFFFF;
	boolean hasSkyLight = cache.getClientCache().hasSkyLightInCurrentDimension();

	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 ->
				cachedChunk.getTiles(sectionNumber).values()
				.forEach(tile -> blocktileupdates.add(BlockTileUpdate.create(version, tile)))
		);
	});

	codec.write(chunkdata);
	for (ClientBoundPacketData blocktileupdate : blocktileupdates) {
		codec.write(blocktileupdate);
	}
}
 
Example #13
Source File: StartGame.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData startgame = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_START_GAME);
	startgame.writeInt(player.getId());
	startgame.writeByte(gamemodeCurrent.getId() | (hardcore ? 0x8 : 0));
	startgame.writeByte(gamemodePrevious.getId());
	ArraySerializer.writeVarIntVarIntUTF8StringArray(startgame, worlds);
	ItemStackSerializer.writeDirectTag(startgame, dimensions);
	StringSerializer.writeVarIntUTF8String(startgame, dimension);
	StringSerializer.writeVarIntUTF8String(startgame, world);
	startgame.writeLong(hashedSeed);
	startgame.writeByte(maxplayers);
	VarNumberSerializer.writeVarInt(startgame, renderDistance);
	startgame.writeBoolean(reducedDebugInfo);
	startgame.writeBoolean(respawnScreenEnabled);
	startgame.writeBoolean(worldDebug);
	startgame.writeBoolean(worldFlat);
	codec.write(startgame);
}
 
Example #14
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 #15
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 #16
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);
		StringSerializer.writeVarIntUTF8String(scoreboardteam, collisionRule);
		scoreboardteam.writeByte(format.isColor() ? format.ordinal() : -1);
	}
	if ((mode == Mode.CREATE) || (mode == Mode.PLAYERS_ADD) || (mode == Mode.PLAYERS_REMOVE)) {
		ArraySerializer.writeVarIntVarIntUTF8StringArray(scoreboardteam, players);
	}
	codec.write(scoreboardteam);
}
 
Example #17
Source File: ChunkLight.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	int blockMask = ((setSkyLightMask | setBlockLightMask | emptySkyLightMask | emptyBlockLightMask) >> 1) & 0xFFFF;
	boolean hasSkyLight = cache.getClientCache().hasSkyLightInCurrentDimension();

	ClientBoundPacketData chunkdata = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CHUNK_SINGLE);
	PositionSerializer.writeIntChunkCoord(chunkdata, coord);
	chunkdata.writeBoolean(false); //full
	chunkdata.writeShort(blockMask);
	ArraySerializer.writeVarIntByteArray(chunkdata, ChunkWriterShort.serializeSections(
		blockMask, blockDataRemappingTable, cachedChunk, hasSkyLight,
		sectionNumber -> cachedChunk.getTiles(sectionNumber).values().forEach(tile -> blocktileupdates.add(BlockTileUpdate.create(version, tile)))
	));

	codec.write(chunkdata);
	for (ClientBoundPacketData blocktileupdate : blocktileupdates) {
		codec.write(blocktileupdate);
	}
}
 
Example #18
Source File: MiddleTabComplete.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void readServerData(ByteBuf serverdata) {
	id = VarNumberSerializer.readVarInt(serverdata);
	start = VarNumberSerializer.readVarInt(serverdata);
	length = VarNumberSerializer.readVarInt(serverdata);
	matches = ArraySerializer.readVarIntTArray(serverdata, CommandMatch.class, data -> {
		String match = StringSerializer.readVarIntUTF8String(serverdata);
		String tooltip = serverdata.readBoolean() ? StringSerializer.readVarIntUTF8String(serverdata) : null;
		return new CommandMatch(match, tooltip);
	});
}
 
Example #19
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 #20
Source File: MiddleUnlockRecipes.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void readServerData(ByteBuf serverdata) {
	action = MiscSerializer.readVarIntEnum(serverdata, Action.CONSTANT_LOOKUP);
	craftRecipeBookOpen = serverdata.readBoolean();
	craftRecipeBookFiltering = serverdata.readBoolean();
	smeltingRecipeBookOpen = serverdata.readBoolean();
	smeltingRecipeBookFiltering = serverdata.readBoolean();
	recipes1 = ArraySerializer.readVarIntVarIntUTF8StringArray(serverdata);
	if (action == Action.INIT) {
		recipes2 = ArraySerializer.readVarIntVarIntUTF8StringArray(serverdata);
	}
}
 
Example #21
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 #22
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 #23
Source File: ResourcePack.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData resourcepack = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_CUSTOM_PAYLOAD);
	StringSerializer.writeVarIntUTF8String(resourcepack, "MC|RPack");
	ArraySerializer.writeShortByteArray(resourcepack, to -> ByteBufUtil.writeUtf8(to, url));
	codec.write(resourcepack);
}
 
Example #24
Source File: MiddleBlockChangeMulti.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void readServerData(ByteBuf serverdata) {
	chunkCoord = PositionSerializer.readIntChunkCoord(serverdata);
	records = ArraySerializer.readVarIntTArray(
		serverdata,
		Record.class,
		from -> new Record(serverdata.readUnsignedShort(), VarNumberSerializer.readVarInt(from))
	);
}
 
Example #25
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 #26
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 #27
Source File: MiddleAdvancements.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
protected void readServerData(ByteBuf serverdata) {
	reset = serverdata.readBoolean();
	advancementsMapping = ArraySerializer.readVarIntTArray(
		serverdata, Any.class,
		buf -> new Any<>(StringSerializer.readVarIntUTF8String(buf), Advancement.read(buf))
	);
	removeAdvancements = ArraySerializer.readVarIntVarIntUTF8StringArray(serverdata);
	advancementsProgress = ArraySerializer.readVarIntTArray(
		serverdata, Any.class,
		buf -> new Any<>(StringSerializer.readVarIntUTF8String(buf), AdvancementProgress.read(buf))
	);
}
 
Example #28
Source File: SkinPacket.java    From ProtocolSupportPocketStuff with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public void toData(ConnectionImpl connection, ByteBuf serializer) {
	ProtocolVersion version = connection.getVersion();
	MiscSerializer.writePEUUID(serializer, uuid);
	StringSerializer.writeString(serializer, version, skinId);
	StringSerializer.writeString(serializer, version, skinName);
	StringSerializer.writeString(serializer, version, previousName);
	ArraySerializer.writeVarIntByteArray(serializer, skinData);
	ArraySerializer.writeVarIntByteArray(serializer, capeData);
	StringSerializer.writeString(serializer, version, geometryId);
	StringSerializer.writeString(serializer, version, geometryData);
	serializer.writeBoolean(false); //premium skin
}
 
Example #29
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 #30
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);
}