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 onEntityCollide function when entity are above a block #6347

Open
wants to merge 21 commits into
base: minor-next
Choose a base branch
from

Conversation

Dhaiven
Copy link
Contributor

@Dhaiven Dhaiven commented May 14, 2024

Introduction

PocketMine don't have function to detect if an entity are above a block.
So i add a function and fix the bug with magma block.
But there are other bug of this type (with top of cactus...), so i must to be fix in this pr or open an other pr to fix them ?

Relevant issues

Fix #2041

Changes

API changes

Add Block::onEntityCollide()

Follow-up

Tests

Add-Magma-Block-PMMP.mp4

@IvanCraft623
Copy link
Member

This does not really check if there is a collision so if there is a slab between the magma block and the player, the player will be burned.

@Dhaiven
Copy link
Contributor Author

Dhaiven commented May 15, 2024

This does not really check if there is a collision so if there is a slab between the magma block and the player, the player will be burned.

Thanks for the feedback, it's fixed

@jasonw4331 jasonw4331 added Category: Gameplay Related to Minecraft gameplay experience Type: Fix Bug fix, typo fix, or any other fix Status: Waiting on Author labels Jun 23, 2024
Copy link
Member

@IvanCraft623 IvanCraft623 left a comment

Choose a reason for hiding this comment

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

The current implementation only works for collsions on down side. An appropriate solution to the problem would be to detect when colliding with any face of the block, not just one.

src/block/Block.php Outdated Show resolved Hide resolved
@Dhaiven
Copy link
Contributor Author

Dhaiven commented Jun 29, 2024

The current implementation only works for collsions on down side. An appropriate solution to the problem would be to detect when colliding with any face of the block, not just one.

Fixed

src/block/Magma.php Outdated Show resolved Hide resolved
src/entity/Entity.php Outdated Show resolved Hide resolved
ShockedPlot7560
ShockedPlot7560 previously approved these changes Jul 5, 2024
Copy link
Member

@ShockedPlot7560 ShockedPlot7560 left a comment

Choose a reason for hiding this comment

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

Look OK to me

src/block/Block.php Show resolved Hide resolved
@Dhaiven Dhaiven requested a review from dries-c July 18, 2024 16:01
@@ -658,6 +658,18 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$this->attack($ev);
$hasUpdate = true;
}else{
$entityBlock = $this->getWorld()->getBlock($this->getLocation());
$entityBox = $this->getBoundingBox()->expandedCopy(0.001, 0.1, 0.001);
Copy link
Member

Choose a reason for hiding this comment

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

Why is this different for the Y axis than X/Z?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Initially, I started testing with 0.001 for each axis but I found a bug on the Y axis with a slab. Indeed, if you put a block of magma under a slab and a player steps on this slab, with 0.001 on the Y axis, the collision is not detected so I put 0.1 to detect it

Copy link
Member

Choose a reason for hiding this comment

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

That doesn't make any sense. Is magma supposed to hurt you from underneath a slab? And if it is, why does 0.1 make a difference since the BB of a slab is 0.5 thick?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

After some reseach, player take damage on magma block if block between player and magma block has AABB below or equal to 13/16 like trapdoor (https://minecraft.wiki/w/Magma_Block#Damage). So the y value is 1-13/16 = 3/16.

Copy link
Member

Choose a reason for hiding this comment

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

Then it seems like a collide function isn't appropriate for this. We need something more like onEntityNearby() or onEntityAdjacent().

@dktapps dktapps changed the base branch from stable to minor-next November 28, 2024 16:13
@dktapps dktapps requested a review from a team as a code owner November 28, 2024 16:13
@dktapps dktapps added Category: API Related to the plugin API Type: Enhancement Contributes features or other improvements to PocketMine-MP and removed Type: Fix Bug fix, typo fix, or any other fix labels Nov 28, 2024
@dktapps dktapps dismissed stale reviews from dries-c and IvanCraft623 November 28, 2024 16:14

No longer valid

@ipad54
Copy link
Member

ipad54 commented Nov 28, 2024

My gut instinct is that a better name is probably called for.

How about onEntityStep()?

@dktapps
Copy link
Member

dktapps commented Nov 28, 2024

Doesn't really fit since it'll be called by a collision from any side.

@Dhaiven
Copy link
Contributor Author

Dhaiven commented Nov 30, 2024

We also still have hasEntityCollision() from those days

Why not keep this name and call this function just if hasEntityCollision return true ?
Moreover, this can be increase performance

@dktapps
Copy link
Member

dktapps commented Nov 30, 2024

We also still have hasEntityCollision() from those days

Why not keep this name and call this function just if hasEntityCollision return true ? Moreover, this can be increase performance

Because this will cause unexpected behaviour. No one expected these two functions to be bound together in the first place.

src/entity/Entity.php Outdated Show resolved Hide resolved
Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

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

It looks like what we actually need for this is a function that gets called when an entity is inside an adjacent block. Then, it should be up to the block to decide how much distance is allowed between the entity and the block to apply the effects.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Category: API Related to the plugin API Category: Gameplay Related to Minecraft gameplay experience Status: Waiting on Author Type: Enhancement Contributes features or other improvements to PocketMine-MP
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Magma blocks don't work any more
8 participants