Fixed CPU leak

This commit is contained in:
Shoghi Cervantes
2014-10-31 21:05:37 +01:00
parent ae06681b60
commit 8601405a88
73 changed files with 304 additions and 564 deletions

View File

@@ -71,7 +71,7 @@ class Arrow extends Projectile{
}
public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool();
$pk = new AddEntityPacket();
$pk->type = Arrow::NETWORK_ID;
$pk->eid = $this->getID();
$pk->x = $this->x;
@@ -80,7 +80,7 @@ class Arrow extends Projectile{
$pk->did = 0; //TODO: send motion here
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -177,7 +177,7 @@ abstract class Entity extends Location implements Metadatable{
$this->boundingBox = new AxisAlignedBB(0, 0, 0, 0, 0, 0);
$this->setPositionAndRotation(
Vector3::createVector(
new Vector3(
$this->namedtag["Pos"][0],
$this->namedtag["Pos"][1],
$this->namedtag["Pos"][2]
@@ -186,7 +186,7 @@ abstract class Entity extends Location implements Metadatable{
$this->namedtag->Rotation[1],
true
);
$this->setMotion(Vector3::createVector($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
$this->setMotion(new Vector3($this->namedtag["Motion"][0], $this->namedtag["Motion"][1], $this->namedtag["Motion"][2]));
if(!isset($this->namedtag->FallDistance)){
$this->namedtag->FallDistance = new Float("FallDistance", 0);
@@ -217,7 +217,7 @@ abstract class Entity extends Location implements Metadatable{
$this->level->addEntity($this);
$this->initEntity();
$this->lastUpdate = $this->server->getTick();
$this->server->getPluginManager()->callEvent(EntitySpawnEvent::createEvent($this));
$this->server->getPluginManager()->callEvent(new EntitySpawnEvent($this));
$this->scheduleUpdate();
@@ -307,7 +307,7 @@ abstract class Entity extends Location implements Metadatable{
$player = [$player];
}
$pk = SetEntityDataPacket::getFromPool();
$pk = new SetEntityDataPacket();
$pk->eid = $this->id;
$pk->metadata = $this->getData();
$pk->encode();
@@ -315,7 +315,7 @@ abstract class Entity extends Location implements Metadatable{
foreach($player as $p){
if($p === $this){
/** @var Player $p */
$pk2 = SetEntityDataPacket::getFromPool();
$pk2 = new SetEntityDataPacket();
$pk2->eid = 0;
$pk2->metadata = $this->getData();
$p->dataPacket($pk2);
@@ -330,7 +330,7 @@ abstract class Entity extends Location implements Metadatable{
*/
public function despawnFrom(Player $player){
if(isset($this->hasSpawned[$player->getID()])){
$pk = RemoveEntityPacket::getFromPool();
$pk = new RemoveEntityPacket();
$pk->eid = $this->id;
$player->dataPacket($pk);
unset($this->hasSpawned[$player->getID()]);
@@ -424,7 +424,7 @@ abstract class Entity extends Location implements Metadatable{
$list = $this->level->getCollisionBlocks($this->boundingBox);
$v = Vector3::createVector($i, $j, $k);
$v = new Vector3($i, $j, $k);
if(count($list) === 0 and !$this->level->isFullBlock($v->setComponents($i, $j, $k))){
return false;
@@ -522,7 +522,7 @@ abstract class Entity extends Location implements Metadatable{
$this->checkBlockCollision();
if($this->y < 0 and $this->dead !== true){
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_VOID, 10);
$this->attack($ev->getFinalDamage(), $ev);
$hasUpdate = true;
}
@@ -535,7 +535,7 @@ abstract class Entity extends Location implements Metadatable{
}
}else{
if(($this->fireTicks % 20) === 0 or $tickDiff > 20){
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FIRE_TICK, 1);
$this->attack($ev->getFinalDamage(), $ev);
}
$this->fireTicks -= $tickDiff;
@@ -566,7 +566,7 @@ abstract class Entity extends Location implements Metadatable{
$this->lastPitch = $this->pitch;
if($this instanceof Human){
$pk = MovePlayerPacket::getFromPool();
$pk = new MovePlayerPacket();
$pk->eid = $this->id;
$pk->x = $this->x;
$pk->y = $this->y;
@@ -576,7 +576,7 @@ abstract class Entity extends Location implements Metadatable{
$pk->bodyYaw = $this->yaw;
}else{
//TODO: add to move list
$pk = MoveEntityPacket::getFromPool();
$pk = new MoveEntityPacket();
$pk->entities = [
[$this->id, $this->x, $this->y + $this->getEyeHeight(), $this->z, $this->yaw, $this->pitch]
];
@@ -590,7 +590,7 @@ abstract class Entity extends Location implements Metadatable{
$this->lastMotionY = $this->motionY;
$this->lastMotionZ = $this->motionZ;
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
@@ -617,7 +617,7 @@ abstract class Entity extends Location implements Metadatable{
$x = -$xz * sin(deg2rad($this->yaw));
$z = $xz * cos(deg2rad($this->yaw));
return Vector3::createVector($x, $y, $z);
return new Vector3($x, $y, $z);
}
public function onUpdate($currentTick){
@@ -709,7 +709,7 @@ abstract class Entity extends Location implements Metadatable{
public function fall($fallDistance){
$damage = floor($fallDistance - 3);
if($damage > 0){
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_FALL, $damage);
$this->attack($ev->getFinalDamage(), $ev);
}
}
@@ -732,7 +732,7 @@ abstract class Entity extends Location implements Metadatable{
protected function switchLevel(Level $targetLevel){
if($this->isValid()){
$this->server->getPluginManager()->callEvent($ev = EntityLevelChangeEvent::createEvent($this, $this->level, $targetLevel));
$this->server->getPluginManager()->callEvent($ev = new EntityLevelChangeEvent($this, $this->level, $targetLevel));
if($ev->isCancelled()){
return false;
}
@@ -750,13 +750,14 @@ abstract class Entity extends Location implements Metadatable{
}
$this->level->freeChunk($X, $Z, $this);
}
$this->level->freeAllChunks($this);
}
}
$this->setLevel($targetLevel, $this instanceof Player ? true : false); //Hard reference
$this->level->addEntity($this);
if($this instanceof Player){
$this->usedChunks = [];
$pk = SetTimePacket::getFromPool();
$pk = new SetTimePacket();
$pk->time = $this->level->getTime();
$pk->started = $this->level->stopTime == false;
$this->dataPacket($pk);
@@ -767,7 +768,7 @@ abstract class Entity extends Location implements Metadatable{
}
public function getPosition(){
return Position::createPosition($this->x, $this->y, $this->z, $this->level);
return new Position($this->x, $this->y, $this->z, $this->level);
}
public function getLocation(){
@@ -775,7 +776,7 @@ abstract class Entity extends Location implements Metadatable{
}
public function isInsideOfWater(){
$block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
$block = $this->level->getBlock(new Vector3(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
if($block instanceof Water){
$f = ($block->y + 1) - ($block->getFluidHeightPercent() - 0.1111111);
@@ -786,7 +787,7 @@ abstract class Entity extends Location implements Metadatable{
}
public function isInsideOfSolid(){
$block = $this->level->getBlock(Vector3::createVector(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
$block = $this->level->getBlock(new Vector3(Math::floorFloat($this->x), Math::floorFloat($y = ($this->y + $this->getEyeHeight())), Math::floorFloat($this->z)));
$bb = $block->getBoundingBox();
@@ -809,7 +810,7 @@ abstract class Entity extends Location implements Metadatable{
if($this->keepMovement){
$this->boundingBox->offset($dx, $dy, $dz);
$this->setPosition(Vector3::createVector(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2));
$this->setPosition(new Vector3(($this->boundingBox->minX + $this->boundingBox->maxX) / 2, $this->boundingBox->minY - $this->ySize, ($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2));
$this->onGround = $this instanceof Player ? true : false;
}else{
@@ -833,7 +834,7 @@ abstract class Entity extends Location implements Metadatable{
$movY = $dy;
$movZ = $dz;
$axisalignedbb = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox);
$axisalignedbb = clone $this->boundingBox;
/*$sneakFlag = $this->onGround and $this instanceof Player;
@@ -911,7 +912,7 @@ abstract class Entity extends Location implements Metadatable{
$dy = $this->stepHeight;
$dz = $movZ;
$axisalignedbb1 = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox);
$axisalignedbb1 = clone $this->boundingBox;
$this->boundingBox->setBB($axisalignedbb);
@@ -971,7 +972,7 @@ abstract class Entity extends Location implements Metadatable{
}
$pos = Vector3::createVector(
$pos = new Vector3(
($this->boundingBox->minX + $this->boundingBox->maxX) / 2,
$this->boundingBox->minY - $this->ySize,
($this->boundingBox->minZ + $this->boundingBox->maxZ) / 2
@@ -986,7 +987,7 @@ abstract class Entity extends Location implements Metadatable{
if($this instanceof Player){
if(!$this->onGround or $movY != 0){
$bb = AxisAlignedBB::cloneBoundingBoxFromPool($this->boundingBox);
$bb = clone $this->boundingBox;
$bb->maxY = $bb->minY + 1;
if(count($this->level->getCollisionBlocks($bb->expand(0.01, 0.01, 0.01))) > 0){
$this->onGround = true;
@@ -1028,8 +1029,8 @@ abstract class Entity extends Location implements Metadatable{
$maxY = Math::floorFloat($this->boundingBox->maxY - 0.001);
$maxZ = Math::floorFloat($this->boundingBox->maxZ - 0.001);
$vector = Vector3::createVector(0, 0, 0);
$v = Vector3::createVector(0, 0, 0);
$vector = new Vector3(0, 0, 0);
$v = new Vector3(0, 0, 0);
for($v->z = $minZ; $v->z <= $maxZ; ++$v->z){
for($v->x = $minX; $v->x <= $maxX; ++$v->x){
@@ -1113,12 +1114,12 @@ abstract class Entity extends Location implements Metadatable{
}
public function getMotion(){
return Vector3::createVector($this->motionX, $this->motionY, $this->motionZ);
return new Vector3($this->motionX, $this->motionY, $this->motionZ);
}
public function setMotion(Vector3 $motion){
if(!$this->justCreated){
$this->server->getPluginManager()->callEvent($ev = EntityMotionEvent::createEvent($this, $motion));
$this->server->getPluginManager()->callEvent($ev = new EntityMotionEvent($this, $motion));
if($ev->isCancelled()){
return false;
}
@@ -1130,7 +1131,7 @@ abstract class Entity extends Location implements Metadatable{
if(!$this->justCreated){
if($this instanceof Player){
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[0, $this->motionX, $this->motionY, $this->motionZ]
];
@@ -1169,14 +1170,14 @@ abstract class Entity extends Location implements Metadatable{
}
$from = Position::fromObject($this, $this->level);
$to = Position::fromObject($pos, $pos instanceof Position ? $pos->getLevel() : $this->level);
$this->server->getPluginManager()->callEvent($ev = EntityTeleportEvent::createEvent($this, $from, $to));
$this->server->getPluginManager()->callEvent($ev = new EntityTeleportEvent($this, $from, $to));
if($ev->isCancelled()){
return false;
}
$this->ySize = 0;
$pos = $ev->getTo();
$this->setMotion(Vector3::createVector(0, 0, 0));
$this->setMotion(new Vector3(0, 0, 0));
if($this->setPositionAndRotation($pos, $yaw === null ? $this->yaw : $yaw, $pitch === null ? $this->pitch : $pitch, true) !== false){
$this->fallDistance = 0;
$this->onGround = true;
@@ -1207,7 +1208,7 @@ abstract class Entity extends Location implements Metadatable{
public function close(){
if(!$this->closed){
$this->server->getPluginManager()->callEvent(EntityDespawnEvent::createEvent($this));
$this->server->getPluginManager()->callEvent(new EntityDespawnEvent($this));
$this->closed = true;
unset($this->level->updateEntities[$this->id]);
if($this->chunk instanceof FullChunk){

View File

@@ -90,8 +90,7 @@ class FallingSand extends Entity{
if(!$this->dead){
if($this->ticksLived === 1){
$pos = Vector3::cloneVector($this);
$block = $this->level->getBlock($pos->floor());
$block = $this->level->getBlock((new Vector3($this->x, $this->y, $this->z))->floor());
if($block->getID() != $this->blockId){
$this->kill();
return true;
@@ -110,8 +109,7 @@ class FallingSand extends Entity{
$this->motionY *= 1 - $this->drag;
$this->motionZ *= $friction;
$pos = Vector3::cloneVector($this);
$pos = $pos->floor();
$pos = (new Vector3($this->x, $this->y, $this->z))->floor();
if($this->onGround){
$this->kill();
@@ -119,7 +117,7 @@ class FallingSand extends Entity{
if(!$block->isFullBlock){
$this->getLevel()->dropItem($this, ItemItem::get($this->getBlock(), $this->getDamage(), 1));
}else{
$this->server->getPluginManager()->callEvent($ev = EntityBlockChangeEvent::createEvent($this, $block, Block::get($this->getBlock(), $this->getDamage())));
$this->server->getPluginManager()->callEvent($ev = new EntityBlockChangeEvent($this, $block, Block::get($this->getBlock(), $this->getDamage())));
if(!$ev->isCancelled()){
$this->getLevel()->setBlock($pos, $ev->getTo(), true);
}
@@ -154,7 +152,7 @@ class FallingSand extends Entity{
}
public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool();
$pk = new AddEntityPacket();
$pk->type = FallingSand::NETWORK_ID;
$pk->eid = $this->getID();
$pk->x = $this->x;
@@ -163,7 +161,7 @@ class FallingSand extends Entity{
$pk->did = -($this->getBlock() | $this->getDamage() << 0x10);
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -156,7 +156,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
if($player !== $this and !isset($this->hasSpawned[$player->getID()])){
$this->hasSpawned[$player->getID()] = $player;
$pk = AddPlayerPacket::getFromPool();
$pk = new AddPlayerPacket();
$pk->clientID = 0;
if($player->getRemoveFormat()){
$pk->username = TextFormat::clean($this->nameTag);
@@ -174,7 +174,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
$pk->metadata = $this->getData();
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
@@ -188,7 +188,7 @@ class Human extends Creature implements ProjectileSource, InventoryHolder{
public function despawnFrom(Player $player){
if(isset($this->hasSpawned[$player->getID()])){
$pk = RemovePlayerPacket::getFromPool();
$pk = new RemovePlayerPacket();
$pk->eid = $this->id;
$pk->clientID = 0;
$player->dataPacket($pk);

View File

@@ -71,7 +71,7 @@ class Item extends Entity{
$this->item = ItemItem::get($this->namedtag->Item["id"], $this->namedtag->Item["Damage"], $this->namedtag->Item["Count"]);
$this->server->getPluginManager()->callEvent(ItemSpawnEvent::createEvent($this));
$this->server->getPluginManager()->callEvent(new ItemSpawnEvent($this));
}
public function onUpdate($currentTick){
@@ -100,7 +100,7 @@ class Item extends Entity{
$friction = 1 - $this->drag;
if($this->onGround and ($this->motionX != 0 or $this->motionZ != 0)){
$friction = $this->getLevel()->getBlock(Vector3::createVector($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction;
$friction = $this->getLevel()->getBlock(new Vector3($this->getFloorX(), $this->getFloorY() - 1, $this->getFloorZ()))->frictionFactor * $friction;
}
$this->motionX *= $friction;
@@ -114,7 +114,7 @@ class Item extends Entity{
}
if($this->age > 6000){
$this->server->getPluginManager()->callEvent($ev = ItemDespawnEvent::createEvent($this));
$this->server->getPluginManager()->callEvent($ev = new ItemDespawnEvent($this));
if($ev->isCancelled()){
$this->age = 0;
}else{
@@ -227,7 +227,7 @@ class Item extends Entity{
}
public function spawnTo(Player $player){
$pk = AddItemEntityPacket::getFromPool();
$pk = new AddItemEntityPacket();
$pk->eid = $this->getID();
$pk->x = $this->x;
$pk->y = $this->y;
@@ -238,7 +238,7 @@ class Item extends Entity{
$pk->item = $this->getItem();
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -91,7 +91,7 @@ abstract class Living extends Entity implements Damageable{
}
}
$pk = EntityEventPacket::getFromPool();
$pk = new EntityEventPacket();
$pk->eid = $this->getID();
$pk->event = 2; //Ouch!
Server::broadcastPacket($this->hasSpawned, $pk);
@@ -114,7 +114,7 @@ abstract class Living extends Entity implements Damageable{
$f = sqrt($x ** 2 + $z ** 2);
$base = 0.4;
$motion = Vector3::createVector($this->motionX, $this->motionY, $this->motionZ);
$motion = new Vector3($this->motionX, $this->motionY, $this->motionZ);
$motion->x /= 2;
$motion->y /= 2;
@@ -139,7 +139,7 @@ abstract class Living extends Entity implements Damageable{
return;
}
parent::kill();
$this->server->getPluginManager()->callEvent($ev = EntityDeathEvent::createEvent($this, $this->getDrops()));
$this->server->getPluginManager()->callEvent($ev = new EntityDeathEvent($this, $this->getDrops()));
foreach($ev->getDrops() as $item){
$this->getLevel()->dropItem($this, $item);
}
@@ -147,10 +147,10 @@ abstract class Living extends Entity implements Damageable{
public function entityBaseTick($tickDiff = 1){
Timings::$timerEntityBaseTick->startTiming();
parent::entityBaseTick();
parent::entityBaseTick($tickDiff);
if($this->dead !== true and $this->isInsideOfSolid()){
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_SUFFOCATION, 1);
$this->attack($ev->getFinalDamage(), $ev);
}
@@ -159,7 +159,7 @@ abstract class Living extends Entity implements Damageable{
if($this->airTicks <= -20){
$this->airTicks = 0;
$ev = EntityDamageEvent::createEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$ev = new EntityDamageEvent($this, EntityDamageEvent::CAUSE_DROWNING, 2);
$this->attack($ev->getFinalDamage(), $ev);
}
}else{

View File

@@ -128,7 +128,7 @@ class PrimedTNT extends Entity implements Explosive{
}
public function explode(){
$this->server->getPluginManager()->callEvent($ev = ExplosionPrimeEvent::createEvent($this, 4));
$this->server->getPluginManager()->callEvent($ev = new ExplosionPrimeEvent($this, 4));
if(!$ev->isCancelled()){
$explosion = new Explosion($this, $ev->getForce(), $this);
@@ -140,7 +140,7 @@ class PrimedTNT extends Entity implements Explosive{
}
public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool();
$pk = new AddEntityPacket();
$pk->type = PrimedTNT::NETWORK_ID;
$pk->eid = $this->getID();
$pk->x = $this->x;
@@ -149,7 +149,7 @@ class PrimedTNT extends Entity implements Explosive{
$pk->did = 0;
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -93,7 +93,7 @@ abstract class Projectile extends Entity{
$this->keepMovement = $this->checkObstruction($this->x, ($this->boundingBox->minY + $this->boundingBox->maxY) / 2, $this->z);
$moveVector = Vector3::createVector($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
$moveVector = new Vector3($this->x + $this->motionX, $this->y + $this->motionY, $this->z + $this->motionZ);
$list = $this->getLevel()->getCollidingEntities($this->boundingBox->addCoord($this->motionX, $this->motionY, $this->motionZ)->expand(1, 1, 1), $this);
@@ -129,18 +129,18 @@ abstract class Projectile extends Entity{
if($movingObjectPosition !== null){
if($movingObjectPosition->entityHit !== null){
$this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this));
$this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this));
$motion = sqrt($this->motionX ** 2 + $this->motionY ** 2 + $this->motionZ ** 2);
$damage = ceil($motion * $this->damage);
$ev = EntityDamageByEntityEvent::createEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage);
$ev = new EntityDamageByEntityEvent($this->shootingEntity === null ? $this : $this->shootingEntity, $movingObjectPosition->entityHit, EntityDamageEvent::CAUSE_PROJECTILE, $damage);
$movingObjectPosition->entityHit->attack($ev->getFinalDamage(), $ev);
if($this->fireTicks > 0){
$ev = EntityCombustByEntityEvent::createEvent($this, $movingObjectPosition->entityHit, 5);
$ev = new EntityCombustByEntityEvent($this, $movingObjectPosition->entityHit, 5);
$this->server->getPluginManager()->callEvent($ev);
if(!$ev->isCancelled()){
$movingObjectPosition->entityHit->setOnFire($ev->getDuration());
@@ -159,7 +159,7 @@ abstract class Projectile extends Entity{
$this->motionY = 0;
$this->motionZ = 0;
$this->server->getPluginManager()->callEvent(ProjectileHitEvent::createEvent($this));
$this->server->getPluginManager()->callEvent(new ProjectileHitEvent($this));
}
if(!$this->onGround or $this->motionX != 0 or $this->motionY != 0 or $this->motionZ != 0){

View File

@@ -69,7 +69,7 @@ class Snowball extends Projectile{
}
public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool();
$pk = new AddEntityPacket();
$pk->type = Snowball::NETWORK_ID;
$pk->eid = $this->getID();
$pk->x = $this->x;
@@ -78,7 +78,7 @@ class Snowball extends Projectile{
$pk->did = 0; //TODO: send motion here
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -55,7 +55,7 @@ class Villager extends Creature implements NPC, Ageable{
}
public function spawnTo(Player $player){
$pk = AddMobPacket::getFromPool();
$pk = new AddMobPacket();
$pk->eid = $this->getID();
$pk->type = Villager::NETWORK_ID;
$pk->x = $this->x;
@@ -66,7 +66,7 @@ class Villager extends Creature implements NPC, Ageable{
$pk->metadata = $this->getData();
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];

View File

@@ -46,7 +46,7 @@ class Zombie extends Monster{
public function spawnTo(Player $player){
$pk = AddMobPacket::getFromPool();
$pk = new AddMobPacket();
$pk->eid = $this->getID();
$pk->type = Zombie::NETWORK_ID;
$pk->x = $this->x;
@@ -57,7 +57,7 @@ class Zombie extends Monster{
$pk->metadata = $this->getData();
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk = new SetEntityMotionPacket();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];