Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
7716731
feat: implement underwater explosion
nicholass003 Sep 21, 2024
f6a7281
Merge branch 'pmmp:stable' into feat/underwater-explosion
nicholass003 Nov 10, 2024
97d5760
feat: Add support for excluding specific BlockTypeIds in Explosion bl…
nicholass003 Nov 11, 2024
d88e149
Merge branch 'pmmp:stable' into feat/underwater-explosion
nicholass003 Nov 11, 2024
c91b3e4
chore: Add type annotations for `$excludedBlockTypeIds` parameter in …
nicholass003 Nov 11, 2024
3a1c7b2
chore: refactor array search by using isset and array_flip for better…
nicholass003 Nov 11, 2024
6f07b03
why did I delete this...
nicholass003 Nov 11, 2024
4c4055a
Merge branch 'pmmp:stable' into feat/underwater-explosion
nicholass003 Nov 11, 2024
af987dd
chore: Optimize `Explosion::explodeA` by avoiding `fromStateId` looku…
nicholass003 Nov 11, 2024
e86fb7c
Merge branch 'stable' into feat/underwater-explosion
nicholass003 Nov 12, 2024
60efe62
Merge branch 'minor-next' of https://github.com/pmmp/PocketMine-MP in…
nicholass003 Jun 9, 2025
3d5078f
feat: Adjust explosion source position for Underwater TNT
nicholass003 Jun 9, 2025
e4e3a66
fix: cs
nicholass003 Jun 9, 2025
f08f9de
docs(Explosion): fix phpstan docs
nicholass003 Jun 9, 2025
54cced4
refactor(Explosion): replace magic number with named constant for und…
nicholass003 Jun 9, 2025
b1cc2c5
Merge branch 'minor-next' into feat/underwater-explosion
nicholass003 Oct 2, 2025
8e4093f
refactor(Explosion): remove unnecessary changes
nicholass003 Oct 2, 2025
ae374e2
Merge branch 'minor-next' into feat/underwater-explosion
nicholass003 Oct 24, 2025
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
4 changes: 2 additions & 2 deletions src/entity/object/PrimedTNT.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

namespace pocketmine\entity\object;

use pocketmine\block\BlockTypeIds;
use pocketmine\block\VanillaBlocks;
use pocketmine\entity\Entity;
use pocketmine\entity\EntitySizeInfo;
Expand Down Expand Up @@ -120,8 +121,7 @@ public function explode() : void{
$ev = new EntityPreExplodeEvent($this, 4);
$ev->call();
if(!$ev->isCancelled()){
//TODO: deal with underwater TNT (underwater TNT treats water as if it has a blast resistance of 0)
$explosion = new Explosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->getWorld()), $ev->getRadius(), $this, $ev->getFireChance());
$explosion = new Explosion(Position::fromObject($this->location->add(0, $this->size->getHeight() / 2, 0), $this->getWorld()), $ev->getRadius(), $this, $ev->getFireChance(), $this->worksUnderwater ? [BlockTypeIds::WATER] : []);
if($ev->isBlockBreaking()){
$explosion->explodeA();
}
Expand Down
20 changes: 19 additions & 1 deletion src/world/Explosion.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@
use pocketmine\world\sound\ExplodeSound;
use pocketmine\world\utils\SubChunkExplorer;
use pocketmine\world\utils\SubChunkExplorerStatus;
use function array_fill_keys;
use function ceil;
use function count;
use function floor;
use function min;
use function mt_rand;
Expand All @@ -69,11 +71,22 @@ class Explosion{

private SubChunkExplorer $subChunkExplorer;

/**
* @var true[]
* @phpstan-var array<int, true>
*/
private array $excludedBlockTypeIds = [];

/**
* @param int[] $excludedBlockTypeIds
* @phpstan-param array<int, int> $excludedBlockTypeIds
*/
public function __construct(
public Position $source,
public float $radius,
private Entity|Block|null $what = null,
private float $fireChance = 0.0
private float $fireChance = 0.0,
array $excludedBlockTypeIds = []
){
if(!$this->source->isValid()){
throw new \InvalidArgumentException("Position does not have a valid world");
Expand All @@ -87,6 +100,8 @@ public function __construct(
throw new \InvalidArgumentException("Explosion radius must be greater than 0, got $radius");
}
$this->subChunkExplorer = new SubChunkExplorer($this->world);

$this->excludedBlockTypeIds = array_fill_keys($excludedBlockTypeIds, true);
}

/**
Expand Down Expand Up @@ -135,6 +150,9 @@ public function explodeA() : bool{
}

$state = $subChunk->getBlockStateId($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK);
if(count($this->excludedBlockTypeIds) > 0 && isset($this->excludedBlockTypeIds[$blockFactory->fromStateId($state)->getTypeId()])){
continue;
}

$blastResistance = $blockFactory->blastResistance[$state] ?? 0;
if($blastResistance >= 0){
Expand Down