PocketMine-MP 5.42.1 git-443151900a14fe9dc682cbf786fa441be1294fab
Loading...
Searching...
No Matches
AttributeValueColor.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\types;
16
17use pmmp\encoding\ByteBufferReader;
18use pmmp\encoding\ByteBufferWriter;
19use pmmp\encoding\VarInt;
22
27 public const ID = AttributeValueType::COLOR;
28
29 public const OPERATION_OVERRIDE = "override";
30 public const OPERATION_ALPHA_BLEND = "alpha_blend";
31 public const OPERATION_ADD = "add";
32 public const OPERATION_SUBTRACT = "subtract";
33 public const OPERATION_MULTIPLY = "multiply";
34
35 public function __construct(
36 private AttributeValueColorValue $value,
37 private string $operation,
38 ){}
39
40 public function getTypeId() : int{
41 return self::ID;
42 }
43
44 public function getValue() : AttributeValueColorValue{ return $this->value; }
45
46 public function getOperation() : string{ return $this->operation; }
47
48 public static function read(ByteBufferReader $in) : self{
49 $value = match(VarInt::readUnsignedInt($in)){
50 AttributeValueColorArray::ID => AttributeValueColorArray::read($in),
51 AttributeValueColorString::ID => AttributeValueColorString::read($in),
52 default => throw new PacketDecodeException("Unknown AttributeValueColor type"),
53 };
54 $operation = CommonTypes::getString($in);
55
56 return new self(
57 $value,
58 $operation
59 );
60 }
61
62 public function write(ByteBufferWriter $out) : void{
63 VarInt::writeUnsignedInt($out, $this->value->getTypeId());
64 $this->value->write($out);
65 CommonTypes::putString($out, $this->operation);
66 }
67}