Skip to content

Commit a5ec228

Browse files
committed
Apply requested changes
1 parent 798ad0d commit a5ec228

File tree

5 files changed

+24
-13
lines changed

5 files changed

+24
-13
lines changed

src/block/utils/WaterloggableTrait.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,15 @@
2525

2626
use pocketmine\block\Block;
2727
use pocketmine\block\BlockTypeTags;
28+
use pocketmine\block\RuntimeBlockStateRegistry;
2829
use pocketmine\block\Water;
2930
use pocketmine\entity\Entity;
3031
use pocketmine\item\Item;
3132
use pocketmine\math\Vector3;
3233
use pocketmine\player\Player;
34+
use pocketmine\utils\AssumptionFailedError;
3335
use pocketmine\world\BlockTransaction;
36+
use pocketmine\world\format\Chunk;
3437

3538
trait WaterloggableTrait{
3639

@@ -74,7 +77,21 @@ public function hasEntityCollision() : bool{
7477
}
7578

7679
public function readStateFromWorld() : Block{
77-
$this->containedWater?->readStateFromWorld();
80+
$world = $this->position->getWorld();
81+
$chunk = $world->getOrLoadChunkAtPosition($this->position);
82+
if($chunk === null){
83+
throw new AssumptionFailedError("Chunk must be already loaded before calling this method");
84+
}
85+
86+
$displacedBlockStateId = $chunk->getDisplacedBlockStateId($this->position->getFloorX() & Chunk::COORD_MASK, $this->position->getFloorY(), $this->position->getFloorZ() & Chunk::COORD_MASK);
87+
if($displacedBlockStateId !== Block::EMPTY_STATE_ID && ($displacedBlock = RuntimeBlockStateRegistry::getInstance()->fromStateId($displacedBlockStateId)) instanceof Water){
88+
$displacedBlock->position($world, $this->position->getFloorX(), $this->position->getFloorY(), $this->position->getFloorZ());
89+
$displacedBlock->readStateFromWorld();
90+
91+
$this->containedWater = $displacedBlock;
92+
}else{
93+
$this->containedWater = null;
94+
}
7895
return $this;
7996
}
8097

src/item/Bucket.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ public function getMaxStackSize() : int{
4141
public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{
4242
//TODO: move this to generic placement logic
4343

44+
$blockClicked = $player->getWorld()->getBlock($blockClicked->getPosition()); //We might interact a displaced block
4445
if($blockClicked instanceof Waterloggable && ($water = $blockClicked->getContainedWater()) !== null && $water->isSource()){
4546
$resultBlock = (clone $blockClicked)->setContainedWater(null);
4647
$liquid = $blockClicked->getContainedWater();

src/item/LiquidBucket.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public function getFuelResidue() : Item{
6060
public function onInteractBlock(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, array &$returnedItems) : ItemUseResult{
6161
//TODO: move this to generic placement logic
6262

63+
$blockClicked = $player->getWorld()->getBlock($blockClicked->getPosition()); //We might interact a displaced block
6364
$targetBlock = null;
6465
$resultBlock = null;
6566

src/network/mcpe/handler/InGamePacketHandler.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@
4545
use pocketmine\nbt\tag\CompoundTag;
4646
use pocketmine\nbt\tag\StringTag;
4747
use pocketmine\network\FilterNoisyPacketException;
48-
use pocketmine\network\mcpe\convert\TypeConverter;
4948
use pocketmine\network\mcpe\InventoryManager;
5049
use pocketmine\network\mcpe\NetworkSession;
5150
use pocketmine\network\mcpe\protocol\ActorEventPacket;
@@ -501,7 +500,7 @@ private function handleUseItemTransaction(UseItemTransactionData $data) : bool{
501500
$vBlockPos = new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
502501
if($vBlockPos->distanceSquared($this->player->getLocation()) < 10000){
503502
$block = $this->player->getWorld()->getBlock($vBlockPos);
504-
$blockTranslator = TypeConverter::getInstance()->getBlockTranslator();
503+
$blockTranslator = $this->session->getTypeConverter()->getBlockTranslator();
505504
$clientRuntimeId = $data->getBlockRuntimeId();
506505
$interactDisplacedBlock = false;
507506

src/world/World.php

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636
use pocketmine\block\UnknownBlock;
3737
use pocketmine\block\utils\Waterloggable;
3838
use pocketmine\block\VanillaBlocks;
39-
use pocketmine\block\Water;
4039
use pocketmine\data\bedrock\BiomeIds;
4140
use pocketmine\data\bedrock\block\BlockStateData;
4241
use pocketmine\data\bedrock\block\BlockStateDeserializeException;
@@ -2029,21 +2028,14 @@ public function getBlockAt(int $x, int $y, int $z, bool $cached = true, bool $ad
20292028
$chunk = $this->chunks[$chunkHash] ?? null;
20302029
if($chunk !== null){
20312030
$block = $this->blockStateRegistry->fromStateId($chunk->getBlockStateId($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK));
2032-
$displacedBlockStateId = $chunk->getDisplacedBlockStateId($x & Chunk::COORD_MASK, $y, $z & Chunk::COORD_MASK);
20332031
}else{
20342032
$addToCache = false;
20352033
$block = VanillaBlocks::AIR();
2036-
$displacedBlockStateId = Block::EMPTY_STATE_ID;
20372034
}
20382035
}else{
20392036
$block = VanillaBlocks::AIR();
2040-
$displacedBlockStateId = Block::EMPTY_STATE_ID;
20412037
}
20422038

2043-
if($block instanceof Waterloggable && $displacedBlockStateId !== Block::EMPTY_STATE_ID){
2044-
$displacedBlockStateId = $this->blockStateRegistry->fromStateId($displacedBlockStateId);
2045-
$block->setContainedWater($displacedBlockStateId instanceof Water ? $displacedBlockStateId : null);
2046-
}
20472039
$block->position($this, $x, $y, $z);
20482040

20492041
if($this->inDynamicStateRecalculation){
@@ -2300,6 +2292,9 @@ private function destroyBlockInternal(Block $target, Item $item, ?Player $player
23002292
*/
23012293
public function useItemOn(Vector3 $vector, Item &$item, int $face, ?Vector3 $clickVector = null, ?Player $player = null, bool $playSound = false, array &$returnedItems = [], bool $interactDisplacedBlock = false) : bool{
23022294
$blockClicked = $this->getBlock($vector);
2295+
if($interactDisplacedBlock){
2296+
$blockClicked = $blockClicked->getDisplacedBlock() ?? $blockClicked;
2297+
}
23032298
$blockReplace = $blockClicked->getSide($face);
23042299

23052300
if($clickVector === null){
@@ -2331,8 +2326,6 @@ public function useItemOn(Vector3 $vector, Item &$item, int $face, ?Vector3 $cli
23312326
if($player->isSneakPressed()){
23322327
$ev->setUseItem(false);
23332328
$ev->setUseBlock($item->isNull()); //opening doors is still possible when sneaking if using an empty hand
2334-
}else{
2335-
$ev->setUseBlock(!$interactDisplacedBlock);
23362329
}
23372330
if($player->isSpectator()){
23382331
$ev->cancel(); //set it to cancelled so plugins can bypass this

0 commit comments

Comments
 (0)