PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
MultiAnyFacingTrait.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block\utils;
25
28use function spl_object_id;
29
33trait MultiAnyFacingTrait{
34
36 protected array $faces = [];
37
38 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
39 $w->enumSet($this->faces, Facing::cases());
40 }
41
43 public function getFaces() : array{ return $this->faces; }
44
45 public function hasFace(Facing $face) : bool{
46 return isset($this->faces[spl_object_id($face)]);
47 }
48
53 public function setFaces(array $faces) : self{
54 $uniqueFaces = [];
55 foreach($faces as $face){
56 $uniqueFaces[spl_object_id($face)] = $face;
57 }
58 $this->faces = $uniqueFaces;
59 return $this;
60 }
61
63 public function setFace(Facing $face, bool $value) : self{
64 if($value){
65 $this->faces[spl_object_id($face)] = $face;
66 }else{
67 unset($this->faces[spl_object_id($face)]);
68 }
69 return $this;
70 }
71}