From 028815490ee69885bd5c9d2b1ef620ca8f0df4b7 Mon Sep 17 00:00:00 2001 From: zSALLAZAR <59490940+zSALLAZAR@users.noreply.github.com> Date: Fri, 18 Apr 2025 11:19:46 +0200 Subject: [PATCH] Add EntityExtinguishEvent (#6671) --- src/block/Water.php | 3 +- src/block/WaterCauldron.php | 3 +- src/entity/Entity.php | 10 ++-- src/event/entity/EntityExtinguishEvent.php | 53 ++++++++++++++++++++++ src/player/Player.php | 3 +- 5 files changed, 66 insertions(+), 6 deletions(-) create mode 100644 src/event/entity/EntityExtinguishEvent.php diff --git a/src/block/Water.php b/src/block/Water.php index b711ab5a1..44759783a 100644 --- a/src/block/Water.php +++ b/src/block/Water.php @@ -24,6 +24,7 @@ declare(strict_types=1); namespace pocketmine\block; use pocketmine\entity\Entity; +use pocketmine\event\entity\EntityExtinguishEvent; use pocketmine\world\sound\BucketEmptyWaterSound; use pocketmine\world\sound\BucketFillWaterSound; use pocketmine\world\sound\Sound; @@ -53,7 +54,7 @@ class Water extends Liquid{ public function onEntityInside(Entity $entity) : bool{ $entity->resetFallDistance(); if($entity->isOnFire()){ - $entity->extinguish(); + $entity->extinguish(EntityExtinguishEvent::CAUSE_WATER); } return true; } diff --git a/src/block/WaterCauldron.php b/src/block/WaterCauldron.php index e470aa6cb..8129f2960 100644 --- a/src/block/WaterCauldron.php +++ b/src/block/WaterCauldron.php @@ -27,6 +27,7 @@ use pocketmine\block\tile\Cauldron as TileCauldron; use pocketmine\block\utils\DyeColor; use pocketmine\color\Color; use pocketmine\entity\Entity; +use pocketmine\event\entity\EntityExtinguishEvent; use pocketmine\item\Armor; use pocketmine\item\Banner; use pocketmine\item\Dye; @@ -183,7 +184,7 @@ final class WaterCauldron extends FillableCauldron{ public function onEntityInside(Entity $entity) : bool{ if($entity->isOnFire()){ - $entity->extinguish(); + $entity->extinguish(EntityExtinguishEvent::CAUSE_WATER_CAULDRON); //TODO: particles $this->position->getWorld()->setBlock($this->position, $this->withFillLevel($this->getFillLevel() - self::ENTITY_EXTINGUISH_USE_AMOUNT)); diff --git a/src/entity/Entity.php b/src/entity/Entity.php index e24c6067c..1637e0755 100644 --- a/src/entity/Entity.php +++ b/src/entity/Entity.php @@ -31,6 +31,7 @@ use pocketmine\block\Water; use pocketmine\entity\animation\Animation; use pocketmine\event\entity\EntityDamageEvent; use pocketmine\event\entity\EntityDespawnEvent; +use pocketmine\event\entity\EntityExtinguishEvent; use pocketmine\event\entity\EntityMotionEvent; use pocketmine\event\entity\EntityRegainHealthEvent; use pocketmine\event\entity\EntitySpawnEvent; @@ -709,7 +710,10 @@ abstract class Entity{ } } - public function extinguish() : void{ + public function extinguish(int $cause = EntityExtinguishEvent::CAUSE_CUSTOM) : void{ + $ev = new EntityExtinguishEvent($this, $cause); + $ev->call(); + $this->fireTicks = 0; $this->networkPropertiesDirty = true; } @@ -720,7 +724,7 @@ abstract class Entity{ protected function doOnFireTick(int $tickDiff = 1) : bool{ if($this->isFireProof() && $this->isOnFire()){ - $this->extinguish(); + $this->extinguish(EntityExtinguishEvent::CAUSE_FIRE_PROOF); return false; } @@ -731,7 +735,7 @@ abstract class Entity{ } if(!$this->isOnFire()){ - $this->extinguish(); + $this->extinguish(EntityExtinguishEvent::CAUSE_TICKING); }else{ return true; } diff --git a/src/event/entity/EntityExtinguishEvent.php b/src/event/entity/EntityExtinguishEvent.php new file mode 100644 index 000000000..b39d12231 --- /dev/null +++ b/src/event/entity/EntityExtinguishEvent.php @@ -0,0 +1,53 @@ + + */ +class EntityExtinguishEvent extends EntityEvent{ + public const CAUSE_CUSTOM = 0; + public const CAUSE_WATER = 1; + public const CAUSE_WATER_CAULDRON = 2; + public const CAUSE_RESPAWN = 3; + public const CAUSE_FIRE_PROOF = 4; + public const CAUSE_TICKING = 5; + public const CAUSE_RAIN = 6; + public const CAUSE_POWDER_SNOW = 7; + + public function __construct( + Entity $entity, + private int $cause + ){ + $this->entity = $entity; + } + + public function getCause() : int{ + return $this->cause; + } +} diff --git a/src/player/Player.php b/src/player/Player.php index 1c67b7182..3c494b980 100644 --- a/src/player/Player.php +++ b/src/player/Player.php @@ -45,6 +45,7 @@ use pocketmine\entity\projectile\Arrow; use pocketmine\entity\Skin; use pocketmine\event\entity\EntityDamageByEntityEvent; use pocketmine\event\entity\EntityDamageEvent; +use pocketmine\event\entity\EntityExtinguishEvent; use pocketmine\event\inventory\InventoryCloseEvent; use pocketmine\event\inventory\InventoryOpenEvent; use pocketmine\event\player\PlayerBedEnterEvent; @@ -2546,7 +2547,7 @@ class Player extends Human implements CommandSender, ChunkListener, IPlayer{ $this->setSneaking(false); $this->setFlying(false); - $this->extinguish(); + $this->extinguish(EntityExtinguishEvent::CAUSE_RESPAWN); $this->setAirSupplyTicks($this->getMaxAirSupplyTicks()); $this->deadTicks = 0; $this->noDamageTicks = 60;