PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
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
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\LE;
20use pmmp\encoding\VarInt;
23
25 public const NETWORK_ID = ProtocolInfo::COMMAND_BLOCK_UPDATE_PACKET;
26
27 public bool $isBlock;
28
29 public BlockPosition $blockPosition;
30 public int $commandBlockMode;
31 public bool $isRedstoneMode;
32 public bool $isConditional;
33
34 public int $minecartActorRuntimeId;
35
36 public string $command;
37 public string $lastOutput;
38 public string $name;
39 public string $filteredName;
40 public bool $shouldTrackOutput;
41 public int $tickDelay;
42 public bool $executeOnFirstTick;
43
44 protected function decodePayload(ByteBufferReader $in) : void{
45 $this->isBlock = CommonTypes::getBool($in);
46
47 if($this->isBlock){
48 $this->blockPosition = CommonTypes::getBlockPosition($in);
49 $this->commandBlockMode = VarInt::readUnsignedInt($in);
50 $this->isRedstoneMode = CommonTypes::getBool($in);
51 $this->isConditional = CommonTypes::getBool($in);
52 }else{
53 //Minecart with command block
54 $this->minecartActorRuntimeId = CommonTypes::getActorRuntimeId($in);
55 }
56
57 $this->command = CommonTypes::getString($in);
58 $this->lastOutput = CommonTypes::getString($in);
59 $this->name = CommonTypes::getString($in);
60 $this->filteredName = CommonTypes::getString($in);
61 $this->shouldTrackOutput = CommonTypes::getBool($in);
62 $this->tickDelay = LE::readUnsignedInt($in);
63 $this->executeOnFirstTick = CommonTypes::getBool($in);
64 }
65
66 protected function encodePayload(ByteBufferWriter $out) : void{
67 CommonTypes::putBool($out, $this->isBlock);
68
69 if($this->isBlock){
70 CommonTypes::putBlockPosition($out, $this->blockPosition);
71 VarInt::writeUnsignedInt($out, $this->commandBlockMode);
72 CommonTypes::putBool($out, $this->isRedstoneMode);
73 CommonTypes::putBool($out, $this->isConditional);
74 }else{
75 CommonTypes::putActorRuntimeId($out, $this->minecartActorRuntimeId);
76 }
77
78 CommonTypes::putString($out, $this->command);
79 CommonTypes::putString($out, $this->lastOutput);
80 CommonTypes::putString($out, $this->name);
81 CommonTypes::putString($out, $this->filteredName);
82 CommonTypes::putBool($out, $this->shouldTrackOutput);
83 LE::writeUnsignedInt($out, $this->tickDelay);
84 CommonTypes::putBool($out, $this->executeOnFirstTick);
85 }
86
87 public function handle(PacketHandlerInterface $handler) : bool{
88 return $handler->handleCommandBlockUpdate($this);
89 }
90}