PocketMine-MP 5.39.4 git-a2b7d660558310260c376d1eeaff549367b9fc6e
Loading...
Searching...
No Matches
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;
32use function floor;
33
38class MobHead extends Spawnable{
39
40 private const TAG_SKULL_TYPE = "SkullType"; //TAG_Byte
41 private const TAG_ROTATION = "Rotation"; //TAG_Float (1.10+, represents yaw in degrees)
42 private const TAG_ROT = "Rot"; //TAG_Byte (legacy, pre-1.10, 0-15)
43 private const TAG_MOUTH_MOVING = "MouthMoving"; //TAG_Byte
44 private const TAG_MOUTH_TICK_COUNT = "MouthTickCount"; //TAG_Int
45
46 private MobHeadType $mobHeadType = MobHeadType::SKELETON;
47 private int $rotation = 0;
48
49 public function readSaveData(CompoundTag $nbt) : void{
50 if(($skullTypeTag = $nbt->getTag(self::TAG_SKULL_TYPE)) instanceof ByteTag){
51 $mobHeadType = MobHeadTypeIdMap::getInstance()->fromId($skullTypeTag->getValue());
52 if($mobHeadType === null){
53 throw new SavedDataLoadingException("Invalid skull type tag value " . $skullTypeTag->getValue());
54 }
55 $this->mobHeadType = $mobHeadType;
56 }
57
58 if($nbt->getTag(self::TAG_ROTATION) instanceof FloatTag){
59 $yaw = $nbt->getFloat(self::TAG_ROTATION, 0.0);
60 $this->rotation = ((int) floor(($yaw * 16 / 360) + 0.5)) & 0xf;
61 }else{
62 $rotation = $nbt->getByte(self::TAG_ROT, 0);
63 if($rotation >= 0 && $rotation <= 15){
64 $this->rotation = $rotation;
65 }
66 }
67 }
68
69 protected function writeSaveData(CompoundTag $nbt) : void{
70 $nbt->setByte(self::TAG_SKULL_TYPE, MobHeadTypeIdMap::getInstance()->toId($this->mobHeadType));
71 $nbt->setFloat(self::TAG_ROTATION, $this->rotation * 360.0 / 16.0);
72 }
73
74 public function setMobHeadType(MobHeadType $type) : void{
75 $this->mobHeadType = $type;
76 }
77
78 public function getMobHeadType() : MobHeadType{
79 return $this->mobHeadType;
80 }
81
82 public function getRotation() : int{
83 return $this->rotation;
84 }
85
86 public function setRotation(int $rotation) : void{
87 $this->rotation = $rotation;
88 }
89
90 protected function addAdditionalSpawnData(CompoundTag $nbt) : void{
91 $nbt->setByte(self::TAG_SKULL_TYPE, MobHeadTypeIdMap::getInstance()->toId($this->mobHeadType));
92 $nbt->setFloat(self::TAG_ROTATION, $this->rotation * 360.0 / 16.0);
93 }
94}
addAdditionalSpawnData(CompoundTag $nbt)
writeSaveData(CompoundTag $nbt)
setFloat(string $name, float $value)