Added Snowballs

This commit is contained in:
Shoghi Cervantes
2014-10-28 12:13:31 +01:00
parent b9f1812f61
commit a5b85c549a
4 changed files with 257 additions and 145 deletions

View File

@ -22,10 +22,68 @@
namespace pocketmine\entity;
use pocketmine\level\format\FullChunk;
use pocketmine\nbt\tag\Compound;
use pocketmine\nbt\tag\String;
use pocketmine\network\protocol\AddEntityPacket;
use pocketmine\network\protocol\SetEntityMotionPacket;
use pocketmine\Player;
class Snowball extends Projectile{
const NETWORK_ID = 81;
public $width = 0.25;
public $length = 0.25;
public $height = 0.25;
protected $gravity = 0.03;
protected $drag = 0.01;
public function __construct(FullChunk $chunk, Compound $nbt, Entity $shootingEntity = null){
$this->shootingEntity = $shootingEntity;
parent::__construct($chunk, $nbt);
}
public function onUpdate($currentTick){
if($this->closed){
return false;
}
$this->timings->startTiming();
$hasUpdate = parent::onUpdate($currentTick);
if($this->age > 1200 or $this->onGround){
$this->kill();
$hasUpdate = true;
}
$this->timings->stopTiming();
return $hasUpdate;
}
protected function initEntity(){
$this->namedtag->id = new String("id", "Snowball");
parent::initEntity();
}
public function spawnTo(Player $player){
$pk = AddEntityPacket::getFromPool();
$pk->type = Snowball::NETWORK_ID;
$pk->eid = $this->getID();
$pk->x = $this->x;
$pk->y = $this->y;
$pk->z = $this->z;
$pk->did = 0; //TODO: send motion here
$player->dataPacket($pk);
$pk = SetEntityMotionPacket::getFromPool();
$pk->entities = [
[$this->getID(), $this->motionX, $this->motionY, $this->motionZ]
];
$player->dataPacket($pk);
parent::spawnTo($player);
}
}