PocketMine-MP 5.15.1 git-5ef247620a7c6301a849b54e5ef1009217729fc8
Villager.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\entity;
25
31
32class Villager extends Living implements Ageable{
33 public const PROFESSION_FARMER = 0;
34 public const PROFESSION_LIBRARIAN = 1;
35 public const PROFESSION_PRIEST = 2;
36 public const PROFESSION_BLACKSMITH = 3;
37 public const PROFESSION_BUTCHER = 4;
38
39 private const TAG_PROFESSION = "Profession"; //TAG_Int
40
41 public static function getNetworkTypeId() : string{ return EntityIds::VILLAGER; }
42
43 private bool $baby = false;
44 private int $profession = self::PROFESSION_FARMER;
45
46 protected function getInitialSizeInfo() : EntitySizeInfo{
47 return new EntitySizeInfo(1.8, 0.6); //TODO: eye height??
48 }
49
50 public function getName() : string{
51 return "Villager";
52 }
53
54 protected function initEntity(CompoundTag $nbt) : void{
55 parent::initEntity($nbt);
56
58 $profession = $nbt->getInt(self::TAG_PROFESSION, self::PROFESSION_FARMER);
59
60 if($profession > 4 || $profession < 0){
61 $profession = self::PROFESSION_FARMER;
62 }
63
64 $this->setProfession($profession);
65 }
66
67 public function saveNBT() : CompoundTag{
68 $nbt = parent::saveNBT();
69 $nbt->setInt(self::TAG_PROFESSION, $this->getProfession());
70
71 return $nbt;
72 }
73
77 public function setProfession(int $profession) : void{
78 $this->profession = $profession; //TODO: validation
79 $this->networkPropertiesDirty = true;
80 }
81
82 public function getProfession() : int{
83 return $this->profession;
84 }
85
86 public function isBaby() : bool{
87 return $this->baby;
88 }
89
90 protected function syncNetworkData(EntityMetadataCollection $properties) : void{
91 parent::syncNetworkData($properties);
92 $properties->setGenericFlag(EntityMetadataFlags::BABY, $this->baby);
93
94 $properties->setInt(EntityMetadataProperties::VARIANT, $this->profession);
95 }
96}
setProfession(int $profession)
Definition: Villager.php:77
setInt(string $name, int $value)