1
0
mirror of https://github.com/p2r3/bareiron.git synced 2025-10-02 07:35:08 +02:00

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,22 +266,32 @@ 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);
// Spawn passive mobs during the day, hostiles during the night while (mob_y < 255) {
if (world_time < 13000) { if ( // Solid block below, non-solid at feet and above
uint32_t mob_choice = (r >> 12) & 3; !isPassableBlock(b_low) &&
if (mob_choice == 0) spawnMob(25, mob_x, mob_y, mob_z, 20); // Chicken isPassableBlock(b_mid) &&
else if (mob_choice == 1) spawnMob(28, mob_x, mob_y, mob_z, 20); // Cow isPassableBlock(b_top)
else if (mob_choice == 2) spawnMob(95, mob_x, mob_y, mob_z, 20); // Pig ) break;
else if (mob_choice == 3) spawnMob(106, mob_x, mob_y, mob_z, 20); // Sheep b_low = b_mid;
} else { b_mid = b_top;
spawnMob(145, mob_x, mob_y, mob_z, 20); // Zombie b_top = getBlockAt(mob_x, mob_y + 2, mob_z);
} mob_y ++;
}
// Spawn passive mobs during the day, hostiles during the night
if (world_time < 13000) {
uint32_t mob_choice = (r >> 12) & 3;
if (mob_choice == 0) spawnMob(25, mob_x, mob_y, mob_z, 20); // Chicken
else if (mob_choice == 1) spawnMob(28, mob_x, mob_y, mob_z, 20); // Cow
else if (mob_choice == 2) spawnMob(95, mob_x, mob_y, mob_z, 20); // Pig
else if (mob_choice == 3) spawnMob(106, mob_x, mob_y, mob_z, 20); // Sheep
} else {
spawnMob(145, mob_x, mob_y, mob_z, 20); // Zombie
} }
} }