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
Open
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,9 +870,11 @@ public function onEntityInside(Entity $entity) : bool{

/**
* Called when an entity collide on this block
*
* @return bool Whether the entity has been updated
*/
public function onEntityCollide(Entity $entity, int $face) : void{
//NOOP
public function onEntityCollide(Entity $entity, int $face) : bool{
return false;
}
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved

/**
Expand Down
5 changes: 4 additions & 1 deletion src/block/Cactus.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,14 @@ public function onEntityInside(Entity $entity) : bool{
return true;
}

public function onEntityCollide(Entity $entity, int $face) : void{
public function onEntityCollide(Entity $entity, int $face) : bool{
if($face === Facing::UP){
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
$entity->attack($ev);
return true;
}

return false;
}

private function canBeSupportedAt(Block $block) : bool{
Expand Down
5 changes: 4 additions & 1 deletion src/block/Magma.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ public function getLightLevel() : int{
return 3;
}

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

return false;
}

public function burnsForever() : bool{
Expand Down
3 changes: 1 addition & 2 deletions src/entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -665,8 +665,7 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{
$block = $entityBlock->getSide($face);
foreach ($block->getCollisionBoxes() as $blockBox) {
if ($entityBox->intersectsWith($blockBox)) {
$block->onEntityCollide($this, Facing::opposite($face));
$hasUpdate = true;
$hasUpdate = $block->onEntityCollide($this, Facing::opposite($face));
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
break;
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down