mirror of
https://github.com/pmmp/PocketMine-MP.git
synced 2025-04-22 08:44:01 +00:00
Improved EntityShootBowEvent
This commit is contained in:
parent
7b09edf048
commit
64bf293c69
@ -1647,7 +1647,7 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
}
|
||||
}
|
||||
|
||||
$f = 1.5;
|
||||
|
||||
$nbt = new Compound("", [
|
||||
"Pos" => new Enum("Pos", [
|
||||
new Double("", $this->x),
|
||||
@ -1655,23 +1655,23 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
new Double("", $this->z)
|
||||
]),
|
||||
"Motion" => new Enum("Motion", [
|
||||
new Double("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI) * $f),
|
||||
new Double("", -sin($this->pitch / 180 * M_PI) * $f),
|
||||
new Double("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI) * $f)
|
||||
new Double("", -sin($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI)),
|
||||
new Double("", -sin($this->pitch / 180 * M_PI)),
|
||||
new Double("", cos($this->yaw / 180 * M_PI) * cos($this->pitch / 180 * M_PI))
|
||||
]),
|
||||
"Rotation" => new Enum("Rotation", [
|
||||
new Float("", $this->yaw),
|
||||
new Float("", $this->pitch)
|
||||
]),
|
||||
]);
|
||||
$arrow = new Arrow($this->chunk, $nbt, $this);
|
||||
|
||||
$ev = new EntityShootBowEvent($this, $bow, $arrow, $f);
|
||||
$f = 1.5;
|
||||
$ev = new EntityShootBowEvent($this, $bow, new Arrow($this->chunk, $nbt, $this), $f);
|
||||
|
||||
$this->server->getPluginManager()->callEvent($ev);
|
||||
|
||||
if($ev->isCancelled()){
|
||||
$arrow->kill();
|
||||
$ev->getProjectile()->kill();
|
||||
}else{
|
||||
if($this->isSurvival()){
|
||||
$this->inventory->removeItem(Item::get(Item::ARROW, 0, 1));
|
||||
@ -1681,7 +1681,8 @@ class Player extends Human implements CommandSender, InventoryHolder, IPlayer{
|
||||
$this->inventory->setItemInHand(Item::get(Item::AIR, 0, 0), $this);
|
||||
}
|
||||
}
|
||||
$arrow->spawnToAll();
|
||||
$ev->getProjectile()->setMotion($ev->getProjectile()->getMotion()->multiply($ev->getForce()));
|
||||
$ev->getProjectile()->spawnToAll();
|
||||
}
|
||||
}
|
||||
//}
|
||||
|
@ -21,6 +21,7 @@
|
||||
|
||||
namespace pocketmine\event\entity;
|
||||
|
||||
use pocketmine\entity\Entity;
|
||||
use pocketmine\entity\Living;
|
||||
use pocketmine\entity\Projectile;
|
||||
use pocketmine\event\Cancellable;
|
||||
@ -64,12 +65,25 @@ class EntityShootBowEvent extends EntityEvent implements Cancellable{
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Projectile
|
||||
* @return Entity
|
||||
*/
|
||||
public function getProjectile(){
|
||||
return $this->projectile;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Entity $projectile
|
||||
*/
|
||||
public function setProjectile(Entity $projectile){
|
||||
if($projectile !== $this->projectile){
|
||||
if(count($this->projectile->getViewers()) === 0){
|
||||
$this->projectile->kill();
|
||||
$this->projectile->close();
|
||||
}
|
||||
$this->projectile = $projectile;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return float
|
||||
*/
|
||||
@ -77,5 +91,12 @@ class EntityShootBowEvent extends EntityEvent implements Cancellable{
|
||||
return $this->force;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $force
|
||||
*/
|
||||
public function setForce($force){
|
||||
$this->force = $force;
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user