mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 18:32:55 +00:00
Added Villager spawn egg
This commit is contained in:
@ -22,12 +22,73 @@
|
||||
namespace pocketmine\entity;
|
||||
|
||||
|
||||
use pocketmine\nbt\tag\Int;
|
||||
use pocketmine\network\protocol\AddMobPacket;
|
||||
use pocketmine\network\protocol\SetEntityMotionPacket;
|
||||
use pocketmine\Player;
|
||||
|
||||
class Villager extends Creature implements NPC, Ageable{
|
||||
const FARMER = 0;
|
||||
const LIBRARIAN = 1;
|
||||
const PRIEST = 2;
|
||||
const BLACKSMITH = 3;
|
||||
const BUTCHER = 4;
|
||||
const PROFESSION_FARMER = 0;
|
||||
const PROFESSION_LIBRARIAN = 1;
|
||||
const PROFESSION_PRIEST = 2;
|
||||
const PROFESSION_BLACKSMITH = 3;
|
||||
const PROFESSION_BUTCHER = 4;
|
||||
const PROFESSION_GENERIC = 5;
|
||||
|
||||
const NETWORK_ID = 15;
|
||||
|
||||
public $width = 0.6;
|
||||
public $length = 0.6;
|
||||
public $height = 1.8;
|
||||
|
||||
public function getName(){
|
||||
return "Villager";
|
||||
}
|
||||
|
||||
protected function initEntity(){
|
||||
parent::initEntity();
|
||||
if(!isset($this->namedtag->Profession)){
|
||||
$this->setProfession(self::PROFESSION_GENERIC);
|
||||
}
|
||||
}
|
||||
|
||||
public function spawnTo(Player $player){
|
||||
if($player !== $this and !isset($this->hasSpawned[$player->getID()])){
|
||||
$this->hasSpawned[$player->getID()] = $player;
|
||||
|
||||
$pk = new AddMobPacket();
|
||||
$pk->eid = $this->getID();
|
||||
$pk->type = Villager::NETWORK_ID;
|
||||
$pk->x = $this->x;
|
||||
$pk->y = $this->y;
|
||||
$pk->z = $this->z;
|
||||
$pk->yaw = $this->yaw;
|
||||
$pk->pitch = $this->pitch;
|
||||
$pk->metadata = $this->getData();
|
||||
$player->dataPacket($pk);
|
||||
|
||||
$pk = new SetEntityMotionPacket();
|
||||
$pk->entities = [
|
||||
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
|
||||
];
|
||||
$player->dataPacket($pk);
|
||||
}
|
||||
}
|
||||
|
||||
public function getData(){ //TODO
|
||||
$flags = 0;
|
||||
$flags |= $this->fireTicks > 0 ? 1 : 0;
|
||||
//$flags |= ($this->crouched === true ? 0b10:0) << 1;
|
||||
//$flags |= ($this->inAction === true ? 0b10000:0);
|
||||
$d = array(
|
||||
0 => array("type" => 0, "value" => $flags),
|
||||
1 => array("type" => 1, "value" => $this->airTicks),
|
||||
16 => array("type" => 0, "value" => 0),
|
||||
17 => array("type" => 6, "value" => array(0, 0, 0)),
|
||||
);
|
||||
|
||||
return $d;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the villager profession
|
||||
@ -35,6 +96,10 @@ class Villager extends Creature implements NPC, Ageable{
|
||||
* @param $profession
|
||||
*/
|
||||
public function setProfession($profession){
|
||||
$this->namedtag->Profession = new Int("Profession", $profession);
|
||||
}
|
||||
|
||||
public function getProfession(){
|
||||
return $this->namedtag["Profession"];
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user