mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-09-07 10:22:56 +00:00
Added Snowballs
This commit is contained in:
@ -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);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user