Last active
July 31, 2020 20:22
-
-
Save nickelpro/fd71d5baf8dba364ed9499dbeed43be5 to your computer and use it in GitHub Desktop.
Combat Event
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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