Skip to content

Commit 3e77acb

Browse files
committed
Move setDisplacedBlock() into an interface
1 parent 2c5c9b0 commit 3e77acb

File tree

4 files changed

+45
-10
lines changed

4 files changed

+45
-10
lines changed

src/block/Block.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -418,14 +418,6 @@ public function getDisplacedBlock() : ?Block{
418418
return null;
419419
}
420420

421-
/**
422-
* @internal
423-
* Called when block is loaded to update its cover.
424-
*/
425-
public function setDisplacedBlock(?Block $block) : void{
426-
//NOOP
427-
}
428-
429421
/**
430422
* Returns whether this block can be placed when obtained as an item.
431423
*/

src/block/utils/BlockDisplacer.php

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<?php
2+
3+
/*
4+
*
5+
* ____ _ _ __ __ _ __ __ ____
6+
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7+
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8+
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9+
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10+
*
11+
* This program is free software: you can redistribute it and/or modify
12+
* it under the terms of the GNU Lesser General Public License as published by
13+
* the Free Software Foundation, either version 3 of the License, or
14+
* (at your option) any later version.
15+
*
16+
* @author PocketMine Team
17+
* @link http://www.pocketmine.net/
18+
*
19+
*
20+
*/
21+
22+
declare(strict_types=1);
23+
24+
namespace pocketmine\block\utils;
25+
26+
use pocketmine\block\Block;
27+
28+
/**
29+
* Indicates that a block can contain another block inside.
30+
* Used in things like waterlogging & snowlogging.
31+
*/
32+
interface BlockDisplacer{
33+
34+
/**
35+
* @internal
36+
* Called when a block is loaded to update its contained block.
37+
* Do NOT use this in plugins, use your block provided API instead.
38+
*/
39+
public function setDisplacedBlock(?Block $block) : void;
40+
}

src/block/utils/CoveredByWater.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
use pocketmine\block\Block;
2727
use pocketmine\block\Water;
2828

29-
interface CoveredByWater{
29+
interface CoveredByWater extends BlockDisplacer{
3030

3131
public function getWaterCover() : ?Water;
3232

src/world/World.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
use pocketmine\block\tile\Tile;
3535
use pocketmine\block\tile\TileFactory;
3636
use pocketmine\block\UnknownBlock;
37+
use pocketmine\block\utils\BlockDisplacer;
3738
use pocketmine\block\VanillaBlocks;
3839
use pocketmine\data\bedrock\BiomeIds;
3940
use pocketmine\data\bedrock\block\BlockStateData;
@@ -2036,7 +2037,9 @@ public function getBlockAt(int $x, int $y, int $z, bool $cached = true, bool $ad
20362037
$displacedBlock = null;
20372038
}
20382039

2039-
$block->setDisplacedBlock($displacedBlock);
2040+
if($block instanceof BlockDisplacer){
2041+
$block->setDisplacedBlock($displacedBlock);
2042+
}
20402043
$block->position($this, $x, $y, $z);
20412044

20422045
if($this->inDynamicStateRecalculation){

0 commit comments

Comments
 (0)