mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-10-19 04:15:04 +00:00
Removed pocketmine subdirectory, map PSR-4 style
This commit is contained in:
95
src/entity/Villager.php
Normal file
95
src/entity/Villager.php
Normal file
@@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
*
|
||||
* ____ _ _ __ __ _ __ __ ____
|
||||
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
|
||||
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
|
||||
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
|
||||
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Lesser General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* @author PocketMine Team
|
||||
* @link http://www.pocketmine.net/
|
||||
*
|
||||
*
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace pocketmine\entity;
|
||||
|
||||
use pocketmine\nbt\tag\CompoundTag;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityLegacyIds;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataFlags;
|
||||
use pocketmine\network\mcpe\protocol\types\entity\EntityMetadataProperties;
|
||||
|
||||
class Villager extends Living implements Ageable{
|
||||
public const PROFESSION_FARMER = 0;
|
||||
public const PROFESSION_LIBRARIAN = 1;
|
||||
public const PROFESSION_PRIEST = 2;
|
||||
public const PROFESSION_BLACKSMITH = 3;
|
||||
public const PROFESSION_BUTCHER = 4;
|
||||
|
||||
public const NETWORK_ID = EntityLegacyIds::VILLAGER;
|
||||
|
||||
public $width = 0.6;
|
||||
public $height = 1.8;
|
||||
|
||||
/** @var bool */
|
||||
private $baby = false;
|
||||
/** @var int */
|
||||
private $profession = self::PROFESSION_FARMER;
|
||||
|
||||
public function getName() : string{
|
||||
return "Villager";
|
||||
}
|
||||
|
||||
protected function initEntity(CompoundTag $nbt) : void{
|
||||
parent::initEntity($nbt);
|
||||
|
||||
/** @var int $profession */
|
||||
$profession = $nbt->getInt("Profession", self::PROFESSION_FARMER);
|
||||
|
||||
if($profession > 4 or $profession < 0){
|
||||
$profession = self::PROFESSION_FARMER;
|
||||
}
|
||||
|
||||
$this->setProfession($profession);
|
||||
}
|
||||
|
||||
public function saveNBT() : CompoundTag{
|
||||
$nbt = parent::saveNBT();
|
||||
$nbt->setInt("Profession", $this->getProfession());
|
||||
|
||||
return $nbt;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the villager profession
|
||||
*
|
||||
* @param int $profession
|
||||
*/
|
||||
public function setProfession(int $profession) : void{
|
||||
$this->profession = $profession; //TODO: validation
|
||||
}
|
||||
|
||||
public function getProfession() : int{
|
||||
return $this->profession;
|
||||
}
|
||||
|
||||
public function isBaby() : bool{
|
||||
return $this->baby;
|
||||
}
|
||||
|
||||
protected function syncNetworkData() : void{
|
||||
parent::syncNetworkData();
|
||||
$this->networkProperties->setGenericFlag(EntityMetadataFlags::BABY, $this->baby);
|
||||
|
||||
$this->networkProperties->setInt(EntityMetadataProperties::VARIANT, $this->profession);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user