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