From 80e767b257205b115a1ef8b8aed69641b9f532b2 Mon Sep 17 00:00:00 2001 From: GameHerobrine Date: Mon, 11 Jul 2022 18:57:23 +0300 Subject: [PATCH] liquid fixes, explosion algorithm was reverted to the old pocketmine's one --- src/material/block/liquid/Lava.php | 8 ++-- src/material/block/liquid/Water.php | 10 ++--- src/world/Explosion.php | 62 ++++++++++++++--------------- 3 files changed, 38 insertions(+), 42 deletions(-) diff --git a/src/material/block/liquid/Lava.php b/src/material/block/liquid/Lava.php index 222bd3a0..b35e5505 100644 --- a/src/material/block/liquid/Lava.php +++ b/src/material/block/liquid/Lava.php @@ -50,14 +50,14 @@ class LavaBlock extends LiquidBlock implements LightingBlock{ } public function checkWater(){ - for($side = 1; $side <= 5; ++$side){ + for($side = 0; $side <= 5; ++$side){ $b = $this->getSide($side); if($b instanceof WaterBlock){ $level = $this->meta & 0x06; if($level == 0x00){ - $this->level->setBlock($this, new ObsidianBlock(), false, false, true); + $this->level->setBlock($b, new ObsidianBlock(), false, false, true); }else{ - $this->level->setBlock($this, new CobblestoneBlock(), false, false, true); + $this->level->setBlock($b, new CobblestoneBlock(), false, false, true); } } } @@ -85,7 +85,7 @@ class LavaBlock extends LiquidBlock implements LightingBlock{ return false; } - if( $this->checkWater()){ + if($this->checkWater()){ return; } diff --git a/src/material/block/liquid/Water.php b/src/material/block/liquid/Water.php index ef26b2ad..7073cc65 100644 --- a/src/material/block/liquid/Water.php +++ b/src/material/block/liquid/Water.php @@ -27,7 +27,7 @@ class WaterBlock extends LiquidBlock{ public function place(Item $item, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){ $ret = $this->level->setBlock($this, $this, true, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 10, BLOCK_UPDATE_NORMAL); + ServerAPI::request()->api->block->scheduleBlockUpdate(clone $this, 5, BLOCK_UPDATE_NORMAL); return $ret; } @@ -96,7 +96,7 @@ class WaterBlock extends LiquidBlock{ if($from !== null || $level == 0x00){ if($down instanceof AirBlock || $down instanceof WaterBlock){ $this->level->setBlock($down, new WaterBlock(0x01), false, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($down, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); }elseif($level !== 0x07){{ for($side = 2; $side <= 5; ++$side){ $b = $this->getSide($side); @@ -106,7 +106,7 @@ class WaterBlock extends LiquidBlock{ } }elseif($b->isFlowable === true){ $this->level->setBlock($b, new WaterBlock($level + 1), false, false, true); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($b, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); } } } @@ -120,7 +120,7 @@ class WaterBlock extends LiquidBlock{ if($tlevel != 0x00){ for ($s = 0; $s <= 5; $s++) { $ssb = $sb->getSide($s); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); } $this->level->setBlock($sb, new AirBlock(), false, false, true); } @@ -131,7 +131,7 @@ class WaterBlock extends LiquidBlock{ if($tlevel != 0x00){ for ($s = 0; $s <= 5; $s++) { $ssb = $sb->getSide($s); - ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 10, BLOCK_UPDATE_NORMAL); + ServerAPI::request()->api->block->scheduleBlockUpdate(new Position($ssb, 0, 0, $this->level), 5, BLOCK_UPDATE_NORMAL); } $this->level->setBlock($b, new AirBlock(), false, false, true); } diff --git a/src/world/Explosion.php b/src/world/Explosion.php index e785654b..75d95a29 100644 --- a/src/world/Explosion.php +++ b/src/world/Explosion.php @@ -43,30 +43,7 @@ class Explosion{ $this->air = BlockAPI::getItem(AIR, 0, 1); $this->nullPlayer = new PlayerNull(); } - private function explodeBlocks($send, $source, $block){ - $server = ServerAPI::request(); - if($block instanceof TNTBlock){ - $data = array( - "x" => $block->x + 0.5, - "y" => $block->y + 0.5, - "z" => $block->z + 0.5, - "power" => 4, - "fuse" => mt_rand(10, 30), //0.5 to 1.5 seconds - ); - $e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); - $server->api->entity->spawnToAll($e); - }elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){ - $tmp = $block->getDrops($this->air, $this->nullPlayer); - if(is_array($tmp)){ - foreach($tmp as $drop){ - $server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1],$drop[2])); //id, meta, count - } - } - } - $this->level->level->setBlockID($block->x, $block->y, $block->z, 0); - $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); - return $send; - } + public function explode(){ if(!Explosion::$enableExplosions){ /*Disable Explosions*/ return; @@ -79,11 +56,7 @@ class Explosion{ )) === false){ return false; } - - $send = array(); - $source = $this->source->floor(); - $radius = 2 * $this->size; - + $mRays = $this->rays - 1; for($i = 0; $i < $this->rays; ++$i){ for($j = 0; $j < $this->rays; ++$j){ @@ -106,7 +79,7 @@ class Explosion{ if($blastForce > 0){ $index = ($block->x << 15) + ($block->z << 7) + $block->y; if(!isset($this->affectedBlocks[$index])){ - $send = $this->explodeBlocks($send, $source,$block); + $this->affectedBlocks[$index] = $block; } } } @@ -116,14 +89,37 @@ class Explosion{ } } } + + $send = array(); + $source = $this->source->floor(); + $radius = 2 * $this->size; foreach($server->api->entity->getRadius($this->source, $radius) as $entity){ - if($entity->type === OBJECT_PRIMEDTNT){ - continue; - } $impact = (1 - $this->source->distance($entity) / $radius) * 0.5; //placeholder, 0.7 should be exposure $damage = (int) (($impact * $impact + $impact) * 8 * $this->size + 1); $entity->harm($damage, "explosion"); } + + foreach($this->affectedBlocks as $block){ + + if($block instanceof TNTBlock){ + $data = array( + "x" => $block->x + 0.5, + "y" => $block->y + 0.5, + "z" => $block->z + 0.5, + "power" => 4, + "fuse" => mt_rand(10, 30), //0.5 to 1.5 seconds + ); + $e = $server->api->entity->add($this->level, ENTITY_OBJECT, OBJECT_PRIMEDTNT, $data); + $server->api->entity->spawnToAll($e); + }elseif(mt_rand(0, 10000) < ((1/$this->size) * 10000)){ + foreach($block->getDrops($this->air, $this->nullPlayer) as $drop){ + $server->api->entity->drop(new Position($block->x + 0.5, $block->y, $block->z + 0.5, $this->level), BlockAPI::getItem($drop[0], $drop[1],$drop[2])); //id, meta, count + } + } + $this->level->level->setBlockID($block->x, $block->y, $block->z, 0); + ServerAPI::request()->api->block->blockUpdateAround(new Position($block->x, $block->y, $block->z, $this->level), BLOCK_UPDATE_NORMAL, 5); + $send[] = new Vector3($block->x - $source->x, $block->y - $source->y, $block->z - $source->z); + } $pk = new ExplodePacket; $pk->x = $this->source->x; $pk->y = $this->source->y;