PocketMine-MP 5.33.2 git-919492bdcad8510eb6606439eb77e1c604f1d1ea
Loading...
Searching...
No Matches
tile/Bell.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\tile;
25
33
34final class Bell extends Spawnable{
35 public const TAG_DIRECTION = "Direction"; //TAG_Int
36 public const TAG_RINGING = "Ringing"; //TAG_Byte
37 public const TAG_TICKS = "Ticks"; //TAG_Int
38
39 private bool $ringing = false;
40 private Facing $facing = Facing::NORTH;
41 private int $ticks = 0;
42
43 public function isRinging() : bool{ return $this->ringing; }
44
45 public function setRinging(bool $ringing) : void{ $this->ringing = $ringing; }
46
47 public function getFacing() : Facing{ return $this->facing; }
48
49 public function setFacing(Facing $facing) : void{ $this->facing = $facing; }
50
51 public function getTicks() : int{ return $this->ticks; }
52
53 public function setTicks(int $ticks) : void{ $this->ticks = $ticks; }
54
55 protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
56 $nbt->setByte(self::TAG_RINGING, $this->ringing ? 1 : 0);
57 //TODO: suspicious use of internal Facing value for network
58 $nbt->setInt(self::TAG_DIRECTION, $this->facing->value);
59 $nbt->setInt(self::TAG_TICKS, $this->ticks);
60 }
61
62 public function readSaveData(CompoundTag $nbt) : void{
63 $this->ringing = $nbt->getByte(self::TAG_RINGING, 0) !== 0;
64 //TODO: suspicious use of internal Facing value for storage
65 $this->facing = Facing::tryFrom($nbt->getInt(self::TAG_DIRECTION, Facing::NORTH->value)) ?? throw new SavedDataLoadingException("Invalid facing value");
66 $this->ticks = $nbt->getInt(self::TAG_TICKS, 0);
67 }
68
69 protected function writeSaveData(CompoundTag $nbt) : void{
70 $nbt->setByte(self::TAG_RINGING, $this->ringing ? 1 : 0);
71 //TODO: suspicious use of internal Facing value for storage
72 $nbt->setInt(self::TAG_DIRECTION, $this->facing->value);
73 $nbt->setInt(self::TAG_TICKS, $this->ticks);
74 }
75
84 public function createFakeUpdatePacket(Facing $bellHitFace) : BlockActorDataPacket{
85 $nbt = $this->getSpawnCompound();
86 $nbt->setByte(self::TAG_RINGING, 1);
87 $nbt->setInt(self::TAG_DIRECTION, match($bellHitFace){
88 Facing::SOUTH => 0,
89 Facing::WEST => 1,
90 Facing::NORTH => 2,
91 Facing::EAST => 3,
92 default => throw new AssumptionFailedError("Unreachable")
93 });
94 $nbt->setInt(self::TAG_TICKS, 0);
95 return BlockActorDataPacket::create(BlockPosition::fromVector3($this->position), new CacheableNbt($nbt));
96 }
97}
addAdditionalSpawnData(CompoundTag $nbt)
Definition tile/Bell.php:55
writeSaveData(CompoundTag $nbt)
Definition tile/Bell.php:69
createFakeUpdatePacket(Facing $bellHitFace)
Definition tile/Bell.php:84
setByte(string $name, int $value)
setInt(string $name, int $value)