Skip to content

Commit b237cac

Browse files
committed
InGamePacketHandler: don't resync blocks if the client predicted an interact fail
if the prediction was a fail, we can assume that the client didn't do anything visual on its end, which avoids the need to resend blocks. This fixes block lag when towering as discussed in #6803. The more general issue in #6803 remains unresolved (that the server's block resyncing may overwrite additional client side predictions if it places a block before the server's resync for the initial placement arrives), but that's more complicated to fix and I'm not convinced on the correct method to resolve it yet. In any case, this change nets a decent improvement for everyone, regardless.
1 parent e7ad3c2 commit b237cac

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/network/mcpe/handler/InGamePacketHandler.php

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@
8989
use pocketmine\network\mcpe\protocol\types\inventory\MismatchTransactionData;
9090
use pocketmine\network\mcpe\protocol\types\inventory\NetworkInventoryAction;
9191
use pocketmine\network\mcpe\protocol\types\inventory\NormalTransactionData;
92+
use pocketmine\network\mcpe\protocol\types\inventory\PredictedResult;
9293
use pocketmine\network\mcpe\protocol\types\inventory\ReleaseItemTransactionData;
9394
use pocketmine\network\mcpe\protocol\types\inventory\stackrequest\ItemStackRequest;
9495
use pocketmine\network\mcpe\protocol\types\inventory\stackresponse\ItemStackResponse;
@@ -498,11 +499,13 @@ private function handleUseItemTransaction(UseItemTransactionData $data) : bool{
498499
$blockPos = $data->getBlockPosition();
499500
$vBlockPos = new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
500501
$this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos);
501-
//always sync this in case plugins caused a different result than the client expected
502-
//we *could* try to enhance detection of plugin-altered behaviour, but this would require propagating
503-
//more information up the stack. For now I think this is good enough.
504-
//if only the client would tell us what blocks it thinks changed...
505-
$this->syncBlocksNearby($vBlockPos, $data->getFace());
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());
508+
}
506509
return true;
507510
case UseItemTransactionData::ACTION_CLICK_AIR:
508511
if($this->player->isUsingItem()){

0 commit comments

Comments
 (0)