mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-05-12 16:59:44 +00:00
Entity: Invalid blocksAround cache when something happens during onEntityInside()
this fixes TNT spawning multiple entities when lit by flaming arrows. The problem here is a bit more complex (entities aren't immediately notified when local block updates happen, so they cache stuff that becomes unusable). The simplest option would be to just lose the cache, but that would have some impacts on performance. Barring a rethink of the block updating mechanism, this solution seems usable for now.
This commit is contained in:
parent
ae9e931849
commit
8e12693494
@ -536,9 +536,12 @@ class Block{
|
||||
/**
|
||||
* Called when an entity's bounding box clips inside this block's cell. Note that the entity may not be intersecting
|
||||
* with the collision box or bounding box.
|
||||
*
|
||||
* @return bool Whether the block is still the same after the intersection. If it changed (e.g. due to an explosive
|
||||
* being ignited), this should return false.
|
||||
*/
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -68,9 +68,10 @@ class Cactus extends Transparent{
|
||||
return [AxisAlignedBB::one()->contract($shrinkSize, 0, $shrinkSize)->trim(Facing::UP, $shrinkSize)];
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_CONTACT, 1);
|
||||
$entity->attack($ev);
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onNearbyBlockChange() : void{
|
||||
|
@ -37,8 +37,9 @@ class Cobweb extends Flowable{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
$entity->resetFallDistance();
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDropsForCompatibleTool(Item $item) : array{
|
||||
|
@ -68,7 +68,7 @@ class Fire extends Flowable{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
|
||||
$entity->attack($ev);
|
||||
|
||||
@ -80,6 +80,7 @@ class Fire extends Flowable{
|
||||
if(!$ev->isCancelled()){
|
||||
$entity->setOnFire($ev->getDuration());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function getDropsForCompatibleTool(Item $item) : array{
|
||||
|
@ -66,11 +66,12 @@ class Ladder extends Transparent{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
if($entity instanceof Living && $entity->getPosition()->floor()->distanceSquared($this->pos) < 1){ //entity coordinates must be inside block
|
||||
$entity->resetFallDistance();
|
||||
$entity->onGround = true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -87,7 +87,7 @@ class Lava extends Liquid{
|
||||
}
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
$entity->fallDistance *= 0.5;
|
||||
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_LAVA, 4);
|
||||
@ -100,5 +100,6 @@ class Lava extends Liquid{
|
||||
}
|
||||
|
||||
$entity->resetFallDistance();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -43,11 +43,12 @@ class Magma extends Opaque{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
if($entity instanceof Living and !$entity->isSneaking()){
|
||||
$ev = new EntityDamageByBlockEvent($this, $entity, EntityDamageEvent::CAUSE_FIRE, 1);
|
||||
$entity->attack($ev);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function burnsForever() : bool{
|
||||
|
@ -83,7 +83,8 @@ class NetherPortal extends Transparent{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
//TODO
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -83,10 +83,12 @@ class TNT extends Opaque{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
if($entity instanceof Arrow and $entity->isOnFire()){
|
||||
$this->ignite();
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public function ignite(int $fuse = 80) : void{
|
||||
|
@ -81,8 +81,9 @@ class Vine extends Flowable{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
$entity->resetFallDistance();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function recalculateCollisionBoxes() : array{
|
||||
|
@ -46,10 +46,11 @@ class Water extends Liquid{
|
||||
return 5;
|
||||
}
|
||||
|
||||
public function onEntityInside(Entity $entity) : void{
|
||||
public function onEntityInside(Entity $entity) : bool{
|
||||
$entity->resetFallDistance();
|
||||
if($entity->isOnFire()){
|
||||
$entity->extinguish();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -1279,7 +1279,9 @@ abstract class Entity{
|
||||
$vectors = [];
|
||||
|
||||
foreach($this->getBlocksAround() as $block){
|
||||
$block->onEntityInside($this);
|
||||
if(!$block->onEntityInside($this)){
|
||||
$this->blocksAround = null;
|
||||
}
|
||||
if(($v = $block->addVelocityToEntity($this)) !== null){
|
||||
$vectors[] = $v;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user