Skip to content

Commit e5dfe53

Browse files
hew02p2r3
andauthored
implement cactus damage
* Added cactus damage for players and issues the respective death message. Halts if condition is reached * style nitpicks --------- Co-authored-by: p2r3 <[email protected]>
1 parent ff89519 commit e5dfe53

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

include/globals.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@
142142
// every time a block is broken.
143143
#define ENABLE_PICKUP_ANIMATION
144144

145+
// If defined, players are able to receive damage from nearby cacti.
146+
#define ENABLE_CACTUS_DAMAGE
147+
145148
// If defined, logs unrecognized packet IDs
146149
// #define DEV_LOG_UNKNOWN_PACKETS
147150

src/procedures.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1389,10 +1389,14 @@ void hurtEntity (int entity_id, int attacker_id, uint8_t damage_type, uint8_t da
13891389
strcpy((char *)recv_buffer + player_name_len, " was slain by ");
13901390
strcpy((char *)recv_buffer + player_name_len + 14, attacker->name);
13911391
recv_buffer[player_name_len + 14 + strlen(attacker->name)] = '\0';
1392+
} else if (damage_type == D_cactus) {
1393+
// Killed by being near a cactus
1394+
strcpy((char *)recv_buffer + player_name_len, " was pricked to death");
1395+
recv_buffer[player_name_len + 21] = '\0';
13921396
} else {
13931397
// Unknown death reason
13941398
strcpy((char *)recv_buffer + player_name_len, " died");
1395-
recv_buffer[player_name_len + 4] = '\0';
1399+
recv_buffer[player_name_len + 5] = '\0';
13961400
}
13971401

13981402
} else player->health -= effective_damage;
@@ -1502,6 +1506,15 @@ void handleServerTick (int64_t time_since_last_tick) {
15021506
if (block >= B_lava && block < B_lava + 4) {
15031507
hurtEntity(player->client_fd, -1, D_lava, 8);
15041508
}
1509+
#ifdef ENABLE_CACTUS_DAMAGE
1510+
// Tick damage from a cactus block if one is under/inside or around the player.
1511+
if (block == B_cactus ||
1512+
getBlockAt(player->x + 1, player->y, player->z) == B_cactus ||
1513+
getBlockAt(player->x - 1, player->y, player->z) == B_cactus ||
1514+
getBlockAt(player->x, player->y, player->z + 1) == B_cactus ||
1515+
getBlockAt(player->x, player->y, player->z - 1) == B_cactus
1516+
) hurtEntity(player->client_fd, -1, D_cactus, 4);
1517+
#endif
15051518
// Heal from saturation if player is able and has enough food
15061519
if (player->health >= 20 || player->health == 0) continue;
15071520
if (player->hunger < 18) continue;

0 commit comments

Comments
 (0)