Skip to content
Open
Show file tree
Hide file tree
Changes from 10 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
2 changes: 1 addition & 1 deletion README.md
Comment thread
ccuser44 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ Alternatively, if you can't set up a file system, you can dump and upload world
- Create issues and discuss with the maintainer(s) before making pull requests.
- Follow the existing code style. Ensure that your changes fit in with the surrounding code, even if you disagree with the style. Pull requests with inconsistent style will be nitpicked.
- Test your code before creating a pull request or requesting a review, regardless of how "simple" your change is. It's a basic form of respect towards the maintainer and reviewer.
- Development tooling and compilation improvements _are not welcome,_ unless you've worked with the codebase long enough to have noticed practical shortcomings in that area. I'm tired of receiving tooling PRs from people who don't intend to work with those tools.
- Development tooling and compilation improvements _are not welcome,_ unless you've worked with the codebase long enough to have noticed practical shortcomings in that area. I'm tired of receiving tooling PRs from people who don't intend to work with those tools.
31 changes: 25 additions & 6 deletions src/main.c
Comment thread
ccuser44 marked this conversation as resolved.
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,33 @@ void handlePacket (int client_fd, int length, int packet_id, int state) {
if (mob_y != 255) {
// Spawn passive mobs above ground during the day,
// or hostiles underground and during the night
uint32_t mob_choice = (r >> 12) & 3;
if ((world_time < 13000 || world_time > 23460) && mob_y > 48) {
uint32_t mob_choice = (r >> 12) & 3;
if (mob_choice == 0) spawnMob(25, mob_x, mob_y, mob_z, 4); // Chicken
else if (mob_choice == 1) spawnMob(28, mob_x, mob_y, mob_z, 10); // Cow
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
switch (mob_choice) {
case 0:
spawnMob(25, mob_x, mob_y, mob_z, 4); // Chicken
case 1:
spawnMob(28, mob_x, mob_y, mob_z, 10); // Cow
case 2:
spawnMob(95, mob_x, mob_y, mob_z, 10); // Pig
case 3:
spawnMob(106, mob_x, mob_y, mob_z, 8); // Sheep
default:
printf("Failed to spawn passive mob %d?\n", mob_choice);
}
} else {
spawnMob(145, mob_x, mob_y, mob_z, 20); // Zombie
switch (mob_choice) {
case 0: // Only have a one in four chance for a creeper to spawn
case 1:
case 2:
spawnMob(/*(biome == W_desert) ? 65 :*/ 145, mob_x, mob_y, mob_z, 20); // Zombie // Husk spawning code is here in case it's going to be implemented later on
break;
case 3:
spawnMob(30, mob_x, mob_y, mob_z, 8); // Creeper, aww man
break;
default:
printf("Failed to spawn hostile mob %d?\n", mob_choice);
}
}
}
}
Expand Down
32 changes: 31 additions & 1 deletion src/procedures.c
Original file line number Diff line number Diff line change
Expand Up @@ -1372,6 +1372,20 @@ void handlePlayerUseItem (PlayerData *player, short x, short y, short z, uint8_t

}

void explode (short x, short y, short z, short radius) {
for (short xI = x - radius; xI <= x + radius; xI++) {
for (short yI = y - radius; yI <= y + radius; yI++) {
for (short zI = z - radius; zI <= z + radius; zI++) {
float randRad = ((float)radius * ((float)fast_rand(x + y + z) / 0x7FFFFFFF / 4 + 0.75));

if ((float)((xI- x) * (xI - x) + (yI - y) * (yI - y) + (zI - z) * (zI - z)) <= randRad*randRad) {
makeBlockChange(xI, yI, zI, B_air);
}
}
}
}
}

Comment thread
ccuser44 marked this conversation as resolved.
Outdated
void spawnMob (uint8_t type, short x, uint8_t y, short z, uint8_t health) {

for (int i = 0; i < MAX_MOBS; i ++) {
Expand Down Expand Up @@ -1786,7 +1800,23 @@ 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);
if (mob_data[i].type == 30) { // If mob is a creeper explode instead of deal meelee damage
//sc_entityEvent(closest_player->client_fd, entity_id, 59);

printf("Attempting to attack player with %d panic value...", panic);
if (panic >= 2) {
//sc_entityEvent(closest_player->client_fd, entity_id, 21);
explode(mob_data[i].x, mob_data[i].y, mob_data[i].z, 3);
hurtEntity(closest_player->client_fd, entity_id, D_generic, 255); // TODO: Make the explosion function deal damage
}

// Increase timer
if (server_ticks % (uint32_t)TICKS_PER_SECOND == 0) {
mob_data[i].data += (1 << 6);
}
} else {
hurtEntity(closest_player->client_fd, entity_id, D_generic, 6);
}
Comment thread
ccuser44 marked this conversation as resolved.
continue;
}

Expand Down