mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
project uses tabs instead of spaces(as in CONTRIBUTING.md)
This commit is contained in:
parent
f00318b6ed
commit
62571f26cd
115 changed files with 2291 additions and 2364 deletions
|
|
@ -5,58 +5,58 @@ move methods
|
|||
*/
|
||||
abstract class Animal extends Creature implements Ageable, Breedable{
|
||||
|
||||
public $parent;
|
||||
public $inLove; //do NOT add it into metadata, it doesnt send it to player
|
||||
public $age;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0);
|
||||
if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){
|
||||
$this->setAge(-24000);
|
||||
}
|
||||
$this->ai->addTask(new TaskTempt());
|
||||
}
|
||||
|
||||
public $parent;
|
||||
public $inLove; //do NOT add it into metadata, it doesnt send it to player
|
||||
public $age;
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setAge(isset($data["Age"]) ? $data["Age"] : 0);
|
||||
if(isset($this->data["IsBaby"]) && $this->data["IsBaby"] && $this->getAge() >= 0){
|
||||
$this->setAge(-24000);
|
||||
}
|
||||
$this->ai->addTask(new TaskTempt());
|
||||
}
|
||||
|
||||
public function isBaby(){
|
||||
return $this->getAge() < 0;
|
||||
}
|
||||
|
||||
public function breed(){
|
||||
$c = $this->spawnChild();
|
||||
if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "child" => $c]) !== false){
|
||||
$c->parent = &$this;
|
||||
$this->server->api->entity->spawnToAll($c);
|
||||
}
|
||||
$c = $this->spawnChild();
|
||||
if($this->server->dhandle("entity.animal.breed", ["parent" => $this, "child" => $c]) !== false){
|
||||
$c->parent = &$this;
|
||||
$this->server->api->entity->spawnToAll($c);
|
||||
}
|
||||
}
|
||||
|
||||
public function update(){
|
||||
parent::update();
|
||||
$age = $this->getAge() + 1; //100 - fast. debug, 1 - normal
|
||||
if($age >= 0 && $this->isBaby()){
|
||||
$this->setAge($age);
|
||||
$this->updateMetadata();
|
||||
}else{
|
||||
$this->setAge($age);
|
||||
}
|
||||
parent::update();
|
||||
$age = $this->getAge() + 1; //100 - fast. debug, 1 - normal
|
||||
if($age >= 0 && $this->isBaby()){
|
||||
$this->setAge($age);
|
||||
$this->updateMetadata();
|
||||
}else{
|
||||
$this->setAge($age);
|
||||
}
|
||||
}
|
||||
|
||||
public function getAge(){
|
||||
return $this->age;
|
||||
return $this->age;
|
||||
}
|
||||
|
||||
public function setAge($i){
|
||||
$this->age = $i;
|
||||
$this->age = $i;
|
||||
}
|
||||
|
||||
public function spawnChild()
|
||||
{
|
||||
return $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
||||
"x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"y" => $this->y,
|
||||
"z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"IsBaby" => true,
|
||||
"Age" => -24000,
|
||||
]);
|
||||
return $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
||||
"x" => $this->x + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"y" => $this->y,
|
||||
"z" => $this->z + Utils::randomFloat() * mt_rand(-1, 1),
|
||||
"IsBaby" => true,
|
||||
"Age" => -24000,
|
||||
]);
|
||||
}
|
||||
|
||||
public function getMetadata(){
|
||||
|
|
@ -66,33 +66,33 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
}
|
||||
|
||||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
$data["IsBaby"] = $this->isBaby();
|
||||
$data["Age"] = $this->getAge();
|
||||
return $data;
|
||||
$data = parent::createSaveData();
|
||||
$data["IsBaby"] = $this->isBaby();
|
||||
$data["Age"] = $this->getAge();
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function isInLove(){
|
||||
return $this->inLove > 0;
|
||||
return $this->inLove > 0;
|
||||
}
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->isFood($slot->getID())){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
|
||||
$this->inLove = 600; //600 ticks, original mehod from mcpe
|
||||
return true;
|
||||
}
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
if($this->isFood($slot->getID())){
|
||||
$e->player->removeItem($slot->getID(), $slot->getMetadata(), 1);
|
||||
$this->inLove = 600; //600 ticks, original mehod from mcpe
|
||||
return true;
|
||||
}
|
||||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
public function counterUpdate(){
|
||||
parent::counterUpdate();
|
||||
if($this->isInLove()){
|
||||
--$this->inLove;
|
||||
}
|
||||
parent::counterUpdate();
|
||||
if($this->isInLove()){
|
||||
--$this->inLove;
|
||||
}
|
||||
}
|
||||
|
||||
public function getDrops(){
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue