mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-06-06 20:07:09 +00:00
Merge branch 'php/7.0'
This commit is contained in:
commit
1c02c747ca
@ -34,11 +34,9 @@ use pocketmine\entity\Entity;
|
|||||||
use pocketmine\entity\Human;
|
use pocketmine\entity\Human;
|
||||||
use pocketmine\entity\Item as DroppedItem;
|
use pocketmine\entity\Item as DroppedItem;
|
||||||
use pocketmine\entity\Living;
|
use pocketmine\entity\Living;
|
||||||
use pocketmine\entity\Projectile;
|
|
||||||
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
use pocketmine\event\entity\EntityDamageByBlockEvent;
|
||||||
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
use pocketmine\event\entity\EntityDamageByEntityEvent;
|
||||||
use pocketmine\event\entity\EntityDamageEvent;
|
use pocketmine\event\entity\EntityDamageEvent;
|
||||||
use pocketmine\event\entity\ProjectileLaunchEvent;
|
|
||||||
use pocketmine\event\inventory\CraftItemEvent;
|
use pocketmine\event\inventory\CraftItemEvent;
|
||||||
use pocketmine\event\inventory\InventoryCloseEvent;
|
use pocketmine\event\inventory\InventoryCloseEvent;
|
||||||
use pocketmine\event\inventory\InventoryPickupArrowEvent;
|
use pocketmine\event\inventory\InventoryPickupArrowEvent;
|
||||||
@ -88,7 +86,6 @@ use pocketmine\level\format\Chunk;
|
|||||||
use pocketmine\level\Level;
|
use pocketmine\level\Level;
|
||||||
use pocketmine\level\Location;
|
use pocketmine\level\Location;
|
||||||
use pocketmine\level\Position;
|
use pocketmine\level\Position;
|
||||||
use pocketmine\level\sound\LaunchSound;
|
|
||||||
use pocketmine\level\WeakPosition;
|
use pocketmine\level\WeakPosition;
|
||||||
use pocketmine\math\AxisAlignedBB;
|
use pocketmine\math\AxisAlignedBB;
|
||||||
use pocketmine\math\Vector2;
|
use pocketmine\math\Vector2;
|
||||||
@ -97,10 +94,7 @@ use pocketmine\metadata\MetadataValue;
|
|||||||
use pocketmine\nbt\NBT;
|
use pocketmine\nbt\NBT;
|
||||||
use pocketmine\nbt\tag\ByteTag;
|
use pocketmine\nbt\tag\ByteTag;
|
||||||
use pocketmine\nbt\tag\CompoundTag;
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
use pocketmine\nbt\tag\DoubleTag;
|
|
||||||
use pocketmine\nbt\tag\FloatTag;
|
|
||||||
use pocketmine\nbt\tag\IntTag;
|
use pocketmine\nbt\tag\IntTag;
|
||||||
use pocketmine\nbt\tag\ListTag;
|
|
||||||
use pocketmine\nbt\tag\LongTag;
|
use pocketmine\nbt\tag\LongTag;
|
||||||
use pocketmine\nbt\tag\StringTag;
|
use pocketmine\nbt\tag\StringTag;
|
||||||
use pocketmine\network\mcpe\PlayerNetworkSessionAdapter;
|
use pocketmine\network\mcpe\PlayerNetworkSessionAdapter;
|
||||||
@ -2382,7 +2376,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
$this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY);
|
$this->level->sendBlocks([$this], [$target, $block], UpdateBlockPacket::FLAG_ALL_PRIORITY);
|
||||||
return true;
|
return true;
|
||||||
}elseif($packet->face === -1){
|
}elseif($packet->face === -1){
|
||||||
$aimPos = new Vector3(
|
$directionVector = new Vector3(
|
||||||
-sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI),
|
-sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI),
|
||||||
-sin($this->pitch / 180 * M_PI),
|
-sin($this->pitch / 180 * M_PI),
|
||||||
cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)
|
cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)
|
||||||
@ -2397,7 +2391,7 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
$item = $this->inventory->getItemInHand();
|
$item = $this->inventory->getItemInHand();
|
||||||
}
|
}
|
||||||
|
|
||||||
$ev = new PlayerInteractEvent($this, $item, $aimPos, $packet->face, PlayerInteractEvent::RIGHT_CLICK_AIR);
|
$ev = new PlayerInteractEvent($this, $item, $directionVector, $packet->face, PlayerInteractEvent::RIGHT_CLICK_AIR);
|
||||||
|
|
||||||
$this->server->getPluginManager()->callEvent($ev);
|
$this->server->getPluginManager()->callEvent($ev);
|
||||||
|
|
||||||
@ -2406,42 +2400,8 @@ class Player extends Human implements CommandSender, ChunkLoader, IPlayer{
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($item->getId() === Item::SNOWBALL){
|
if($item->onClickAir($this, $directionVector) and $this->isSurvival()){
|
||||||
$nbt = new CompoundTag("", [
|
$this->inventory->setItemInHand($item);
|
||||||
new ListTag("Pos", [
|
|
||||||
new DoubleTag("", $this->x),
|
|
||||||
new DoubleTag("", $this->y + $this->getEyeHeight()),
|
|
||||||
new DoubleTag("", $this->z)
|
|
||||||
]),
|
|
||||||
new ListTag("Motion", [
|
|
||||||
new DoubleTag("", $aimPos->x),
|
|
||||||
new DoubleTag("", $aimPos->y),
|
|
||||||
new DoubleTag("", $aimPos->z)
|
|
||||||
]),
|
|
||||||
new ListTag("Rotation", [
|
|
||||||
new FloatTag("", $this->yaw),
|
|
||||||
new FloatTag("", $this->pitch)
|
|
||||||
]),
|
|
||||||
]);
|
|
||||||
|
|
||||||
$f = 1.5;
|
|
||||||
$snowball = Entity::createEntity("Snowball", $this->getLevel(), $nbt, $this);
|
|
||||||
$snowball->setMotion($snowball->getMotion()->multiply($f));
|
|
||||||
if($this->isSurvival()){
|
|
||||||
$item->setCount($item->getCount() - 1);
|
|
||||||
$this->inventory->setItemInHand($item->getCount() > 0 ? $item : ItemFactory::get(Item::AIR));
|
|
||||||
}
|
|
||||||
if($snowball instanceof Projectile){
|
|
||||||
$this->server->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($snowball));
|
|
||||||
if($projectileEv->isCancelled()){
|
|
||||||
$snowball->kill();
|
|
||||||
}else{
|
|
||||||
$snowball->spawnToAll();
|
|
||||||
$this->level->addSound(new LaunchSound($this), $this->getViewers());
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
$snowball->spawnToAll();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->setGenericFlag(self::DATA_FLAG_ACTION, true);
|
$this->setGenericFlag(self::DATA_FLAG_ACTION, true);
|
||||||
|
@ -829,8 +829,22 @@ class Item implements ItemIds, \JsonSerializable{
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Called when a player uses the item on air, for example throwing a projectile.
|
||||||
|
* Returns whether the item was changed, for example count decrease or durability change.
|
||||||
|
*
|
||||||
|
* @param Player $player
|
||||||
|
* @param Vector3 $directionVector
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
*/
|
||||||
|
public function onClickAir(Player $player, Vector3 $directionVector) : bool{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a player is using this item and releases it. Used to handle bow shoot actions.
|
* Called when a player is using this item and releases it. Used to handle bow shoot actions.
|
||||||
|
* Returns whether the item was changed, for example count decrease or durability change.
|
||||||
*
|
*
|
||||||
* @param Player $player
|
* @param Player $player
|
||||||
* @return bool
|
* @return bool
|
||||||
|
80
src/pocketmine/item/ProjectileItem.php
Normal file
80
src/pocketmine/item/ProjectileItem.php
Normal file
@ -0,0 +1,80 @@
|
|||||||
|
<?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\item;
|
||||||
|
|
||||||
|
use pocketmine\entity\Entity;
|
||||||
|
use pocketmine\entity\Projectile;
|
||||||
|
use pocketmine\event\entity\ProjectileLaunchEvent;
|
||||||
|
use pocketmine\level\sound\LaunchSound;
|
||||||
|
use pocketmine\math\Vector3;
|
||||||
|
use pocketmine\nbt\tag\CompoundTag;
|
||||||
|
use pocketmine\nbt\tag\DoubleTag;
|
||||||
|
use pocketmine\nbt\tag\FloatTag;
|
||||||
|
use pocketmine\nbt\tag\ListTag;
|
||||||
|
use pocketmine\Player;
|
||||||
|
|
||||||
|
abstract class ProjectileItem extends Item{
|
||||||
|
|
||||||
|
abstract public function getProjectileEntityType() : string;
|
||||||
|
|
||||||
|
abstract public function getThrowForce() : float;
|
||||||
|
|
||||||
|
public function onClickAir(Player $player, Vector3 $directionVector) : bool{
|
||||||
|
$nbt = new CompoundTag("", [
|
||||||
|
new ListTag("Pos", [
|
||||||
|
new DoubleTag("", $player->x),
|
||||||
|
new DoubleTag("", $player->y + $player->getEyeHeight()),
|
||||||
|
new DoubleTag("", $player->z)
|
||||||
|
]),
|
||||||
|
new ListTag("Motion", [
|
||||||
|
new DoubleTag("", $directionVector->x),
|
||||||
|
new DoubleTag("", $directionVector->y),
|
||||||
|
new DoubleTag("", $directionVector->z)
|
||||||
|
]),
|
||||||
|
new ListTag("Rotation", [
|
||||||
|
new FloatTag("", $player->yaw),
|
||||||
|
new FloatTag("", $player->pitch)
|
||||||
|
]),
|
||||||
|
]);
|
||||||
|
|
||||||
|
$snowball = Entity::createEntity($this->getProjectileEntityType(), $player->getLevel(), $nbt, $player);
|
||||||
|
$snowball->setMotion($snowball->getMotion()->multiply($this->getThrowForce()));
|
||||||
|
|
||||||
|
$this->count--;
|
||||||
|
|
||||||
|
if($snowball instanceof Projectile){
|
||||||
|
$player->getServer()->getPluginManager()->callEvent($projectileEv = new ProjectileLaunchEvent($snowball));
|
||||||
|
if($projectileEv->isCancelled()){
|
||||||
|
$snowball->kill();
|
||||||
|
}else{
|
||||||
|
$snowball->spawnToAll();
|
||||||
|
$player->getLevel()->addSound(new LaunchSound($player), $player->getViewers());
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
$snowball->spawnToAll();
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
@ -23,8 +23,7 @@ declare(strict_types=1);
|
|||||||
|
|
||||||
namespace pocketmine\item;
|
namespace pocketmine\item;
|
||||||
|
|
||||||
|
class Snowball extends ProjectileItem{
|
||||||
class Snowball extends Item{
|
|
||||||
public function __construct(int $meta = 0){
|
public function __construct(int $meta = 0){
|
||||||
parent::__construct(self::SNOWBALL, $meta, "Snowball");
|
parent::__construct(self::SNOWBALL, $meta, "Snowball");
|
||||||
}
|
}
|
||||||
@ -33,4 +32,11 @@ class Snowball extends Item{
|
|||||||
return 16;
|
return 16;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getProjectileEntityType() : string{
|
||||||
|
return "Snowball";
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getThrowForce() : float{
|
||||||
|
return 1.5;
|
||||||
|
}
|
||||||
}
|
}
|
@ -62,21 +62,19 @@ class Sign extends Spawnable{
|
|||||||
* @param null|string $line2
|
* @param null|string $line2
|
||||||
* @param null|string $line3
|
* @param null|string $line3
|
||||||
* @param null|string $line4
|
* @param null|string $line4
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
*/
|
||||||
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
|
public function setText($line1 = "", $line2 = "", $line3 = "", $line4 = ""){
|
||||||
if($line1 !== null){
|
if($line1 !== null){
|
||||||
$this->namedtag->Text1->setValue("Text1", $line1);
|
$this->namedtag->Text1->setValue($line1);
|
||||||
}
|
}
|
||||||
if($line2 !== null){
|
if($line2 !== null){
|
||||||
$this->namedtag->Text2->setValue("Text2", $line2);
|
$this->namedtag->Text2->setValue($line2);
|
||||||
}
|
}
|
||||||
if($line3 !== null){
|
if($line3 !== null){
|
||||||
$this->namedtag->Text3->setValue("Text3", $line3);
|
$this->namedtag->Text3->setValue($line3);
|
||||||
}
|
}
|
||||||
if($line4 !== null){
|
if($line4 !== null){
|
||||||
$this->namedtag->Text4->setValue("Text4", $line4);
|
$this->namedtag->Text4->setValue($line4);
|
||||||
}
|
}
|
||||||
$this->onChanged();
|
$this->onChanged();
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user