Java Code Examples for protocolsupport.protocol.serializer.MiscSerializer#writeVarIntEnum()

The following examples show how to use protocolsupport.protocol.serializer.MiscSerializer#writeVarIntEnum() . 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: 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 2
Source File: MiddleRecipeBookData.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToServer() {
	ServerBoundPacketData recipebookdata = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_RECIPE_BOOK_DATA);
	MiscSerializer.writeVarIntEnum(recipebookdata, type);
	switch (type) {
		case DISPLAYED_RECIPE: {
			StringSerializer.writeVarIntUTF8String(recipebookdata, recipeId);
			break;
		}
		case RECIPE_BOOK_STATUS: {
			recipebookdata.writeBoolean(craftRecipeBookOpen);
			recipebookdata.writeBoolean(craftRecipeBookFiltering);
			recipebookdata.writeBoolean(smeltingRecipeBookOpen);
			recipebookdata.writeBoolean(smeltingRecipeBookFiltering);
			recipebookdata.writeBoolean(blastingRecipeBookOpen);
			recipebookdata.writeBoolean(blastingRecipeBookFiltering);
			recipebookdata.writeBoolean(smokingRecipeBookOpen);
			recipebookdata.writeBoolean(smokingRecipeBookFiltering);
			break;
		}
	}
	codec.read(recipebookdata);
}
 
Example 3
Source File: CombatEvent.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData combatevent = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_COMBAT_EVENT);
	MiscSerializer.writeVarIntEnum(combatevent, type);
	switch (type) {
		case ENTER_COMBAT: {
			break;
		}
		case END_COMBAT: {
			VarNumberSerializer.writeVarInt(combatevent, duration);
			combatevent.writeInt(entityId);
			break;
		}
		case ENTITY_DEAD: {
			VarNumberSerializer.writeVarInt(combatevent, playerId);
			combatevent.writeInt(entityId);
			StringSerializer.writeVarIntUTF8String(combatevent, message);
			break;
		}
	}
}
 
Example 4
Source File: MiddleUpdateStructureBlock.java    From ProtocolSupport with GNU Affero General Public License v3.0 6 votes vote down vote up
public static ServerBoundPacketData create(Position position, Action action, Mode mode, String name,
	byte offsetX, byte offsetY, byte offsetZ, byte sizeX, byte sizeY, byte sizeZ,
	Mirror mirror, Rotation rotation, String metadata, float integrity, long seed, byte flags
) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_UPDATE_STRUCTURE_BLOCK);
	PositionSerializer.writePosition(creator, position);
	MiscSerializer.writeVarIntEnum(creator, action);
	MiscSerializer.writeVarIntEnum(creator, mode);
	StringSerializer.writeVarIntUTF8String(creator, name);
	creator.writeByte(offsetX);
	creator.writeByte(offsetY);
	creator.writeByte(offsetZ);
	creator.writeByte(sizeX);
	creator.writeByte(sizeY);
	creator.writeByte(sizeZ);
	MiscSerializer.writeVarIntEnum(creator, mirror);
	MiscSerializer.writeVarIntEnum(creator, rotation);
	StringSerializer.writeVarIntUTF8String(creator, metadata);
	creator.writeFloat(integrity);
	VarNumberSerializer.writeVarLong(creator, seed);
	creator.writeByte(flags);
	return creator;
}
 
Example 5
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 6
Source File: MiddleEntityAction.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ServerBoundPacketData create(int entityId, Action action, int jumpBoost) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_ENTITY_ACTION);
	VarNumberSerializer.writeVarInt(creator, entityId);
	MiscSerializer.writeVarIntEnum(creator, action);
	VarNumberSerializer.writeVarInt(creator, jumpBoost);
	return creator;
}
 
Example 7
Source File: MiddleBlockDig.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ServerBoundPacketData create(Action status, Position position, int face) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_BLOCK_DIG);
	MiscSerializer.writeVarIntEnum(creator, status);
	PositionSerializer.writePosition(creator, position);
	creator.writeByte(face);
	return creator;
}
 
Example 8
Source File: MiddleClientSettings.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ServerBoundPacketData create(String locale, int viewDist, ChatMode chatMode, boolean chatColors, int skinFlags, MainHand mainHand) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_SETTINGS);
	StringSerializer.writeVarIntUTF8String(creator, locale);
	creator.writeByte(viewDist);
	MiscSerializer.writeVarIntEnum(creator, chatMode);
	creator.writeBoolean(chatColors);
	creator.writeByte(skinFlags);
	MiscSerializer.writeVarIntEnum(creator, mainHand);
	return creator;
}
 
Example 9
Source File: UnlockRecipes.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData unlockrecipes = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_UNLOCK_RECIPES);
	MiscSerializer.writeVarIntEnum(unlockrecipes, action);
	unlockrecipes.writeBoolean(craftRecipeBookOpen);
	unlockrecipes.writeBoolean(craftRecipeBookFiltering);
	unlockrecipes.writeBoolean(smeltingRecipeBookOpen);
	unlockrecipes.writeBoolean(smeltingRecipeBookFiltering);
	ArraySerializer.writeVarIntVarIntUTF8StringArray(unlockrecipes, recipes1);
	if (action == Action.INIT) {
		ArraySerializer.writeVarIntVarIntUTF8StringArray(unlockrecipes, recipes2);
	}
	codec.write(unlockrecipes);
}
 
Example 10
Source File: MiddleUpdateCommandBlock.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ServerBoundPacketData create(Position position, String command, Mode mode, int flags) {
	ServerBoundPacketData creator = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_UPDATE_COMMAND_BLOCK);
	PositionSerializer.writePosition(creator, position);
	StringSerializer.writeVarIntUTF8String(creator, command);
	MiscSerializer.writeVarIntEnum(creator, mode);
	creator.writeByte(flags);
	return creator;
}
 
Example 11
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);
	MiscSerializer.writeVarIntEnum(entityequipment, slot);
	ItemStackSerializer.writeItemStack(entityequipment, version, locale, itemstack);
	return entityequipment;
}
 
Example 12
Source File: InventoryOpen.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient0() {
	ClientBoundPacketData windowopen = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WINDOW_OPEN);
	VarNumberSerializer.writeVarInt(windowopen, windowId);
	MiscSerializer.writeVarIntEnum(windowopen, windowRemapper.toClientWindowType(type));
	StringSerializer.writeVarIntUTF8String(windowopen, ChatAPI.toJSON(LegacyChatJson.convert(version, clientCache.getLocale(), title)));
	codec.write(windowopen);
}
 
Example 13
Source File: WorldCustomSound.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ClientBoundPacketData create(
	ProtocolVersion version,
	int x, int y, int z,
	String sound, SoundCategory category, float volume, float pitch
) {
	ClientBoundPacketData worldcustomsound = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WORLD_CUSTOM_SOUND);
	StringSerializer.writeVarIntUTF8String(worldcustomsound, SoundRemapper.getSoundName(version, sound));
	MiscSerializer.writeVarIntEnum(worldcustomsound, category);
	worldcustomsound.writeInt(x);
	worldcustomsound.writeInt(y);
	worldcustomsound.writeInt(z);
	worldcustomsound.writeFloat(volume);
	worldcustomsound.writeFloat(pitch);
	return worldcustomsound;
}
 
Example 14
Source File: Advancements.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
protected static void writeAdvancementDisplay(ByteBuf to, ProtocolVersion version, String locale, AdvancementDisplay display) {
	StringSerializer.writeVarIntUTF8String(to, ChatAPI.toJSON(LegacyChatJson.convert(version, locale, display.title)));
	StringSerializer.writeVarIntUTF8String(to, ChatAPI.toJSON(LegacyChatJson.convert(version, locale, display.description)));
	ItemStackSerializer.writeItemStack(to, version, locale, display.icon);
	MiscSerializer.writeVarIntEnum(to, display.frametype);
	to.writeInt(display.flags);
	if ((display.flags & AdvancementDisplay.flagHasBackgroundOffset) != 0) {
		StringSerializer.writeVarIntUTF8String(to, display.background);
	}
	to.writeFloat(display.x);
	to.writeFloat(display.y);
}
 
Example 15
Source File: WorldCustomSound.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
public static ClientBoundPacketData create(
	ProtocolVersion version,
	int x, int y, int z,
	String sound, SoundCategory category, float volume, float pitch
) {
	ClientBoundPacketData worldcustomsound = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_WORLD_CUSTOM_SOUND);
	StringSerializer.writeVarIntUTF8String(worldcustomsound, SoundRemapper.getSoundName(version, sound));
	MiscSerializer.writeVarIntEnum(worldcustomsound, category);
	worldcustomsound.writeInt(x);
	worldcustomsound.writeInt(y);
	worldcustomsound.writeInt(z);
	worldcustomsound.writeFloat(volume);
	worldcustomsound.writeByte((int) (pitch * 63.5));
	return worldcustomsound;
}
 
Example 16
Source File: BossBar.java    From ProtocolSupport with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData bossbar = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_BOSS_BAR);
	UUIDSerializer.writeUUID2L(bossbar, uuid);
	MiscSerializer.writeVarIntEnum(bossbar, action);
	switch (action) {
		case ADD: {
			StringSerializer.writeVarIntUTF8String(bossbar, ChatAPI.toJSON(LegacyChatJson.convert(version, cache.getClientCache().getLocale(), title)));
			bossbar.writeFloat(percent);
			VarNumberSerializer.writeVarInt(bossbar, color);
			VarNumberSerializer.writeVarInt(bossbar, divider);
			bossbar.writeByte(flags);
			break;
		}
		case REMOVE: {
			break;
		}
		case UPDATE_PERCENT: {
			bossbar.writeFloat(percent);
			break;
		}
		case UPDATE_TITLE: {
			StringSerializer.writeVarIntUTF8String(bossbar, ChatAPI.toJSON(LegacyChatJson.convert(version, cache.getClientCache().getLocale(), title)));
			break;
		}
		case UPDATE_STYLE: {
			VarNumberSerializer.writeVarInt(bossbar, color);
			VarNumberSerializer.writeVarInt(bossbar, divider);
			break;
		}
		case UPDATE_FLAGS: {
			bossbar.writeByte(flags);
			break;
		}
	}
	codec.write(bossbar);
}
 
Example 17
Source File: MiddleClientCommand.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
public static ServerBoundPacketData create(Command command) {
	ServerBoundPacketData clientcommand = ServerBoundPacketData.create(PacketType.SERVERBOUND_PLAY_CLIENT_COMMAND);
	MiscSerializer.writeVarIntEnum(clientcommand, command);
	return clientcommand;
}
 
Example 18
Source File: NetworkEntityMetadataObjectEntityPose.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) {
	MiscSerializer.writeVarIntEnum(to, value);
}
 
Example 19
Source File: BookOpen.java    From ProtocolSupport with GNU Affero General Public License v3.0 4 votes vote down vote up
@Override
protected void writeToClient() {
	ClientBoundPacketData bookopen = ClientBoundPacketData.create(PacketType.CLIENTBOUND_PLAY_BOOK_OPEN);
	MiscSerializer.writeVarIntEnum(bookopen, hand);
	codec.write(bookopen);
}
 
Example 20
Source File: NetworkEntityMetadataObjectDirection.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) {
	MiscSerializer.writeVarIntEnum(to, value);
}