mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-07-03 00:29:54 +00:00
parent
11cc20972f
commit
2db13bd114
@ -30,6 +30,7 @@ use pocketmine\block\Block;
|
|||||||
use pocketmine\block\BlockFactory;
|
use pocketmine\block\BlockFactory;
|
||||||
use pocketmine\block\Water;
|
use pocketmine\block\Water;
|
||||||
use pocketmine\entity\projectile\Arrow;
|
use pocketmine\entity\projectile\Arrow;
|
||||||
|
use pocketmine\entity\projectile\Egg;
|
||||||
use pocketmine\entity\projectile\Snowball;
|
use pocketmine\entity\projectile\Snowball;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\event\entity\EntityDespawnEvent;
|
use pocketmine\event\entity\EntityDespawnEvent;
|
||||||
@ -219,6 +220,7 @@ abstract class Entity extends Location implements Metadatable{
|
|||||||
|
|
||||||
public static function init(){
|
public static function init(){
|
||||||
Entity::registerEntity(Arrow::class);
|
Entity::registerEntity(Arrow::class);
|
||||||
|
Entity::registerEntity(Egg::class);
|
||||||
Entity::registerEntity(FallingSand::class);
|
Entity::registerEntity(FallingSand::class);
|
||||||
Entity::registerEntity(Item::class);
|
Entity::registerEntity(Item::class);
|
||||||
Entity::registerEntity(PrimedTNT::class);
|
Entity::registerEntity(PrimedTNT::class);
|
||||||
|
45
src/pocketmine/entity/projectile/Egg.php
Normal file
45
src/pocketmine/entity/projectile/Egg.php
Normal 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
|
||||||
|
}
|
@ -23,40 +23,12 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\entity\projectile;
|
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\network\mcpe\protocol\AddEntityPacket;
|
||||||
use pocketmine\Player;
|
use pocketmine\Player;
|
||||||
|
|
||||||
class Snowball extends Projectile{
|
class Snowball extends Throwable{
|
||||||
const NETWORK_ID = 81;
|
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){
|
public function spawnTo(Player $player){
|
||||||
$pk = new AddEntityPacket();
|
$pk = new AddEntityPacket();
|
||||||
$pk->type = Snowball::NETWORK_ID;
|
$pk->type = Snowball::NETWORK_ID;
|
||||||
|
49
src/pocketmine/entity/projectile/Throwable.php
Normal file
49
src/pocketmine/entity/projectile/Throwable.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
@ -23,12 +23,21 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\item;
|
namespace pocketmine\item;
|
||||||
|
|
||||||
class Egg extends Item{
|
class Egg extends ProjectileItem{
|
||||||
public function __construct(int $meta = 0){
|
public function __construct(int $meta = 0){
|
||||||
parent::__construct(self::EGG, $meta, "Egg");
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user