added separated class for arrows

This commit is contained in:
GameHerobrine 2022-06-26 06:03:19 +03:00
parent fa41b2ed65
commit 577e00378e
4 changed files with 49 additions and 19 deletions

View file

@ -142,7 +142,7 @@ class Entity extends Position{
$this->setHealth(10000000, "generic");
$this->server->schedule(5, array($this, "updateFuse"), array(), true);
$this->update();
}elseif($this->type === (OBJECT_ARROW or OBJECT_SNOWBALL)){
}elseif($this->type === OBJECT_SNOWBALL){
$this->server->schedule(1210, array($this, "update")); //Despawn
$this->update();
}elseif($this->type == OBJECT_MINECART){
@ -241,9 +241,9 @@ class Entity extends Position{
$this->close(); //Despawn timer
return false;
}
}elseif($this->class === ENTITY_OBJECT and ($this->type === OBJECT_ARROW or OBJECT_SNOWBALL)){
}elseif($this->class === ENTITY_OBJECT and $this->type === OBJECT_SNOWBALL){
if(($time - $this->spawntime) >= 60){
$this->close(); //Despawn timer
$this->close();
return false;
}
}
@ -730,22 +730,6 @@ class Entity extends Position{
$pk->did = 0;
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk->eid = $this->eid;
$pk->speedX = $this->speedX;
$pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
}elseif($this->type === OBJECT_ARROW){
$pk = new AddEntityPacket;
$pk->eid = $this->eid;
$pk->type = $this->type;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->did = 0;
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk->eid = $this->eid;
$pk->speedX = $this->speedX;

View file

@ -46,6 +46,7 @@ class EntityRegistry{
self::registerEntity(Skeleton::class);
self::registerEntity(Spider::class);
self::registerEntity(Zombie::class);
self::registerEntity(Arrow::class);
}
/*Register an Entity*/

View file

@ -0,0 +1,6 @@
<?php
abstract class Projectile extends Entity{
const CLASS_TYPE = ENTITY_OBJECT;
}

View file

@ -0,0 +1,39 @@
<?php
class Arrow extends Projectile{
const TYPE = OBJECT_ARROW;
function __construct(Level $level, $eid, $class, $type = 0, $data = array()){
parent::__construct($level, $eid, $class, $type, $data);
$this->server->schedule(1210, array($this, "update")); //Despawn
$this->update();
}
public function environmentUpdate(){
parent::environmentUpdate();
$time = microtime(true);
if(($time - $this->spawntime) >= 60){
$this->close();
return false;
}
}
public function spawn($player){
if($this->type === OBJECT_ARROW){
$pk = new AddEntityPacket;
$pk->eid = $this->eid;
$pk->type = $this->type;
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->did = 0;
$player->dataPacket($pk);
$pk = new SetEntityMotionPacket;
$pk->eid = $this->eid;
$pk->speedX = $this->speedX;
$pk->speedY = $this->speedY;
$pk->speedZ = $this->speedZ;
$player->dataPacket($pk);
}
}
}