Skip to content

Commit 0a21d05

Browse files
committed
Requested changes
1 parent b9ba469 commit 0a21d05

File tree

4 files changed

+27
-20
lines changed

4 files changed

+27
-20
lines changed

src/block/Liquid.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ private function onFlowUpdate() : void{
329329
if($adjacentDecay <= self::MAX_DECAY){
330330
$calculator = new MinimumCostFlowCalculator($world, $this->getFlowDecayPerBlock(), $this->canFlowInto(...));
331331
foreach($calculator->getOptimalFlowDirections($x, $y, $z) as $facing){
332-
if(!$this->isSideAvailable($owningBlock, Facing::opposite($facing))){
332+
if(!$this->isSideAvailable($owningBlock, $facing)){
333333
continue;
334334
}
335335
[$dx, $dy, $dz] = Facing::OFFSET[$facing];
@@ -359,7 +359,7 @@ protected function flowIntoBlock(Block $block, int $newFlowDecay, bool $falling)
359359
/** @phpstan-impure */
360360
private function getSmallestFlowDecay(Block $block, int $decay, int $face) : int{
361361
$liquid = $this->unpackLiquid($block);
362-
if(!($liquid instanceof Liquid) || !$liquid->hasSameTypeId($this) || !$this->isSideAvailable($block, $face)){
362+
if(!($liquid instanceof Liquid) || !$liquid->hasSameTypeId($this) || !$this->isSideAvailable($block, Facing::opposite($face))){
363363
return $decay;
364364
}
365365

src/block/Stair.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,7 @@ public function setShape(StairShape $shape) : self{
8989
}
9090

9191
public function isSideOpenToFlow(int $face) : bool{
92-
return
93-
($this->upsideDown || $face !== Facing::DOWN) &&
94-
($this->shape !== StairShape::STRAIGHT || Facing::opposite($this->facing) !== $face);
92+
return $this->getSupportType($face) !== SupportType::FULL;
9593
}
9694

9795
protected function recalculateCollisionBoxes() : array{

src/network/mcpe/handler/InGamePacketHandler.php

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
use pocketmine\math\Vector3;
4545
use pocketmine\nbt\tag\CompoundTag;
4646
use pocketmine\nbt\tag\StringTag;
47+
use pocketmine\network\mcpe\convert\TypeConverter;
4748
use pocketmine\network\mcpe\InventoryManager;
4849
use pocketmine\network\mcpe\NetworkSession;
4950
use pocketmine\network\mcpe\protocol\ActorEventPacket;
@@ -498,13 +499,27 @@ private function handleUseItemTransaction(UseItemTransactionData $data) : bool{
498499

499500
$blockPos = $data->getBlockPosition();
500501
$vBlockPos = new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
501-
$this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos, $data->getBlockRuntimeId());
502-
if($data->getClientInteractPrediction() === PredictedResult::SUCCESS){
503-
//always sync this in case plugins caused a different result than the client expected
504-
//we *could* try to enhance detection of plugin-altered behaviour, but this would require propagating
505-
//more information up the stack. For now I think this is good enough.
506-
//if only the client would tell us what blocks it thinks changed...
507-
$this->syncBlocksNearby($vBlockPos, $data->getFace());
502+
if($this->player->canInteract($vBlockPos->add(0.5, 0.5, 0.5), 15)){
503+
$block = $this->player->getWorld()->getBlock($vBlockPos);
504+
$blockTranslator = TypeConverter::getInstance()->getBlockTranslator();
505+
$clientRuntimeId = $data->getBlockRuntimeId();
506+
$interactContainedBlock = false;
507+
508+
if(($displaced = $block->getDisplacedBlock()) !== null && $blockTranslator->internalIdToNetworkId($displaced->getStateId()) === $clientRuntimeId){
509+
$interactContainedBlock = true;
510+
}elseif($blockTranslator->internalIdToNetworkId($block->getStateId()) !== $clientRuntimeId){
511+
$this->syncBlocksNearby($vBlockPos, $data->getFace());
512+
return true;
513+
}
514+
515+
$this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos, $interactContainedBlock);
516+
if($data->getClientInteractPrediction() === PredictedResult::SUCCESS){
517+
//always sync this in case plugins caused a different result than the client expected
518+
//we *could* try to enhance detection of plugin-altered behaviour, but this would require propagating
519+
//more information up the stack. For now I think this is good enough.
520+
//if only the client would tell us what blocks it thinks changed...
521+
$this->syncBlocksNearby($vBlockPos, $data->getFace());
522+
}
508523
}
509524
return true;
510525
case UseItemTransactionData::ACTION_CLICK_AIR:

src/player/Player.php

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,6 @@
108108
use pocketmine\math\Vector3;
109109
use pocketmine\nbt\tag\CompoundTag;
110110
use pocketmine\nbt\tag\IntTag;
111-
use pocketmine\network\mcpe\convert\TypeConverter;
112111
use pocketmine\network\mcpe\NetworkSession;
113112
use pocketmine\network\mcpe\protocol\AnimatePacket;
114113
use pocketmine\network\mcpe\protocol\MovePlayerPacket;
@@ -1927,20 +1926,15 @@ public function breakBlock(Vector3 $pos) : bool{
19271926
*
19281927
* @return bool if it did something
19291928
*/
1930-
public function interactBlock(Vector3 $pos, int $face, Vector3 $clickOffset, ?int $blockRuntimeId = null) : bool{
1929+
public function interactBlock(Vector3 $pos, int $face, Vector3 $clickOffset, bool $interactContainedBlock = false) : bool{
19311930
$this->setUsingItem(false);
19321931

19331932
if($this->canInteract($pos->add(0.5, 0.5, 0.5), $this->isCreative() ? self::MAX_REACH_DISTANCE_CREATIVE : self::MAX_REACH_DISTANCE_SURVIVAL)){
19341933
$this->broadcastAnimation(new ArmSwingAnimation($this), $this->getViewers());
19351934
$item = $this->inventory->getItemInHand(); //this is a copy of the real item
19361935
$oldItem = clone $item;
19371936
$returnedItems = [];
1938-
$world = $this->getWorld();
1939-
$interactContainedBlock = false;
1940-
if($blockRuntimeId !== null && ($displacedBlock = $world->getBlock($pos)->getDisplacedBlock()) !== null){
1941-
$interactContainedBlock = TypeConverter::getInstance()->getBlockTranslator()->internalIdToNetworkId($displacedBlock->getStateId()) === $blockRuntimeId;
1942-
}
1943-
if($world->useItemOn($pos, $item, $face, $clickOffset, $this, true, $returnedItems, $interactContainedBlock)){
1937+
if($this->getWorld()->useItemOn($pos, $item, $face, $clickOffset, $this, true, $returnedItems, $interactContainedBlock)){
19441938
$this->returnItemsFromAction($oldItem, $item, $returnedItems);
19451939
return true;
19461940
}

0 commit comments

Comments
 (0)