mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-20 19:49:44 +00:00
code style fix
This commit is contained in:
parent
fc5c5625cb
commit
5e8e9330e2
361 changed files with 4766 additions and 4650 deletions
|
|
@ -1,17 +1,15 @@
|
|||
<?php
|
||||
|
||||
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 $loveTimeout;
|
||||
|
||||
|
||||
|
||||
|
||||
public $closestPlayerThatCanFeedEID = false;
|
||||
public $closestPlayerThatCanFeedDist = INF;
|
||||
|
||||
|
||||
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
|
||||
parent::__construct($level, $eid, $class, $type, $data);
|
||||
$this->setAge($data["Age"] ?? 0);
|
||||
|
|
@ -20,11 +18,11 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
}
|
||||
$this->searchForClosestPlayers = true;
|
||||
}
|
||||
|
||||
|
||||
public function isPlayerValid(Player $player){
|
||||
return $player->spawned && $this->isFood($player->getHeldItem()->id) && !$player->entity->dead;
|
||||
}
|
||||
|
||||
|
||||
public function handlePrePlayerSearcher(){
|
||||
parent::handlePrePlayerSearcher();
|
||||
if($this->closestPlayerThatCanFeedEID !== false){
|
||||
|
|
@ -33,15 +31,15 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
$this->closestPlayerThatCanFeedEID = false;
|
||||
$this->closestPlayerThatCanFeedDist = INF;
|
||||
}else{
|
||||
$dist = ($this->x - $player->x)*($this->x - $player->x) + ($this->y - $player->y)*($this->y - $player->y) + ($this->z - $player->z)*($this->z - $player->z);
|
||||
$dist = ($this->x - $player->x) * ($this->x - $player->x) + ($this->y - $player->y) * ($this->y - $player->y) + ($this->z - $player->z) * ($this->z - $player->z);
|
||||
$this->closestPlayerThatCanFeedDist = $dist;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function handlePlayerSearcher(Player $player, $dist){
|
||||
parent::handlePlayerSearcher($player, $dist);
|
||||
|
||||
|
||||
if($this->closestPlayerThatCanFeedDist >= $dist){
|
||||
if($this->isPlayerValid($player)){
|
||||
$this->closestPlayerThatCanFeedDist = $dist;
|
||||
|
|
@ -49,18 +47,18 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function harm($dmg, $cause = "generic", $force = false){
|
||||
$ret = parent::harm($dmg, $cause, $force);
|
||||
$this->inPanic |= ($ret && is_numeric($cause));
|
||||
$this->inLove = false;
|
||||
return $ret;
|
||||
}
|
||||
|
||||
|
||||
public function isBaby(){
|
||||
return $this->getAge() < 0;
|
||||
}
|
||||
|
||||
|
||||
public function breed(){
|
||||
if($this->server->dhandle("entity.animal.breed", ["parent" => $this]) !== false){
|
||||
$c = $this->spawnChild();
|
||||
|
|
@ -70,22 +68,22 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public function resetInLove(){
|
||||
$this->inLove = 0;
|
||||
}
|
||||
|
||||
|
||||
public function canMate($ent){
|
||||
return $ent->eid != $this->eid && $this->type === $ent->type && $this->isInLove() && $ent->isInLove();
|
||||
}
|
||||
|
||||
|
||||
public function update($now){
|
||||
parent::update($now);
|
||||
|
||||
|
||||
if($this->loveTimeout > 0){
|
||||
--$this->loveTimeout;
|
||||
}
|
||||
|
||||
|
||||
$age = $this->getAge() + 1; //100 - fast. debug, 1 - normal
|
||||
if($age >= 0 && $this->isBaby()){
|
||||
$this->setAge($age);
|
||||
|
|
@ -99,15 +97,15 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
unset($this->level->entitiesInLove[$this->eid]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getAge(){
|
||||
return $this->age;
|
||||
}
|
||||
|
||||
|
||||
public function setAge($i){
|
||||
$this->age = $i;
|
||||
}
|
||||
|
||||
|
||||
public function spawnChild()
|
||||
{
|
||||
return $this->server->api->entity->add($this->level, $this->class, $this->type, [
|
||||
|
|
@ -118,24 +116,24 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
"Age" => -24000,
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
public function getMetadata(){
|
||||
$d = parent::getMetadata();
|
||||
$d[14]["value"] = $this->isBaby();
|
||||
return $d;
|
||||
}
|
||||
|
||||
|
||||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
$data["IsBaby"] = $this->isBaby();
|
||||
$data["Age"] = $this->getAge();
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
public function isInLove(){
|
||||
return $this->inLove > 0;
|
||||
}
|
||||
|
||||
|
||||
public function interactWith(Entity $e, $action){
|
||||
if($e->isPlayer() && $action === InteractPacket::ACTION_HOLD){
|
||||
$slot = $e->player->getHeldItem();
|
||||
|
|
@ -149,14 +147,14 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
}
|
||||
parent::interactWith($e, $action);
|
||||
}
|
||||
|
||||
|
||||
public function counterUpdate(){
|
||||
parent::counterUpdate();
|
||||
if($this->isInLove()){
|
||||
--$this->inLove;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public function getDrops(){
|
||||
if($this->isBaby()){
|
||||
return [];
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue