PocketMine-MP 5.19.1 git-5cc1068cd43264d3363295eb8d6901e02f467897
Note.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;
25
26use pocketmine\block\tile\Note as TileNote;
27use function assert;
28
29class Note extends Opaque{
30 public const MIN_PITCH = 0;
31 public const MAX_PITCH = 24;
32
33 private int $pitch = self::MIN_PITCH;
34
35 public function readStateFromWorld() : Block{
36 parent::readStateFromWorld();
37 $tile = $this->position->getWorld()->getTile($this->position);
38 if($tile instanceof TileNote){
39 $this->pitch = $tile->getPitch();
40 }else{
41 $this->pitch = self::MIN_PITCH;
42 }
43
44 return $this;
45 }
46
47 public function writeStateToWorld() : void{
48 parent::writeStateToWorld();
49 $tile = $this->position->getWorld()->getTile($this->position);
50 assert($tile instanceof TileNote);
51 $tile->setPitch($this->pitch);
52 }
53
54 public function getFuelTime() : int{
55 return 300;
56 }
57
58 public function getPitch() : int{
59 return $this->pitch;
60 }
61
63 public function setPitch(int $pitch) : self{
64 if($pitch < self::MIN_PITCH || $pitch > self::MAX_PITCH){
65 throw new \InvalidArgumentException("Pitch must be in range " . self::MIN_PITCH . " - " . self::MAX_PITCH);
66 }
67 $this->pitch = $pitch;
68 return $this;
69 }
70
71 //TODO
72}
setPitch(int $pitch)
Definition: Note.php:63