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

Explosion: implemented underwater explosion #6456

Open
wants to merge 1 commit into
base: stable
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
1 change: 0 additions & 1 deletion src/entity/object/PrimedTNT.php
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ 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);
if($ev->isBlockBreaking()){
$explosion->explodeA();
Expand Down
13 changes: 13 additions & 0 deletions src/world/Explosion.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@
use pocketmine\block\RuntimeBlockStateRegistry;
use pocketmine\block\TNT;
use pocketmine\block\VanillaBlocks;
use pocketmine\block\Water;
use pocketmine\entity\Entity;
use pocketmine\entity\object\PrimedTNT;
use pocketmine\event\entity\EntityDamageByBlockEvent;
use pocketmine\event\entity\EntityDamageByEntityEvent;
use pocketmine\event\entity\EntityDamageEvent;
Expand Down Expand Up @@ -82,6 +84,11 @@ public function explodeA() : bool{
return false;
}

$worksUnderwater = false;
if($this->what instanceof PrimedTNT || $this->what instanceof TNT){
$worksUnderwater = $this->what->worksUnderwater();
}

$blockFactory = RuntimeBlockStateRegistry::getInstance();

$mRays = $this->rays - 1;
Expand Down Expand Up @@ -120,12 +127,18 @@ public function explodeA() : bool{
$state = $subChunk->getBlockStateId($vBlockX & SubChunk::COORD_MASK, $vBlockY & SubChunk::COORD_MASK, $vBlockZ & SubChunk::COORD_MASK);

$blastResistance = $blockFactory->blastResistance[$state] ?? 0;
if($worksUnderwater && $blockFactory->fromStateId($state) instanceof Water){
$blastResistance = 0;
}
if($blastResistance >= 0){
$blastForce -= ($blastResistance / 5 + 0.3) * $this->stepLen;
if($blastForce > 0){
if(!isset($this->affectedBlocks[World::blockHash($vBlockX, $vBlockY, $vBlockZ)])){
$_block = $this->world->getBlockAt($vBlockX, $vBlockY, $vBlockZ, true, false);
foreach($_block->getAffectedBlocks() as $_affectedBlock){
if($_affectedBlock instanceof Water){
continue;
}
$_affectedBlockPos = $_affectedBlock->getPosition();
$this->affectedBlocks[World::blockHash($_affectedBlockPos->x, $_affectedBlockPos->y, $_affectedBlockPos->z)] = $_affectedBlock;
}
Expand Down