PocketMine-MP 5.21.2 git-a6534ecbbbcf369264567d27e5ed70f7f5be9816
Loading...
Searching...
No Matches
MapInfoRequestPacketClientPixel.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
19use function intdiv;
20
22
23 private const Y_INDEX_MULTIPLIER = 128;
24
25 public function __construct(
26 public Color $color,
27 public int $x,
28 public int $y
29 ){}
30
31 public function getColor() : Color{ return $this->color; }
32
33 public function getX() : int{ return $this->x; }
34
35 public function getY() : int{ return $this->y; }
36
37 public static function read(PacketSerializer $in) : self{
38 $color = $in->getLInt();
39 $index = $in->getLShort();
40
41 $x = $index % self::Y_INDEX_MULTIPLIER;
42 $y = intdiv($index, self::Y_INDEX_MULTIPLIER);
43
44 return new self(Color::fromRGBA($color), $x, $y);
45 }
46
47 public function write(PacketSerializer $out) : void{
48 $out->putLInt($this->color->toRGBA());
49 $out->putLShort($this->x + ($this->y * self::Y_INDEX_MULTIPLIER));
50 }
51}