Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nearby players collision check when trying to place blocks #293

Merged
merged 8 commits into from
Dec 25, 2024

Conversation

Tiiita
Copy link
Contributor

@Tiiita Tiiita commented Nov 15, 2024

Description

Added a function in world/mod.rs that checks nearby players by a given point and a radius.
Using this function I switched the function that gets the nearby players to the new one and chose a radius of 20.
So every time a player tries to place a block it searches up players in the radius of 20 blocks and checks the collision with them.
If no collision was found it places the block. With that change I also fixed the bug that players could place blocks at their head height and start to swim.

Testing

Tried to place blocks beside or in myself and my 2. account. Both tries worked as expected. Feels like original vanilla minecraft.
I also tried to change the game modes and place from different angles.

Checklist

  • (Not needed) More testing with more than 2 players. [ ]

  • Code is well-formatted and adheres to project style guidelines: cargo fmt

  • Code does not produce any clippy warnings cargo clippy

@Tiiita Tiiita force-pushed the check_collision_before_block_place branch from b9ee79b to afae3d0 Compare December 2, 2024 18:57

//Search in 20 block radius
let mut intersects = false;
for player in world.get_nearby_players(entity.pos.load(), 20).await {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would't i make more sense to search in the players block range distance ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not say no, because the block should not intercept with other boundingboxes. I mean the position of the player is unimportant for the collision check. As you can see the radius is 20 blocks so the "placer" or player that places the block will automatically be in that range so players cannot place in themselfs. I hope I was able to make clear why used the block as the middle of the searching circle. But if you still want that to be changed I can do that.

@Snowiiii
Copy link
Member

Overall looks good.
Thanks @Tiiita

@Snowiiii Snowiiii merged commit e8deff5 into Pumpkin-MC:master Dec 25, 2024
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants