PocketMine-MP 5.18.1 git-9381fc4172e5dce4cada1cb356050c8a2ab57b94
BlockStateUpgradeSchemaBlockRemap.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\data\bedrock\block\upgrade;
25
28use function array_diff;
29use function count;
30
41 public function __construct(
42 public array $oldState,
43 public string|BlockStateUpgradeSchemaFlattenedName $newName,
44 public array $newState,
45 public array $copiedState
46 ){}
47
48 public function equals(self $that) : bool{
49 $sameName = $this->newName === $that->newName ||
50 (
51 $this->newName instanceof BlockStateUpgradeSchemaFlattenedName &&
52 $that->newName instanceof BlockStateUpgradeSchemaFlattenedName &&
53 $this->newName->equals($that->newName)
54 );
55 if(!$sameName){
56 return false;
57 }
58
59 if(
60 count($this->oldState) !== count($that->oldState) ||
61 count($this->newState) !== count($that->newState) ||
62 count($this->copiedState) !== count($that->copiedState) ||
63 count(array_diff($this->copiedState, $that->copiedState)) !== 0
64 ){
65 return false;
66 }
67 foreach(Utils::stringifyKeys($this->oldState) as $propertyName => $propertyValue){
68 if(!isset($that->oldState[$propertyName]) || !$that->oldState[$propertyName]->equals($propertyValue)){
69 //different filter value
70 return false;
71 }
72 }
73 foreach(Utils::stringifyKeys($this->newState) as $propertyName => $propertyValue){
74 if(!isset($that->newState[$propertyName]) || !$that->newState[$propertyName]->equals($propertyValue)){
75 //different replacement value
76 return false;
77 }
78 }
79
80 return true;
81 }
82}
__construct(public array $oldState, public string|BlockStateUpgradeSchemaFlattenedName $newName, public array $newState, public array $copiedState)
static stringifyKeys(array $array)
Definition: Utils.php:605