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