added throwable eggs and refactor some projectile logic

close #1473
This commit is contained in:
Dylan K. Taylor 2017-10-19 14:12:44 +01:00
parent 11cc20972f
commit 2db13bd114
5 changed files with 108 additions and 31 deletions

View File

@ -30,6 +30,7 @@ use pocketmine\block\Block;
use pocketmine\block\BlockFactory;
use pocketmine\block\Water;
use pocketmine\entity\projectile\Arrow;
use pocketmine\entity\projectile\Egg;
use pocketmine\entity\projectile\Snowball;
use pocketmine\event\entity\EntityDamageEvent;
use pocketmine\event\entity\EntityDespawnEvent;
@ -219,6 +220,7 @@ abstract class Entity extends Location implements Metadatable{
public static function init(){
Entity::registerEntity(Arrow::class);
Entity::registerEntity(Egg::class);
Entity::registerEntity(FallingSand::class);
Entity::registerEntity(Item::class);
Entity::registerEntity(PrimedTNT::class);

View File

@ -0,0 +1,45 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\projectile;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\Player;
class Egg extends Throwable{
const NETWORK_ID = 82;
public function spawnTo(Player $player){
$pk = new AddEntityPacket();
$pk->type = Egg::NETWORK_ID;
$pk->entityRuntimeId = $this->getId();
$pk->position = $this->asVector3();
$pk->motion = $this->getMotion();
$pk->metadata = $this->dataProperties;
$player->dataPacket($pk);
parent::spawnTo($player);
}
//TODO: spawn chickens on collision
}

View File

@ -23,40 +23,12 @@ declare(strict_types=1);
namespace pocketmine\entity\projectile;
use pocketmine\entity\Entity;
use pocketmine\level\Level;
use pocketmine\nbt\tag\CompoundTag;
use pocketmine\network\mcpe\protocol\AddEntityPacket;
use pocketmine\Player;
class Snowball extends Projectile{
class Snowball extends Throwable{
const NETWORK_ID = 81;
public $width = 0.25;
public $height = 0.25;
protected $gravity = 0.03;
protected $drag = 0.01;
public function __construct(Level $level, CompoundTag $nbt, Entity $shootingEntity = null){
parent::__construct($level, $nbt, $shootingEntity);
}
public function entityBaseTick(int $tickDiff = 1) : bool{
if($this->closed){
return false;
}
$hasUpdate = parent::entityBaseTick($tickDiff);
if($this->age > 1200 or $this->isCollided){
$this->kill();
$hasUpdate = true;
}
return $hasUpdate;
}
public function spawnTo(Player $player){
$pk = new AddEntityPacket();
$pk->type = Snowball::NETWORK_ID;

View File

@ -0,0 +1,49 @@
<?php
/*
*
* ____ _ _ __ __ _ __ __ ____
* | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
* | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
* | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
* |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* @author PocketMine Team
* @link http://www.pocketmine.net/
*
*
*/
declare(strict_types=1);
namespace pocketmine\entity\projectile;
abstract class Throwable extends Projectile{
public $width = 0.25;
public $height = 0.25;
protected $gravity = 0.03;
protected $drag = 0.01;
public function entityBaseTick(int $tickDiff = 1) : bool{
if($this->closed){
return false;
}
$hasUpdate = parent::entityBaseTick($tickDiff);
if($this->age > 1200 or $this->isCollided){
//TODO: hit particles
$this->kill();
$hasUpdate = true;
}
return $hasUpdate;
}
}

View File

@ -23,12 +23,21 @@ declare(strict_types=1);
namespace pocketmine\item;
class Egg extends Item{
class Egg extends ProjectileItem{
public function __construct(int $meta = 0){
parent::__construct(self::EGG, $meta, "Egg");
}
//TODO
public function getMaxStackSize() : int{
return 16;
}
public function getProjectileEntityType() : string{
return "Egg";
}
public function getThrowForce() : float{
return 1.5;
}
}