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 13 commits into
base: stable
Choose a base branch
from
6 changes: 6 additions & 0 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -868,6 +868,12 @@ public function onEntityInside(Entity $entity) : bool{
return true;
}

/**
* Called when an entity's is above this block
*/
public function onEntityCollide(Entity $entity) : void{
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
}
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved

/**
* Returns a direction vector describing which way an entity intersecting this block should be pushed.
* This is used by liquids to push entities in liquid currents.
Expand Down
3 changes: 1 addition & 2 deletions src/block/Magma.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,11 @@ public function hasEntityCollision() : bool{
return true;
}

public function onEntityInside(Entity $entity) : bool{
public function onEntityCollide(Entity $entity) : void{
if($entity instanceof Living && !$entity->isSneaking()){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
$entity->attack($ev);
}
return true;
}

public function burnsForever() : bool{
Expand Down
9 changes: 9 additions & 0 deletions src/entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,15 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$this->attack($ev);
$hasUpdate = true;
}elseif($this->isOnGround()){
$block = $this->getWorld()->getBlock($this->getLocation()->subtract(0, 1, 0));
$entityBox = $this->getBoundingBox()->addCoord(0, -0.00001, 0);
foreach ($block->getCollisionBoxes() as $blockBox) {
if ($entityBox->intersectsWith($blockBox)) {
$block->onEntityCollide($this);
break;
}
}
}

if($this->isOnFire() && $this->doOnFireTick($tickDiff)){
Expand Down