Add Cake #81

Merged
TheBrokenRail merged 22 commits from bigjango13/minecraft-pi-reborn:master into master 2024-02-07 06:47:47 +00:00
1 changed files with 26 additions and 36 deletions
Showing only changes of commit 19dd4b1d79 - Show all commits

View File

@ -11,63 +11,53 @@ static const char *monster_names[] = {"Zombie", "Creeper", "Skeleton", "Spider",
static std::string get_death_message(Player *player, Entity *cause, bool was_shot = false) {
// Prepare Death Message
std::string message = player->username;
// The cause
if (cause) {
// Entity cause
int type_id = cause->vtable->getEntityTypeId(cause);
int aux = cause->vtable->getAuxData(cause);
if (cause->vtable->isPlayer(cause)) {
// Another player
bool is_player = cause->vtable->isPlayer(cause);
if (cause->vtable->getCreatureBaseType(cause) != 0 || is_player) {
// Killed by a creature
if (was_shot) {
message += " was shot by ";
} else {
message += " was killed by ";
}
message += ((Player *) cause)->username;
} else if (cause->vtable->getCreatureBaseType(cause) == 1) {
// Killed by a monster
if (was_shot) {
message += " was shot by a ";
} else {
message += " was killed by a ";
}
if (32 <= type_id && type_id <= 36) {
if (is_player) {
// Killed by a player
message += ((Player *) cause)->username;
} else if (32 <= type_id && type_id <= 36) {
// Normal monster
message += "a ";
message += monster_names[type_id - 32];
} else {
// Unknown monster
message += "Mysterious Beast";
// Unknown creature
message += "a Mysterious Beast";
}
return message;
} else if (aux) {
// Throwable with owner
// Killed by a throwable with owner
Level *level = player->level;
Entity *shooter = Level_getEntity(level, aux);
return get_death_message(player, shooter, true);
} else if (80 <= type_id || type_id <= 82) {
// Throwable without owner
message += " was shot under mysterious circumstances";
} else if (type_id == 65) {
bigjango13 marked this conversation as resolved
Review

Shouldn't this check if this was an arrow? What if another entity has aux data?

Shouldn't this check if this was an arrow? What if another entity has aux data?
Review

That's intended, only throwables have aux values:

// The owner entity id for arrows/throwables, else 0
virtual-method int getAuxData() = 0xf4;

So if I egg you to death, it still says that I'm the one who did it.

That's intended, only throwables have aux values: ``` // The owner entity id for arrows/throwables, else 0 virtual-method int getAuxData() = 0xf4; ``` So if I egg you to death, it still says that I'm the one who did it.
// TNT
message += " was blown apart";
// Blown up by TNT
return message + " was blown apart";
} else if (cause->vtable->isHangingEntity(cause)) {
// Painting?
message += " admired too much art";
} else {
if (was_shot) {
message += " was shot under mysterious circumstances";
} else {
message += " was killed under mysterious circumstances";
}
return message + " admired too much art";
bigjango13 marked this conversation as resolved Outdated

A lot of these death messages are duplicated. Is there any chance these could be consolidated into fewer if statements?

A lot of these death messages are duplicated. Is there any chance these could be consolidated into fewer if statements?

Done 👍

Done 👍
}
}
if (was_shot) {
// Throwable with invalid owner
return message + " was shot under mysterious circumstances";

When would this ever happen?

When would this ever happen?

No idea, I thought it might be useful in case the paintings ever try to take over.

No idea, I thought it might be useful in case the paintings ever try to take over.
} else if (cause) {
// Unknown entity
return message + " was killed";
} else {
// Non-entity cause
if (was_shot) {
// Throwable with invalid owner
message += " was shot under mysterious circumstances";
} else {
// Anything else
message += " has died";
}
// Anything else
return message + " has died";
}
// Return