PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
tile/MobHead.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
26use pocketmine\block\utils\MobHeadType;
31
36class MobHead extends Spawnable{
37
38 private const TAG_SKULL_TYPE = "SkullType"; //TAG_Byte
39 private const TAG_ROT = "Rot"; //TAG_Byte
40 private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte
41 private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int
42
43 private MobHeadType $mobHeadType = MobHeadType::SKELETON;
44 private int $rotation = 0;
45
46 public function readSaveData(CompoundTag $nbt) : void{
47 if(($skullTypeTag = $nbt->getTag(self::TAG_SKULL_TYPE)) instanceof ByteTag){
48 $mobHeadType = MobHeadTypeIdMap::getInstance()->fromId($skullTypeTag->getValue());
49 if($mobHeadType === null){
50 throw new SavedDataLoadingException("Invalid skull type tag value " . $skullTypeTag->getValue());
51 }
52 $this->mobHeadType = $mobHeadType;
53 }
54 $rotation = $nbt->getByte(self::TAG_ROT, 0);
55 if($rotation >= 0 && $rotation <= 15){
56 $this->rotation = $rotation;
57 }
58 }
59
60 protected function writeSaveData(CompoundTag $nbt) : void{
61 $nbt->setByte(self::TAG_SKULL_TYPE, MobHeadTypeIdMap::getInstance()->toId($this->mobHeadType));
62 $nbt->setByte(self::TAG_ROT, $this->rotation);
63 }
64
65 public function setMobHeadType(MobHeadType $type) : void{
66 $this->mobHeadType = $type;
67 }
68
69 public function getMobHeadType() : MobHeadType{
70 return $this->mobHeadType;
71 }
72
73 public function getRotation() : int{
74 return $this->rotation;
75 }
76
77 public function setRotation(int $rotation) : void{
78 $this->rotation = $rotation;
79 }
80
81 protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
82 $nbt->setByte(self::TAG_SKULL_TYPE, MobHeadTypeIdMap::getInstance()->toId($this->mobHeadType));
83 $nbt->setByte(self::TAG_ROT, $this->rotation);
84 }
85}
addAdditionalSpawnData(CompoundTag $nbt)
writeSaveData(CompoundTag $nbt)
setByte(string $name, int $value)