From ba03d92ad0f2cea409a94486a86dbe26bc161aa3 Mon Sep 17 00:00:00 2001 From: anmol-patankar Date: Fri, 12 Sep 2025 22:23:08 +0530 Subject: [PATCH] fix mobs spawning in water * Fixed underwater under lava mob spawn issue #17 * made comment changes * minor fix * method name change * method change * fixed --- include/procedures.h | 1 + src/main.c | 6 +++--- src/procedures.c | 9 +++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/include/procedures.h b/include/procedures.h index 4c97b61..819aa4a 100644 --- a/include/procedures.h +++ b/include/procedures.h @@ -28,6 +28,7 @@ uint8_t makeBlockChange (short x, uint8_t y, short z, uint8_t block); uint8_t isInstantlyMined (PlayerData *player, uint8_t block); uint8_t isColumnBlock (uint8_t block); uint8_t isPassableBlock (uint8_t block); +uint8_t isPassableSpawnBlock (uint8_t block); uint8_t isReplaceableBlock (uint8_t block); uint32_t isCompostItem (uint16_t item); uint8_t getItemStackSize (uint16_t item); diff --git a/src/main.c b/src/main.c index b2f99e7..dd1266f 100644 --- a/src/main.c +++ b/src/main.c @@ -355,10 +355,10 @@ void handlePacket (int client_fd, int length, int packet_id, int state) { uint8_t b_mid = getBlockAt(mob_x, mob_y, mob_z); uint8_t b_top = getBlockAt(mob_x, mob_y + 1, mob_z); while (mob_y < 255) { - if ( // Solid block below, non-solid at feet and above + if ( // Solid block below, non-solid(spawnable) at feet and above !isPassableBlock(b_low) && - isPassableBlock(b_mid) && - isPassableBlock(b_top) + isPassableSpawnBlock(b_mid) && + isPassableSpawnBlock(b_top) ) break; b_low = b_mid; b_mid = b_top; diff --git a/src/procedures.c b/src/procedures.c index 24068dd..2e485b3 100644 --- a/src/procedures.c +++ b/src/procedures.c @@ -637,6 +637,15 @@ uint8_t isPassableBlock (uint8_t block) { block == B_torch ); } +// Checks whether the given block is non-solid and spawnable +uint8_t isPassableSpawnBlock (uint8_t block) { + if ((block >= B_water && block < B_water + 8) || + (block >= B_lava && block < B_lava + 4)) + { + return 0; + } + return isPassableBlock(block); +} // Checks whether the given block can be replaced by another block uint8_t isReplaceableBlock (uint8_t block) {