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 all 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
9 changes: 9 additions & 0 deletions src/block/Block.php
Original file line number Diff line number Diff line change
Expand Up @@ -870,6 +870,15 @@ public function onEntityInside(Entity $entity) : bool{
return true;
}

/**
* Called when an entity collide on this block
*
* @return bool Whether the entity has been updated
*/
public function onEntityCollide(Entity $entity, int $face) : bool{
return false;
}
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
10 changes: 10 additions & 0 deletions src/block/Cactus.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,16 @@ public function onEntityInside(Entity $entity) : bool{
return true;
}

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{
$supportBlock = $block->getSide(Facing::DOWN);
if(!$supportBlock->hasSameTypeId($this) && !$supportBlock->hasTypeTag(BlockTypeTags::SAND)){
Expand Down
13 changes: 6 additions & 7 deletions src/block/Magma.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,22 @@
use pocketmine\entity\Living;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\math\Facing;

class Magma extends Opaque{

public function getLightLevel() : int{
return 3;
}

public function hasEntityCollision() : bool{
return true;
}

public function onEntityInside(Entity $entity) : bool{
if($entity instanceof Living && !$entity->isSneaking() && $entity->getFrostWalkerLevel() === 0){
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 true;

return false;
}

public function burnsForever() : bool{
Expand Down
10 changes: 10 additions & 0 deletions src/entity/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -661,6 +661,16 @@ protected function entityBaseTick(int $tickDiff = 1) : bool{
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$this->attack($ev);
$hasUpdate = true;
}else{
$entityBox = $this->getBoundingBox()->expandedCopy(0.00001, 3 / 16, 0.00001);
foreach (Facing::ALL as $face) {
$block = $this->getWorld()->getBlock($this->getLocation()->getSide($face));
if ($block->collidesWithBB($entityBox)) {
if ($block->onEntityCollide($this, Facing::opposite($face))) {
$hasUpdate = true;
Dhaiven marked this conversation as resolved.
Show resolved Hide resolved
}
}
}
}

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