Big update about mobs

Removes some array() and some another minor changes.
Cow now drop 0-3 meat.
Pigs can be saddled, and if pig saddled it will drop them.
Creeper can be blown up with flint and steel ("power" => 3).
You can ride on pig (some buggy).
Now Saddle maxStackSize = 1.
Using shears and flint&steel on sheep and creeper they will break.
Saddled will save with closing the server.
This commit is contained in:
ArkQuark 2022-10-30 18:13:37 +03:00
parent 2a52e6c69c
commit f5222be9d2
17 changed files with 221 additions and 180 deletions

View file

@ -2,9 +2,9 @@
class Chicken extends Animal{
const TYPE = MOB_CHICKEN;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg"));
$this->server->schedule(mt_rand(0,6000) + 6000, [$this, "dropAnEgg"]);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 4, "generic");
$this->setName('Chicken');
$this->setSize($this->isBaby() ? 0.2 : 0.4, $this->isBaby() ? 0.35 : 0.7);
@ -17,15 +17,14 @@ class Chicken extends Animal{
if($this->closed){
return;
}
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(EGG,0,1));
$this->server->schedule(mt_rand(0,6000) + 6000, array($this, "dropAnEgg"));
ServerAPI::request()->api->entity->drop(new Position($this->x + 0.5, $this->y, $this->z + 0.5, $this->level), BlockAPI::getItem(EGG, 0, 1));
$this->server->schedule(mt_rand(0,6000) + 6000, [$this, "dropAnEgg"]);
}
public function getDrops(){
return $this->isBaby() ? parent::getDrops() :
array(
array(FEATHER, 0, mt_rand(0,2)),
array(($this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN), 0, 1),
);
return $this->isBaby() ? parent::getDrops() : [
[FEATHER, 0, mt_rand(0,2)],
[[$this->fire > 0 ? COOKED_CHICKEN : RAW_CHICKEN], 0, 1]
];
}
}

View file

@ -2,23 +2,23 @@
class Cow extends Animal{
const TYPE = MOB_COW;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 10, "generic");
$this->setSize($this->isBaby() ? 0.45 : 0.9 , $this->isBaby() ? 0.7 : 1.4);
$this->setName('Cow');
$this->setName("Cow");
$this->update();
}
public function isFood($id){
return $id === WHEAT;
}
public function getDrops(){
return $this->isBaby() ? parent::getDrops() :
array(
array(LEATHER, 0, mt_rand(0,2)),
array(($this->fire > 0 ? STEAK:BEEF), 0, 1),
);
return $this->isBaby() ? parent::getDrops() : [
[LEATHER, 0, mt_rand(0,2)],
[($this->fire > 0 ? STEAK : BEEF), 0, mt_rand(0, 3)]
];
}
}

View file

@ -1,22 +1,34 @@
<?php
class Pig extends Animal{
class Pig extends Animal implements Rideable{
const TYPE = MOB_PIG;
public $server;
public function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
public function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"]:10, "generic");
$this->server = ServerAPI::request();
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.45 : 0.9);
$this->setName('Pig');
$this->setName("Pig");
$this->update();
}
public function getMetadata(){
$d = parent::getMetadata();
if(!isset($this->data["Saddled"])){
$this->data["Saddled"] = 0;
}
$d[16]["value"] = ((int)$this->data["Saddled"]);
return $d;
}
public function isFood($id){
return $id === POTATO || $id === CARROT || $id === BEETROOT;
}
public function getDrops(){
return $this->isBaby() ? parent::getDrops() :
array(
array(($this->fire > 0 ? COOKED_PORKCHOP:RAW_PORKCHOP), 0, mt_rand(0,2)),
);
return $this->isBaby() ? parent::getDrops() : ($this->data["Saddled"] ? [
[($this->fire > 0 ? COOKED_PORKCHOP : RAW_PORKCHOP), 0, mt_rand(0,2)],
[SADDLE, 0, 1]
] : [
[($this->fire > 0 ? COOKED_PORKCHOP : RAW_PORKCHOP), 0, mt_rand(0,2)]
]);
}
}

View file

@ -2,21 +2,18 @@
class Sheep extends Animal{
const TYPE = MOB_SHEEP;
const NOT_SHEARED = 0;
const SHEARED = 1;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
function __construct(Level $level, $eid, $class, $type = 0, $data = []){
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
$this->setName('Sheep');
$this->setName("Sheep");
$this->setSize($this->isBaby() ? 0.45 : 0.9, $this->isBaby() ? 0.675 : 1.3);
$this->update();
}
public function getDrops(){
return $this->isBaby() ? parent::getDrops() :
array(
array(WOOL, $this->data["Color"] & 0x0F, 1),
);
return $this->isBaby() ? parent::getDrops() : [
[WOOL, $this->data["Color"] & 0x0F, 1],
];
}
public function isFood($id){
@ -26,18 +23,19 @@ class Sheep extends Animal{
public function getMetadata(){
$d = parent::getMetadata();
if(!isset($this->data["Sheared"])){
$this->data["Sheared"] = Sheep::NOT_SHEARED;
$this->data["Sheared"] = 0;
}
if(!isset($this->data["Color"])){ //Make a new random color if it is not in data
$this->data["Color"] = $this->sheepColor();
}
$d[16]["value"] = (($this->data["Sheared"] == 1 ? Sheep::SHEARED : Sheep::NOT_SHEARED) << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here...
$d[16]["value"] = ($this->data["Sheared"] << 4) | ($this->data["Color"] & 0x0F); //dark manipulations are happening here...
return $d;
}
public function sheepColor(){
$pink = 0.1558;
$brown = 2.85;
$lightgray_black_gray = 14.25;
$lightgrayBlackGray = 14.25;
$chance = Utils::randomFloat() * 100;
switch($chance){
case($chance <= $pink):
@ -46,8 +44,8 @@ class Sheep extends Animal{
case($chance > $pink and $chance <= ($brown+$pink)):
$color = 12;
break;
case($chance > ($brown+$pink) and $chance <= ($lightgray_black_gray+$brown+$pink)):
$rand = mt_rand(1,3);
case($chance > ($brown+$pink) and $chance <= ($lightgrayBlackGray+$brown+$pink)):
$rand = mt_rand(1, 3);
if($rand == 1) $color = 15;
elseif($rand == 2) $color = 7;
else $color = 8;