130 private const MAX_FORM_RESPONSE_SIZE = 10 * 1024;
131 private const MAX_FORM_RESPONSE_DEPTH = 2;
133 protected float $lastRightClickTime = 0.0;
136 protected ?
Vector3 $lastPlayerAuthInputPosition =
null;
137 protected ?
float $lastPlayerAuthInputYaw =
null;
138 protected ?
float $lastPlayerAuthInputPitch =
null;
139 protected ?
BitSet $lastPlayerAuthInputFlags =
null;
143 public bool $forceMoveSync =
false;
145 protected ?
string $lastRequestedFullSkinId =
null;
147 public function __construct(
153 public function handleText(
TextPacket $packet) :
bool{
154 if($packet->type === TextPacket::TYPE_CHAT){
155 return $this->player->chat($packet->message);
167 private function resolveOnOffInputFlags(
BitSet $inputFlags,
int $startFlag,
int $stopFlag) : ?
bool{
168 $enabled = $inputFlags->get($startFlag);
169 $disabled = $inputFlags->get($stopFlag);
170 if($enabled !== $disabled){
178 $rawPos = $packet->getPosition();
179 $rawYaw = $packet->getYaw();
180 $rawPitch = $packet->getPitch();
181 foreach([$rawPos->x, $rawPos->y, $rawPos->z, $rawYaw, $packet->getHeadYaw(), $rawPitch] as $float){
182 if(is_infinite($float) || is_nan($float)){
183 $this->session->getLogger()->debug(
"Invalid movement received, contains NAN/INF components");
188 if($rawYaw !== $this->lastPlayerAuthInputYaw || $rawPitch !== $this->lastPlayerAuthInputPitch){
189 $this->lastPlayerAuthInputYaw = $rawYaw;
190 $this->lastPlayerAuthInputPitch = $rawPitch;
192 $yaw = fmod($rawYaw, 360);
193 $pitch = fmod($rawPitch, 360);
198 $this->player->setRotation($yaw, $pitch);
201 $hasMoved = $this->lastPlayerAuthInputPosition ===
null || !$this->lastPlayerAuthInputPosition->equals($rawPos);
202 $newPos = $rawPos->subtract(0, 1.62, 0)->round(4);
204 if($this->forceMoveSync && $hasMoved){
205 $curPos = $this->player->getLocation();
207 if($newPos->distanceSquared($curPos) > 1){
208 $this->session->getLogger()->debug(
"Got outdated pre-teleport movement, received " . $newPos .
", expected " . $curPos);
214 $this->forceMoveSync =
false;
217 $inputFlags = $packet->getInputFlags();
218 if($this->lastPlayerAuthInputFlags ===
null || !$inputFlags->equals($this->lastPlayerAuthInputFlags)){
219 $this->lastPlayerAuthInputFlags = $inputFlags;
223 $sneaking = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SNEAKING, PlayerAuthInputFlags::STOP_SNEAKING);
224 $sprinting = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SPRINTING, PlayerAuthInputFlags::STOP_SPRINTING);
225 $swimming = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_SWIMMING, PlayerAuthInputFlags::STOP_SWIMMING);
226 $gliding = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_GLIDING, PlayerAuthInputFlags::STOP_GLIDING);
227 $flying = $this->resolveOnOffInputFlags($inputFlags, PlayerAuthInputFlags::START_FLYING, PlayerAuthInputFlags::STOP_FLYING);
229 (!$this->player->toggleSneak($sneaking ?? $this->player->isSneaking(), $sneakPressed)) |
230 ($sprinting !==
null && !$this->player->toggleSprint($sprinting)) |
231 ($swimming !==
null && !$this->player->toggleSwim($swimming)) |
232 ($gliding !==
null && !$this->player->toggleGlide($gliding)) |
233 ($flying !==
null && !$this->player->toggleFlight($flying));
234 if((
bool) $mismatch){
235 $this->player->sendData([$this->player]);
239 $this->player->jump();
242 $this->player->missSwing();
246 if(!$this->forceMoveSync && $hasMoved){
247 $this->lastPlayerAuthInputPosition = $rawPos;
249 $this->player->handleMovement($newPos);
252 $packetHandled =
true;
254 $useItemTransaction = $packet->getItemInteractionData();
255 if($useItemTransaction !==
null){
256 if(count($useItemTransaction->getTransactionData()->getActions()) > 100){
260 $this->inventoryManager->setCurrentItemStackRequestId($useItemTransaction->getRequestId());
261 $this->inventoryManager->addRawPredictedSlotChanges($useItemTransaction->getTransactionData()->getActions());
262 if(!$this->handleUseItemTransaction($useItemTransaction->getTransactionData())){
263 $packetHandled =
false;
264 $this->session->getLogger()->debug(
"Unhandled transaction in PlayerAuthInputPacket (type " . $useItemTransaction->getTransactionData()->getActionType() .
")");
266 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
268 $this->inventoryManager->setCurrentItemStackRequestId(
null);
271 $itemStackRequest = $packet->getItemStackRequest();
272 $itemStackResponseBuilder = $itemStackRequest !==
null ? $this->handleSingleItemStackRequest($itemStackRequest) :
null;
276 $blockActions = $packet->getBlockActions();
277 if($blockActions !==
null){
278 if(count($blockActions) > 100){
281 foreach(Utils::promoteKeys($blockActions) as $k => $blockAction){
282 $actionHandled =
false;
284 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(),
new BlockPosition(0, 0, 0), Facing::DOWN);
286 $actionHandled = $this->handlePlayerActionFromData($blockAction->getActionType(), $blockAction->getBlockPosition(), $blockAction->getFace());
290 $packetHandled =
false;
291 $this->session->getLogger()->debug(
"Unhandled player block action at offset $k in PlayerAuthInputPacket");
296 if($itemStackRequest !==
null){
297 $itemStackResponse = $itemStackResponseBuilder?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $itemStackRequest->getRequestId());
301 return $packetHandled;
311 if(count($packet->trData->getActions()) > 50){
314 if(count($packet->requestChangedSlots) > 10){
318 $this->inventoryManager->setCurrentItemStackRequestId($packet->requestId);
319 $this->inventoryManager->addRawPredictedSlotChanges($packet->trData->getActions());
322 $result = $this->handleNormalTransaction($packet->trData, $packet->requestId);
324 $this->session->getLogger()->debug(
"Mismatch transaction received");
325 $this->inventoryManager->requestSyncAll();
328 $result = $this->handleUseItemTransaction($packet->trData);
330 $result = $this->handleUseItemOnEntityTransaction($packet->trData);
332 $result = $this->handleReleaseItemTransaction($packet->trData);
335 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
341 foreach($packet->requestChangedSlots as $containerInfo){
342 foreach($containerInfo->getChangedSlotIndexes() as $netSlot){
344 $inventoryAndSlot = $this->inventoryManager->locateWindowAndSlot($windowId, $slot);
345 if($inventoryAndSlot !==
null){
346 $this->inventoryManager->onSlotChange($inventoryAndSlot[0], $inventoryAndSlot[1]);
351 $this->inventoryManager->setCurrentItemStackRequestId(
null);
355 private function executeInventoryTransaction(
InventoryTransaction $transaction,
int $requestId) :
bool{
356 $this->player->setUsingItem(
false);
358 $this->inventoryManager->setCurrentItemStackRequestId($requestId);
359 $this->inventoryManager->addTransactionPredictedSlotChanges($transaction);
363 $this->inventoryManager->requestSyncAll();
364 $logger = $this->session->getLogger();
365 $logger->debug(
"Invalid inventory transaction $requestId: " . $e->getMessage());
369 $this->session->getLogger()->debug(
"Inventory transaction $requestId cancelled by a plugin");
373 $this->inventoryManager->syncMismatchedPredictedSlotChanges();
374 $this->inventoryManager->setCurrentItemStackRequestId(
null);
380 private function handleNormalTransaction(
NormalTransactionData $data,
int $itemStackRequestId) :
bool{
387 if($actionCount > 2){
388 if($actionCount > 5){
394 $this->session->getLogger()->debug(
"Ignoring normal inventory transaction with $actionCount actions (drop-item should have exactly 2 actions)");
399 $clientItemStack =
null;
400 $droppedCount =
null;
402 foreach($data->
getActions() as $networkInventoryAction){
403 if($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_WORLD && $networkInventoryAction->inventorySlot === NetworkInventoryAction::ACTION_MAGIC_SLOT_DROP_ITEM){
404 $droppedCount = $networkInventoryAction->newItem->getItemStack()->getCount();
405 if($droppedCount <= 0){
408 }elseif($networkInventoryAction->sourceType === NetworkInventoryAction::SOURCE_CONTAINER && $networkInventoryAction->windowId === ContainerIds::INVENTORY){
410 $sourceSlot = $networkInventoryAction->inventorySlot;
411 $clientItemStack = $networkInventoryAction->oldItem->getItemStack();
413 $this->session->getLogger()->debug(
"Unexpected inventory action type $networkInventoryAction->sourceType in drop item transaction");
417 if($sourceSlot ===
null || $clientItemStack ===
null || $droppedCount ===
null){
418 $this->session->getLogger()->debug(
"Missing information in drop item transaction, need source slot, client item stack and dropped count");
422 $inventory = $this->player->getInventory();
424 if(!$inventory->slotExists($sourceSlot)){
428 $sourceSlotItem = $inventory->getItem($sourceSlot);
429 if($sourceSlotItem->getCount() < $droppedCount){
432 $serverItemStack = $this->session->getTypeConverter()->coreItemStackToNet($sourceSlotItem);
436 $serverItemStack->getId() !== $clientItemStack->getId() ||
437 $serverItemStack->getMeta() !== $clientItemStack->getMeta() ||
438 $serverItemStack->getCount() !== $clientItemStack->getCount() ||
439 $serverItemStack->getBlockRuntimeId() !== $clientItemStack->getBlockRuntimeId()
449 $droppedItem = $sourceSlotItem->pop($droppedCount);
452 $builder->getInventory($inventory)->setItem($sourceSlot, $sourceSlotItem);
456 return $this->executeInventoryTransaction($transaction, $itemStackRequestId);
460 $this->player->selectHotbarSlot($data->getHotbarSlot());
462 switch($data->getActionType()){
463 case UseItemTransactionData::ACTION_CLICK_BLOCK:
465 $clickPos = $data->getClickPosition();
466 $spamBug = ($this->lastRightClickData !==
null &&
467 microtime(
true) - $this->lastRightClickTime < 0.1 &&
468 $this->lastRightClickData->getPlayerPosition()->distanceSquared($data->getPlayerPosition()) < 0.00001 &&
469 $this->lastRightClickData->getBlockPosition()->equals($data->getBlockPosition()) &&
470 $this->lastRightClickData->getClickPosition()->distanceSquared($clickPos) < 0.00001
473 $this->lastRightClickData = $data;
474 $this->lastRightClickTime = microtime(
true);
480 self::validateFacing($data->getFace());
482 $blockPos = $data->getBlockPosition();
483 $vBlockPos =
new Vector3($blockPos->getX(), $blockPos->getY(), $blockPos->getZ());
484 $this->player->interactBlock($vBlockPos, $data->getFace(), $clickPos);
485 if($data->getClientInteractPrediction() === PredictedResult::SUCCESS){
493 $syncAdjacentFace =
null;
494 if($data->getItemInHand()->getItemStack()->getBlockRuntimeId() === ItemTranslator::NO_BLOCK_RUNTIME_ID){
495 $this->session->getLogger()->debug(
"Placing held item might place multiple blocks client-side; doing full adjacent sync");
496 $syncAdjacentFace = $data->getFace();
498 $this->syncBlocksNearby($vBlockPos, $syncAdjacentFace);
501 case UseItemTransactionData::ACTION_CLICK_AIR:
502 if($this->player->isUsingItem()){
503 if(!$this->player->consumeHeldItem()){
504 $hungerAttr = $this->player->getAttributeMap()->get(Attribute::HUNGER) ??
throw new AssumptionFailedError();
505 $hungerAttr->markSynchronized(
false);
510 $this->player->setUsingItem(
false);
513 $this->player->useHeldItem();
523 private static function validateFacing(
int $facing) :
void{
524 if(!in_array($facing, Facing::ALL,
true)){
532 private function syncBlocksNearby(
Vector3 $blockPos, ?
int $face) :
void{
533 if($blockPos->distanceSquared($this->player->getLocation()) < 10000){
536 $sidePos = $blockPos->
getSide($face);
539 array_push($blocks, ...$sidePos->sidesArray());
541 $blocks[] = $blockPos;
543 foreach($this->player->getWorld()->createBlockUpdatePackets($blocks) as $packet){
544 $this->session->sendDataPacket($packet);
550 $target = $this->player->getWorld()->getEntity($data->getActorRuntimeId());
553 if($target ===
null || $target->isFlaggedForDespawn()){
557 $this->player->selectHotbarSlot($data->getHotbarSlot());
559 switch($data->getActionType()){
560 case UseItemOnEntityTransactionData::ACTION_INTERACT:
561 $this->player->interactEntity($target, $data->getClickPosition());
563 case UseItemOnEntityTransactionData::ACTION_ATTACK:
564 $this->player->attackEntity($target);
572 $this->player->selectHotbarSlot($data->getHotbarSlot());
574 if($data->getActionType() === ReleaseItemTransactionData::ACTION_RELEASE){
575 $this->player->releaseHeldItem();
598 $transaction = $executor->generateInventoryTransaction();
599 if($transaction !==
null){
600 $result = $this->executeInventoryTransaction($transaction, $request->getRequestId());
606 $this->session->getLogger()->debug(
"ItemStackRequest #" . $request->getRequestId() .
" failed: " . $e->getMessage());
607 $this->session->getLogger()->debug(implode(
"\n", Utils::printableExceptionInfo($e)));
608 $this->inventoryManager->requestSyncAll();
611 return $result ? $executor->getItemStackResponseBuilder() :
null;
616 if(count($packet->getRequests()) > 80){
620 foreach($packet->getRequests() as $request){
621 $responses[] = $this->handleSingleItemStackRequest($request)?->build() ??
new ItemStackResponse(ItemStackResponse::RESULT_ERROR, $request->getRequestId());
630 if($packet->windowId === ContainerIds::OFFHAND){
633 if($packet->windowId === ContainerIds::INVENTORY){
634 $this->inventoryManager->onClientSelectHotbarSlot($packet->hotbarSlot);
635 if(!$this->player->selectHotbarSlot($packet->hotbarSlot)){
636 $this->inventoryManager->syncSelectedHotbarSlot();
648 if($packet->action === InteractPacket::ACTION_MOUSEOVER){
656 $target = $this->player->getWorld()->getEntity($packet->targetActorRuntimeId);
657 if($target ===
null){
660 if($packet->action === InteractPacket::ACTION_OPEN_INVENTORY && $target === $this->player){
661 $this->inventoryManager->onClientOpenMainInventory();
668 return $this->player->pickBlock(
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ()), $packet->addUserData);
672 return $this->player->pickEntity($packet->actorUniqueId);
676 return $this->handlePlayerActionFromData($packet->action, $packet->blockPosition, $packet->face);
679 private function handlePlayerActionFromData(
int $action,
BlockPosition $blockPosition,
int $face) :
bool{
680 $pos =
new Vector3($blockPosition->getX(), $blockPosition->getY(), $blockPosition->getZ());
683 case PlayerAction::START_BREAK:
684 case PlayerAction::CONTINUE_DESTROY_BLOCK:
685 self::validateFacing($face);
686 if($this->lastBlockAttacked !==
null && $blockPosition->equals($this->lastBlockAttacked)){
691 $this->session->getLogger()->debug(
"Ignoring PlayerAction $action on $pos because we were already destroying this block");
694 if(!$this->player->attackBlock($pos, $face)){
695 $this->syncBlocksNearby($pos, $face);
697 $this->lastBlockAttacked = $blockPosition;
701 case PlayerAction::ABORT_BREAK:
702 case PlayerAction::STOP_BREAK:
703 $this->player->stopBreakBlock($pos);
704 $this->lastBlockAttacked =
null;
706 case PlayerAction::START_SLEEPING:
709 case PlayerAction::STOP_SLEEPING:
710 $this->player->stopSleep();
712 case PlayerAction::CRACK_BREAK:
713 self::validateFacing($face);
714 $this->player->continueBreakBlock($pos, $face);
715 $this->lastBlockAttacked = $blockPosition;
717 case PlayerAction::INTERACT_BLOCK:
719 case PlayerAction::CREATIVE_PLAYER_DESTROY_BLOCK:
722 case PlayerAction::PREDICT_DESTROY_BLOCK:
723 self::validateFacing($face);
724 if(!$this->player->breakBlock($pos)){
725 $this->syncBlocksNearby($pos, $face);
727 $this->lastBlockAttacked =
null;
729 case PlayerAction::START_ITEM_USE_ON:
730 case PlayerAction::STOP_ITEM_USE_ON:
734 $this->session->getLogger()->debug(
"Unhandled/unknown player action type " . $action);
738 $this->player->setUsingItem(
false);
754 $this->inventoryManager->onClientRemoveWindow($packet->windowId);
766 $textTag = $nbt->
getTag($tagName);
768 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textTag) .
" for tag \"$tagName\" in sign update data");
770 $textBlobTag = $textTag->getTag(Sign::TAG_TEXT_BLOB);
772 throw new PacketHandlingException(
"Invalid tag type " . get_debug_type($textBlobTag) .
" for tag \"" . Sign::TAG_TEXT_BLOB .
"\" in sign update data");
776 $text = SignText::fromBlob($textBlobTag->getValue());
777 }
catch(\InvalidArgumentException $e){
778 throw PacketHandlingException::wrap($e,
"Invalid sign text update");
781 $oldText = $block->getFaceText($frontFace);
782 if($text->getLines() === $oldText->getLines()){
788 foreach($this->player->getWorld()->createBlockUpdatePackets([$pos]) as $updatePacket){
789 $this->session->sendDataPacket($updatePacket);
794 }
catch(\UnexpectedValueException $e){
795 throw PacketHandlingException::wrap($e);
800 $pos =
new Vector3($packet->blockPosition->getX(), $packet->blockPosition->getY(), $packet->blockPosition->getZ());
801 if($pos->distanceSquared($this->player->getLocation()) > 10000){
805 $block = $this->player->getLocation()->getWorld()->getBlock($pos);
806 $nbt = $packet->nbt->getRoot();
810 if(!$this->updateSignText($nbt, Sign::TAG_FRONT_TEXT,
true, $block, $pos)){
812 $this->updateSignText($nbt, Sign::TAG_BACK_TEXT,
false, $block, $pos);
822 $gameMode = $this->session->getTypeConverter()->protocolGameModeToCore($packet->gamemode);
823 if($gameMode !== $this->player->getGamemode()){
825 $this->session->syncGameMode($this->player->getGamemode(),
true);
839 $this->player->setViewDistance($packet->radius);
853 if(str_starts_with($packet->command,
'/')){
854 $this->player->chat($packet->command);
865 if($packet->skin->getFullSkinId() === $this->lastRequestedFullSkinId){
868 $this->session->getLogger()->debug(
"Refused duplicate skin change request");
871 $this->lastRequestedFullSkinId = $packet->skin->getFullSkinId();
873 $this->session->getLogger()->debug(
"Processing skin change request");
875 $skin = $this->session->getTypeConverter()->getSkinAdapter()->fromSkinData($packet->skin);
877 throw PacketHandlingException::wrap($e,
"Invalid skin in PlayerSkinPacket");
879 return $this->player->changeSkin($skin, $packet->newSkinName, $packet->oldSkinName);
889 private function checkBookText(
string $string,
string $fieldName,
int $softLimit,
int $hardLimit,
bool &$cancel) :
string{
890 if(strlen($string) > $hardLimit){
891 throw new PacketHandlingException(sprintf(
"Book %s must be at most %d bytes, but have %d bytes", $fieldName, $hardLimit, strlen($string)));
894 $result = TextFormat::clean($string,
false);
896 if(strlen($result) > $softLimit * 4 || mb_strlen($result,
'UTF-8') > $softLimit){
898 $this->session->getLogger()->debug(
"Cancelled book edit due to $fieldName exceeded soft limit of $softLimit chars");
905 $inventory = $this->player->getInventory();
906 if(!$inventory->slotExists($packet->inventorySlot)){
910 $oldBook = $inventory->getItem($packet->inventorySlot);
915 $newBook = clone $oldBook;
918 switch($packet->type){
919 case BookEditPacket::TYPE_REPLACE_PAGE:
920 $text = self::checkBookText($packet->text,
"page text", 256, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
921 $newBook->setPageText($packet->pageNumber, $text);
922 $modifiedPages[] = $packet->pageNumber;
924 case BookEditPacket::TYPE_ADD_PAGE:
925 if(!$newBook->pageExists($packet->pageNumber)){
930 $text = self::checkBookText($packet->text,
"page text", 256, WritableBookPage::PAGE_LENGTH_HARD_LIMIT_BYTES, $cancel);
931 $newBook->insertPage($packet->pageNumber, $text);
932 $modifiedPages[] = $packet->pageNumber;
934 case BookEditPacket::TYPE_DELETE_PAGE:
935 if(!$newBook->pageExists($packet->pageNumber)){
938 $newBook->deletePage($packet->pageNumber);
939 $modifiedPages[] = $packet->pageNumber;
941 case BookEditPacket::TYPE_SWAP_PAGES:
942 if(!$newBook->pageExists($packet->pageNumber) || !$newBook->pageExists($packet->secondaryPageNumber)){
944 $newBook->addPage(max($packet->pageNumber, $packet->secondaryPageNumber));
946 $newBook->swapPages($packet->pageNumber, $packet->secondaryPageNumber);
947 $modifiedPages = [$packet->pageNumber, $packet->secondaryPageNumber];
949 case BookEditPacket::TYPE_SIGN_BOOK:
950 $title = self::checkBookText($packet->title,
"title", 16, Limits::INT16_MAX, $cancel);
952 $author = self::checkBookText($packet->author,
"author", 256, Limits::INT16_MAX, $cancel);
954 $newBook = VanillaItems::WRITTEN_BOOK()
955 ->setPages($oldBook->getPages())
958 ->setGeneration(WrittenBook::GENERATION_ORIGINAL);
965 $action = match($packet->type){
966 BookEditPacket::TYPE_REPLACE_PAGE => PlayerEditBookEvent::ACTION_REPLACE_PAGE,
967 BookEditPacket::TYPE_ADD_PAGE => PlayerEditBookEvent::ACTION_ADD_PAGE,
968 BookEditPacket::TYPE_DELETE_PAGE => PlayerEditBookEvent::ACTION_DELETE_PAGE,
969 BookEditPacket::TYPE_SWAP_PAGES => PlayerEditBookEvent::ACTION_SWAP_PAGES,
970 BookEditPacket::TYPE_SIGN_BOOK => PlayerEditBookEvent::ACTION_SIGN_BOOK,
978 $oldPageCount = count($oldBook->getPages());
979 $newPageCount = count($newBook->getPages());
980 if(($newPageCount > $oldPageCount && $newPageCount > 50)){
981 $this->session->getLogger()->debug(
"Cancelled book edit due to adding too many pages (new page count would be $newPageCount)");
985 $event =
new PlayerEditBookEvent($this->player, $oldBook, $newBook, $action, $modifiedPages);
991 if($event->isCancelled()){
995 $this->player->getInventory()->setItem($packet->inventorySlot, $event->getNewBook());
1001 if($packet->cancelReason !==
null){
1003 return $this->player->onFormSubmit($packet->formId,
null);
1004 }elseif($packet->formData !==
null){
1005 if(strlen($packet->formData) > self::MAX_FORM_RESPONSE_SIZE){
1006 throw new PacketHandlingException(
"Form response data too large, refusing to decode (received" . strlen($packet->formData) .
" bytes, max " . self::MAX_FORM_RESPONSE_SIZE .
" bytes)");
1008 if(!$this->player->hasPendingForm($packet->formId)){
1009 $this->session->getLogger()->debug(
"Got unexpected response for form $packet->formId");
1013 $responseData = json_decode($packet->formData,
true, self::MAX_FORM_RESPONSE_DEPTH, JSON_THROW_ON_ERROR);
1014 }
catch(\JsonException $e){
1015 throw PacketHandlingException::wrap($e,
"Failed to decode form response data");
1017 return $this->player->onFormSubmit($packet->formId, $responseData);
1019 throw new PacketHandlingException(
"Expected either formData or cancelReason to be set in ModalFormResponsePacket");
1032 $pos = $packet->blockPosition;
1033 $chunkX = $pos->getX() >> Chunk::COORD_BIT_SIZE;
1034 $chunkZ = $pos->getZ() >> Chunk::COORD_BIT_SIZE;
1035 $world = $this->player->getWorld();
1036 if(!$world->isChunkLoaded($chunkX, $chunkZ) || $world->isChunkLocked($chunkX, $chunkZ)){
1040 $lectern = $world->getBlockAt($pos->getX(), $pos->getY(), $pos->getZ());
1041 if($lectern instanceof
Lectern && $this->player->canInteract($lectern->getPosition(), 15)){
1042 if(!$lectern->onPageTurn($packet->page)){
1043 $this->syncBlocksNearby($lectern->getPosition(),
null);
1065 public function handleEmote(
EmotePacket $packet) :
bool{
1066 $this->player->emote($packet->getEmoteId());