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,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;