PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
CommandBlockUpdatePacket.php
1<?php
2
3/*
4 * This file is part of BedrockProtocol.
5 * Copyright (C) 2014-2022 PocketMine Team <https://github.com/pmmp/BedrockProtocol>
6 *
7 * BedrockProtocol is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 */
12
13declare(strict_types=1);
14
15namespace pocketmine\network\mcpe\protocol;
16
19
21 public const NETWORK_ID = ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET;
22
23 public bool $isBlock;
24
25 public BlockPosition $blockPosition;
26 public int $commandBlockMode;
27 public bool $isRedstoneMode;
28 public bool $isConditional;
29
30 public int $minecartActorRuntimeId;
31
32 public string $command;
33 public string $lastOutput;
34 public string $name;
35 public bool $shouldTrackOutput;
36 public int $tickDelay;
37 public bool $executeOnFirstTick;
38
39 protected function decodePayload(PacketSerializer $in) : void{
40 $this->isBlock = $in->getBool();
41
42 if($this->isBlock){
43 $this->blockPosition = $in->getBlockPosition();
44 $this->commandBlockMode = $in->getUnsignedVarInt();
45 $this->isRedstoneMode = $in->getBool();
46 $this->isConditional = $in->getBool();
47 }else{
48 //Minecart with command block
49 $this->minecartActorRuntimeId = $in->getActorRuntimeId();
50 }
51
52 $this->command = $in->getString();
53 $this->lastOutput = $in->getString();
54 $this->name = $in->getString();
55
56 $this->shouldTrackOutput = $in->getBool();
57 $this->tickDelay = $in->getLInt();
58 $this->executeOnFirstTick = $in->getBool();
59 }
60
61 protected function encodePayload(PacketSerializer $out) : void{
62 $out->putBool($this->isBlock);
63
64 if($this->isBlock){
65 $out->putBlockPosition($this->blockPosition);
66 $out->putUnsignedVarInt($this->commandBlockMode);
67 $out->putBool($this->isRedstoneMode);
68 $out->putBool($this->isConditional);
69 }else{
70 $out->putActorRuntimeId($this->minecartActorRuntimeId);
71 }
72
73 $out->putString($this->command);
74 $out->putString($this->lastOutput);
75 $out->putString($this->name);
76
77 $out->putBool($this->shouldTrackOutput);
78 $out->putLInt($this->tickDelay);
79 $out->putBool($this->executeOnFirstTick);
80 }
81
82 public function handle(PacketHandlerInterface $handler) : bool{
83 return $handler->handleCommandBlockUpdate($this);
84 }
85}