Skip to content

Instantly share code, notes, and snippets.

@nickelpro
Last active July 31, 2020 20:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickelpro/fd71d5baf8dba364ed9499dbeed43be5 to your computer and use it in GitHub Desktop.
Save nickelpro/fd71d5baf8dba364ed9499dbeed43be5 to your computer and use it in GitHub Desktop.
Combat Event
class ClientboundCombatEvent : public Packet {
public:
std::int64_t event;
std::int64_t duration;
std::int64_t playerId;
std::int32_t entityId;
std::string message;
ClientboundCombatEvent();
void encode(std::ostream &dest);
void decode(std::istream &src);
};
void ClientboundCombatEvent::encode(std::ostream &dest) {
enc_varint(dest, event);
switch(event) {
case 1:
enc_varint(dest, duration);
enc_be32(dest, entityId);
break;
case 2:
enc_varint(dest, playerId);
enc_be32(dest, entityId);
enc_string(dest, message);
break;
}
}
void ClientboundCombatEvent::decode(std::istream &src) {
event = dec_varint(src);
switch(event) {
case 1:
duration = dec_varint(src);
entityId = dec_be32(src);
break;
case 2:
playerId = dec_varint(src);
entityId = dec_be32(src);
message = dec_string(src);
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment