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

@ -676,14 +676,14 @@ class Entity extends Position{
2 -> Integer
3 -> Float
4 -> Length of <value>, Short
5 -> array(Short, Byte, Short)
6 -> arry(Integer, Integer, Integer)
5 -> [Short, Byte, Short]
6 -> [Integer, Integer, Integer]
******************
0 => array("type" => 0, "value" => $flags) --> DATA_FLAGS
1 => array("type" => 1, "value" => $this->air) --> Entity Air
14 => array("type" => 0, "value" => 1) --> IsBaby, value: 0 => false, 1 => true
16 => array("type" => 0, "value" => 0) --> Fuse(TNT), Saddled(Pig)
17 => array("type" => 6, "value" => array(0, 0, 0)) --> Bed Position <?>
0 => ["type" => 0, "value" => $flags] --> DATA_FLAGS
1 => ["type" => 1, "value" => $this->air] --> Entity Air
14 => ["type" => 0, "value" => 1] --> IsBaby, value: 0 => false, 1 => true
16 => ["type" => 0, "value" => 0] --> Fuse(TNT), Saddled(Pig)
17 => ["type" => 6, "value" => [0, 0, 0]] --> Bed Position <?>
DATA FLAGS IDS
@ -697,21 +697,21 @@ class Entity extends Position{
$flags ^= $this->fire > 0 ? 0b1 : 0;
$flags ^= ($this->crouched ? 0b1 : 0) << 1;
$flags ^= ($this->inAction ? 0b1 : 0) << 4;
$d = array(
0 => array("type" => 0, "value" => $flags),
1 => array("type" => 1, "value" => $this->air),
14 => array("type" => 0, "value" => 0),
16 => array("type" => 0, "value" => 0),
17 => array("type" => 6, "value" => array(0, 0, 0)),
);
$d = [
0 => ["type" => 0, "value" => $flags],
1 => ["type" => 1, "value" => $this->air],
14 => ["type" => 0, "value" => 0],
16 => ["type" => 0, "value" => 0],
17 => ["type" => 6, "value" => [0, 0, 0]]
];
if($this->class === ENTITY_MOB){ //ladder fix 2.0
if($this->type === MOB_PIG){ /*Saddled Pig*/
$d[16]["value"] = 0;
}
//if($this->type === MOB_PIG){ /*Saddled Pig*/
//$d[16]["value"] = 0;
//}
}elseif($this->class === ENTITY_PLAYER){
if($this->player->isSleeping !== false){
$d[16]["value"] = 2;
$d[17]["value"] = array($this->player->isSleeping->x, $this->player->isSleeping->y, $this->player->isSleeping->z);
$d[17]["value"] = [$this->player->isSleeping->x, $this->player->isSleeping->y, $this->player->isSleeping->z];
}
}
return $d;

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;

View file

@ -1,19 +1,41 @@
<?php
class Creeper extends Monster{
const TYPE = MOB_CREEPER;
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"]:16, "generic");
$this->setName('Creeper');
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 16, "generic");
$this->setName("Creeper");
$this->setSize(0.6, 1.7);
$this->update();
if($this->data["Saddled"] === 1){
$this->server->schedule(30, [$this, "updateFuse"], []); //unknown ticks
}
}
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 updateFuse(){
if($this->closed === true){
return false;
}
if($this->type === MOB_CREEPER){
$this->updateMetadata();
$this->close();
$explosion = new Explosion($this, 3);
$explosion->explode();
}
}
public function getDrops(){
return array(
array(GUNPOWDER, 0, mt_rand(0,2)),
);
return $this->data["Saddled"] === 1 ? parent::getDrops() : [
[GUNPOWDER, 0, mt_rand(0,2)]
];
}
}

View file

@ -1,18 +1,18 @@
<?php
class PigZombie extends Monster{
const TYPE = MOB_PIGMAN;
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"] : 12, "generic");
$this->setSize(0.3, 1.95);
$this->setName('Pigman');
$this->setName("Pigman");
$this->update();
}
public function getDrops(){
return array(
array(COOKED_PORKCHOP, 0, mt_rand(0,2)),
array(GOLD_INGOT, 0, mt_rand(0,1)),
);
return [
[COOKED_PORKCHOP, 0, mt_rand(0,2)],
[GOLD_INGOT, 0, mt_rand(0,1)]
];
}
}

View file

@ -1,19 +1,18 @@
<?php
class Skeleton extends Monster{
const TYPE = MOB_SKELETON;
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->setName('Skeleton');
$this->setName("Skeleton");
$this->setSize(0.6, 1.99);
$this->update();
}
public function getDrops(){
return array(
array(ARROW, 0, mt_rand(0,2)),
array(BONE, 0, mt_rand(0,2)),
);
return [
[ARROW, 0, mt_rand(0,2)],
[BONE, 0, mt_rand(0,2)]
];
}
}

View file

@ -1,18 +1,17 @@
<?php
class Spider extends Monster{
const TYPE = MOB_SPIDER;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 8, "generic");
$this->setName('Spider');
$this->setName("Spider");
$this->setSize(1.4, 0.9);
$this->update();
}
public function getDrops(){
return array(
array(STRING, 0, mt_rand(0,2)),
);
return [
[STRING, 0, mt_rand(0,2)]
];
}
}

View file

@ -1,20 +1,19 @@
<?php
class Zombie extends Monster{
const TYPE = MOB_ZOMBIE;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data);
$this->setHealth(isset($this->data["Health"]) ? $this->data["Health"] : 12, "generic");
$this->setName('Zombie');
$this->setName("Zombie");
$this->setSize(0.6, 1.85);
$this->update();
}
public function getDrops(){
return array(
array(CARROT, 0, Utils::chance(0.83) ? 1 : 0),
array(POTATO, 0, Utils::chance(0.83) ? 1 : 0),
array(FEATHER, 0, mt_rand(0,2)),
);
return [
[CARROT, 0, Utils::chance(0.83) ? 1 : 0],
[POTATO, 0, Utils::chance(0.83) ? 1 : 0],
[FEATHER, 0, mt_rand(0,2)]
];
}
}

View file

@ -2,10 +2,11 @@
class Arrow extends Projectile{
const TYPE = OBJECT_ARROW;
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(1210, array($this, "update")); //Despawn
}
public function handleUpdate(){
$pk = new MoveEntityPacket_PosRot;
$pk->eid = $this->eid;
@ -16,8 +17,8 @@ class Arrow extends Projectile{
$pk->pitch = $this->pitch;
$this->server->api->player->broadcastPacket($this->level->players, $pk);
}
public function shoot($d, $d1, $d2, $f, $f1){ //original name from 0.8.1 IDA decompilation, var names are taken from b1.7.3
$f2 = sqrt($d * $d + $d1 * $d1 + $d2 * $d2);
$d /= $f2;
$d1 /= $f2;
@ -37,6 +38,7 @@ class Arrow extends Projectile{
$this->update();
//TODO i guess? $ticksInGround = 0;
}
public function spawn($player){
if($this->type === OBJECT_ARROW){
$pk = new AddEntityPacket;

View file

@ -2,14 +2,12 @@
class Minecart extends Vehicle{
const TYPE = OBJECT_MINECART;
private $moveVector = [];
const STATE_INITIAL = 0;
const STATE_ON_RAIL = 1;
const STATE_OFF_RAIL = 2;
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->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
@ -25,9 +23,9 @@ class Minecart extends Vehicle{
}
public function getDrops(){
return array(
array(MINECART, 0, 1),
);
return [
[MINECART, 0, 1]
];
}
public function spawn($player){

View file

@ -2,7 +2,7 @@
class Painting extends Hanging{
const TYPE = OBJECT_PAINTING;
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->x = isset($this->data["TileX"]) ? $this->data["TileX"]:$this->x;
$this->y = isset($this->data["TileY"]) ? $this->data["TileY"]:$this->y;
@ -13,7 +13,9 @@ class Painting extends Hanging{
}
public function getDrops(){
return array(array(PAINTING, 0, 1));
return [
[PAINTING, 0, 1]
];
}
public function spawn($player){
$pk = new AddPaintingPacket;

View file

@ -3,21 +3,22 @@
class PrimedTNT extends Entity{
const TYPE = OBJECT_PRIMEDTNT;
const CLASS_TYPE = ENTITY_OBJECT;
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);
if(!isset($this->data["fuse"])){
$this->data["fuse"] = 0;
}
$this->setHealth(10000000, "generic");
$this->server->schedule(5, array($this, "updateFuse"), array(), true);
$this->server->schedule(5, [$this, "updateFuse"], [], true);
$this->update();
}
public function getMetadata(){
$d = parent::getMetadata();
$d[16]["value"] = (int) max(0, $this->data["fuse"] - (microtime(true) - $this->spawntime) * 20);
return $d;
}
public function updateFuse(){
if($this->closed === true){
return false;