mirror of
https://github.com/oldminecraftcommunity/NostalgiaCore.git
synced 2026-11-21 12:09:43 +00:00
baby animals will grow now, small changes to despawn command
This commit is contained in:
parent
685efef843
commit
107afb434b
6 changed files with 79 additions and 45 deletions
|
|
@ -55,7 +55,7 @@ class EntityAPI{
|
|||
}
|
||||
$mobName = ucfirst(array_flip($mob)[$type]);
|
||||
|
||||
if(strtolower($args[1] === "baby") or strtolower($args[2] === "baby") and $type > 13){
|
||||
if((strtolower($args[1] === "baby") or strtolower($args[2] === "baby")) and !Utils::in_range($type, 10, 13)){
|
||||
$output .= "$mobName cannot be a baby!";
|
||||
break;
|
||||
}
|
||||
|
|
@ -77,13 +77,13 @@ class EntityAPI{
|
|||
$output .= "Cannot spawn > 25 mobs";
|
||||
break;
|
||||
}
|
||||
|
||||
$isBaby = false;
|
||||
if(isset($args[2]) and strtolower($args[2]) === 'baby'){//summon <mob> [amount] [baby]
|
||||
$isBaby = 1;
|
||||
$isBaby = true;
|
||||
}
|
||||
|
||||
for($cnt = $amount; $cnt > 0; --$cnt){
|
||||
$this->summon($pos, ENTITY_MOB, $type, $isBaby === 1 ? ["IsBaby" => 1] : []);
|
||||
$this->summon($pos, ENTITY_MOB, $type, ["IsBaby" => $isBaby]);
|
||||
}
|
||||
|
||||
$output .= "$amount ".($isBaby === 1 ? "Baby" : "")." $mobName".(($type !== 13 || $amount > 1) ? "s" : "")." spawned in $x, $y, $z.";
|
||||
|
|
@ -102,7 +102,7 @@ class EntityAPI{
|
|||
break;
|
||||
}else{
|
||||
if($args[0] === "all"){
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE class = 2 or 3 or 4 or 5;");
|
||||
$l = $this->server->query("SELECT EID FROM entities WHERE class = 2 or class = 3 or class = 4 or class = 5;");
|
||||
}else{
|
||||
$array = explode(",", strtolower($args[0]));
|
||||
if(count($array) > 4){
|
||||
|
|
|
|||
|
|
@ -434,8 +434,8 @@ class PlayerAPI{
|
|||
$clients[$e->CID] = $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
return $clients;
|
||||
} return $clients;
|
||||
|
||||
}
|
||||
return $this->server->clients;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,4 +2,13 @@
|
|||
|
||||
interface Ageable{
|
||||
public function isBaby();
|
||||
/**
|
||||
* Get Entity Age. It can be negative.
|
||||
*/
|
||||
public function getAge();
|
||||
/**
|
||||
* Set Entity age.
|
||||
* @param int $i
|
||||
*/
|
||||
public function setAge($i);
|
||||
}
|
||||
|
|
@ -7,22 +7,60 @@ 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);
|
||||
}
|
||||
}
|
||||
|
||||
public function isBaby(){
|
||||
if(!isset($this->data["IsBaby"])){
|
||||
$this->data["IsBaby"] = false;
|
||||
}
|
||||
return $this->data["IsBaby"];
|
||||
return $this->getAge() < 0;
|
||||
}
|
||||
|
||||
public function spawnChild(){
|
||||
//TODO
|
||||
//$c->parent = $this->eid;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
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, [
|
||||
"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(){
|
||||
$d = parent::getMetadata();
|
||||
if(!isset($this->data["IsBaby"])){
|
||||
$this->data["IsBaby"] = 0;
|
||||
}
|
||||
$d[14]["value"] = $this->isBaby();
|
||||
return $d;
|
||||
}
|
||||
|
|
@ -30,8 +68,8 @@ abstract class Animal extends Creature implements Ageable, Breedable{
|
|||
public function createSaveData(){
|
||||
$data = parent::createSaveData();
|
||||
$data["IsBaby"] = $this->isBaby();
|
||||
$data["Age"] = $this->getAge();
|
||||
return $data;
|
||||
|
||||
}
|
||||
|
||||
public function isInLove(){
|
||||
|
|
|
|||
|
|
@ -37,4 +37,5 @@ class Chicken extends Animal{
|
|||
[[$this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN], 0, 1]
|
||||
];
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -8,32 +8,18 @@ class SpawnEggItem extends Item{
|
|||
}
|
||||
|
||||
public function onActivate(Level $level, Player $player, Block $block, Block $target, $face, $fx, $fy, $fz){
|
||||
$ageable = false;
|
||||
switch($this->meta){
|
||||
case MOB_CHICKEN:
|
||||
case MOB_SHEEP:
|
||||
case MOB_COW:
|
||||
case MOB_PIG:
|
||||
$ageable = true;
|
||||
case MOB_ZOMBIE:
|
||||
case MOB_CREEPER:
|
||||
case MOB_SKELETON:
|
||||
case MOB_SPIDER:
|
||||
case MOB_PIGMAN:
|
||||
$data = array(
|
||||
"x" => $block->x + 0.5,
|
||||
"y" => $block->y,
|
||||
"z" => $block->z + 0.5,
|
||||
"IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0,
|
||||
);
|
||||
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
|
||||
ServerAPI::request()->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
--$this->count;
|
||||
}
|
||||
return true;
|
||||
break;
|
||||
}
|
||||
return false;
|
||||
$ageable = $this->meta === MOB_CHICKEN || $this->meta === MOB_COW || $this->meta === MOB_SHEEP || $this->meta === MOB_PIG;
|
||||
$data = array(
|
||||
"x" => $block->x + 0.5,
|
||||
"y" => $block->y,
|
||||
"z" => $block->z + 0.5,
|
||||
"IsBaby" => $ageable ? Utils::chance(5) ? 1 : 0 : 0
|
||||
);
|
||||
$e = ServerAPI::request()->api->entity->add($block->level, ENTITY_MOB, $this->meta, $data);
|
||||
ServerAPI::request()->api->entity->spawnToAll($e);
|
||||
if(($player->gamemode & 0x01) === 0){
|
||||
-- $this->count;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue