Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/procedures.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ void handlePlayerUseItem (PlayerData *player, short x, short y, short z, uint8_t
void checkFluidUpdate (short x, uint8_t y, short z, uint8_t block);

void spawnMob (uint8_t type, short x, uint8_t y, short z, uint8_t health);
void spawnHostileMob(short mob_x, short mob_y, short mob_z);
void interactEntity (int entity_id, int interactor_id);
void hurtEntity (int entity_id, int attacker_id, uint8_t damage_type, uint8_t damage);
void handleServerTick (int64_t time_since_last_tick);
Expand Down
2 changes: 1 addition & 1 deletion src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
else if (mob_choice == 2) spawnMob(95, mob_x, mob_y, mob_z, 10); // Pig
else if (mob_choice == 3) spawnMob(106, mob_x, mob_y, mob_z, 8); // Sheep
} else {
spawnMob(145, mob_x, mob_y, mob_z, 20); // Zombie
spawnHostileMob(mob_x, mob_y, mob_z);
}
}
}
Expand Down
34 changes: 33 additions & 1 deletion src/procedures.c
Original file line number Diff line number Diff line change
Expand Up @@ -1397,6 +1397,19 @@ void spawnMob (uint8_t type, short x, uint8_t y, short z, uint8_t health) {

}

void spawnHostileMob(short mob_x, short mob_y, short mob_z){

int biome = getChunkBiome(div_floor(mob_x, CHUNK_SIZE), div_floor(mob_z, CHUNK_SIZE));

if (biome == W_desert) {
spawnMob(65, mob_x, mob_y, mob_z, 20); // Husk
return;
}

spawnMob(145, mob_x, mob_y, mob_z, 20); // Zombie

}

void interactEntity (int entity_id, int interactor_id) {

PlayerData *player;
Expand Down Expand Up @@ -1558,7 +1571,8 @@ void hurtEntity (int entity_id, int attacker_id, uint8_t damage_type, uint8_t da
case 28: givePlayerItem(player, I_beef, 1 + (fast_rand() % 3)); break;
case 95: givePlayerItem(player, I_porkchop, 1 + (fast_rand() % 3)); break;
case 106: givePlayerItem(player, I_mutton, 1 + (fast_rand() & 1)); break;
case 145: givePlayerItem(player, I_rotten_flesh, (fast_rand() % 3)); break;
case 145:
case 65: givePlayerItem(player, I_rotten_flesh, (fast_rand() % 3)); break;
default: break;
}
}
Expand Down Expand Up @@ -1771,6 +1785,24 @@ void handleServerTick (int64_t time_since_last_tick) {
// If we're already next to the player, hurt them and skip movement
if (closest_dist < 3 && abs(old_y - closest_player->y) < 2) {
hurtEntity(closest_player->client_fd, entity_id, D_generic, 6);
// Apply husk hunger penalty
if (closest_player->health > 0 && mob_data[i].type == 65) {
// If there is enough saturation to take the penalty, just subtract
// If not, then reset saturation and apply a smaller penalty to hunger
if (closest_player->saturation > 150) {
closest_player->saturation -= 150;
} else {
uint8_t penalty = 150 - closest_player->saturation;
closest_player->saturation = 200;
uint8_t hunger_penalty = penalty < 150 ? 1 : penalty / 50;
if (hunger_penalty > closest_player->hunger) {
closest_player->hunger = 0;
} else {
closest_player->hunger -= hunger_penalty;
}
sc_setHealth(closest_player->client_fd, closest_player->health, closest_player->hunger, closest_player->saturation);
}
}
continue;
}

Expand Down