fix mobs spawning at bad Y coordinate

This commit is contained in:
p2r3
2025-08-23 02:13:51 +03:00
parent d9f6511af1
commit b020cec224
2 changed files with 29 additions and 16 deletions

View File

@@ -27,6 +27,9 @@ void makeBlockChange (short x, uint8_t y, short z, uint8_t block);
uint8_t isInstantlyMined (PlayerData *player, uint8_t block); uint8_t isInstantlyMined (PlayerData *player, uint8_t block);
uint8_t isColumnBlock (uint8_t block); uint8_t isColumnBlock (uint8_t block);
uint8_t isPassableBlock (uint8_t block);
uint8_t isReplaceableBlock (uint8_t block);
uint16_t getMiningResult (uint16_t held_item, uint8_t block); uint16_t getMiningResult (uint16_t held_item, uint8_t block);
void bumpToolDurability (PlayerData *player); void bumpToolDurability (PlayerData *player);
void handlePlayerAction (PlayerData *player, int action, short x, short y, short z); void handlePlayerAction (PlayerData *player, int action, short x, short y, short z);

View File

@@ -266,12 +266,23 @@ void handlePacket (int client_fd, int length, int packet_id) {
// at a random position within the chunk // at a random position within the chunk
short mob_x = (_x + dx * VIEW_DISTANCE) * 16 + ((r >> 4) & 15); short mob_x = (_x + dx * VIEW_DISTANCE) * 16 + ((r >> 4) & 15);
short mob_z = (_z + dz * VIEW_DISTANCE) * 16 + ((r >> 8) & 15); short mob_z = (_z + dz * VIEW_DISTANCE) * 16 + ((r >> 8) & 15);
uint8_t mob_y = getHeightAt(mob_x, mob_z) + 1; // Start at the Y coordinate of the spawning player and move upward
// Ensure that there's space to spawn the mob // until a valid space is found
if ( uint8_t mob_y = cy;
getBlockAt(mob_x, mob_y, mob_z) == B_air && uint8_t b_low = getBlockAt(mob_x, mob_y - 1, mob_z);
getBlockAt(mob_x, mob_y + 1, mob_z) == B_air 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
!isPassableBlock(b_low) &&
isPassableBlock(b_mid) &&
isPassableBlock(b_top)
) break;
b_low = b_mid;
b_mid = b_top;
b_top = getBlockAt(mob_x, mob_y + 2, mob_z);
mob_y ++;
}
// Spawn passive mobs during the day, hostiles during the night // Spawn passive mobs during the day, hostiles during the night
if (world_time < 13000) { if (world_time < 13000) {
uint32_t mob_choice = (r >> 12) & 3; uint32_t mob_choice = (r >> 12) & 3;
@@ -283,7 +294,6 @@ void handlePacket (int client_fd, int length, int packet_id) {
spawnMob(145, mob_x, mob_y, mob_z, 20); // Zombie spawnMob(145, mob_x, mob_y, mob_z, 20); // Zombie
} }
} }
}
while (dx != 0) { while (dx != 0) {
sc_chunkDataAndUpdateLight(client_fd, _x + dx * VIEW_DISTANCE, _z); sc_chunkDataAndUpdateLight(client_fd, _x + dx * VIEW_DISTANCE, _z);