本文整理汇总了PHP中pocketmine\event\inventory\InventoryPickupArrowEvent类的典型用法代码示例。如果您正苦于以下问题:PHP InventoryPickupArrowEvent类的具体用法?PHP InventoryPickupArrowEvent怎么用?PHP InventoryPickupArrowEvent使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了InventoryPickupArrowEvent类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: onUpdate
public function onUpdate($currentTick)
{
if (!$this->loggedIn) {
return false;
}
$tickDiff = $currentTick - $this->lastUpdate;
if ($tickDiff <= 0) {
return true;
}
$this->messageCounter = 2;
$this->lastUpdate = $currentTick;
if ($this->dead === true and $this->spawned) {
++$this->deadTicks;
if ($this->deadTicks >= 10) {
$this->despawnFromAll();
}
return $this->deadTicks < 10;
}
$this->timings->startTiming();
$this->lastUpdate = $currentTick;
if ($this->spawned) {
$this->processMovement($currentTick);
$this->entityBaseTick(1);
if ($this->speed and $this->isSurvival()) {
$speed = sqrt($this->speed->x ** 2 + $this->speed->z ** 2);
if ($speed > 0.45) {
$this->highSpeedTicks += $speed > 3 ? 2 : 1;
if ($this->highSpeedTicks > 40 and !$this->server->getAllowFlight()) {
$this->kick("Flying is not enabled on this server");
return false;
} elseif ($this->highSpeedTicks >= 10 and $this->highSpeedTicks % 4 === 0) {
$this->forceMovement = $this->getPosition();
$this->speed = null;
}
} elseif ($this->highSpeedTicks > 0) {
if ($speed < 22) {
$this->highSpeedTicks = 0;
} else {
$this->highSpeedTicks--;
}
}
}
if ($this->onGround) {
$this->inAirTicks = 0;
} else {
if ($this->inAirTicks > 10 and $this->isSurvival() and !$this->isSleeping()) {
$expectedVelocity = -$this->gravity / $this->drag - -$this->gravity / $this->drag * exp(-$this->drag * ($this->inAirTicks - 2));
$diff = sqrt(abs($this->speed->y - $expectedVelocity));
if ($diff > 0.6 and $expectedVelocity < $this->speed->y and !$this->server->getAllowFlight()) {
if ($this->inAirTicks < 100) {
$this->setMotion(new Vector3(0, $expectedVelocity, 0));
} else {
$this->kick("Flying is not enabled on this server");
return false;
}
}
}
++$this->inAirTicks;
}
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) {
if ($currentTick - $entity->lastUpdate > 1) {
$entity->scheduleUpdate();
}
if ($entity instanceof Arrow and $entity->hadCollision) {
if ($entity->dead !== true) {
$item = Item::get(Item::ARROW, 0, 1);
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$this->inventory->addItem(clone $item);
$entity->kill();
}
} elseif ($entity instanceof DroppedItem) {
if ($entity->dead !== true and $entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
//.........这里部分代码省略.........
示例2: checkNearEntities
protected function checkNearEntities($tickDiff)
{
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) {
$entity->scheduleUpdate();
if (!$entity->isAlive()) {
continue;
}
if ($entity instanceof Arrow and $entity->hadCollision) {
$item = Item::get(Item::ARROW, 0, 1);
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$this->inventory->addItem(clone $item);
$entity->kill();
} elseif ($entity instanceof DroppedItem) {
if ($entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$this->inventory->addItem(clone $item);
$entity->kill();
}
}
}
}
}
示例3: onPickUp
public function onPickUp(\pocketmine\event\inventory\InventoryPickupArrowEvent $event)
{
$event->setCancelled(true);
}
示例4: onUpdate
public function onUpdate($currentTick)
{
if ($this->dead === true and $this->spawned) {
++$this->deadTicks;
if ($this->deadTicks >= 10) {
$this->despawnFromAll();
}
return $this->deadTicks < 10;
}
$this->timings->startTiming();
$this->lastUpdate = $currentTick;
if ($this->spawned) {
$this->processMovement($currentTick);
$this->entityBaseTick(1);
if ($this->onGround) {
$this->inAirTicks = 0;
} else {
if ($this->inAirTicks > 100 and $this->isSurvival() and !$this->isSleeping() and $this->spawned and !$this->server->getAllowFlight()) {
$this->kick("Flying is not enabled on this server");
return false;
} else {
++$this->inAirTicks;
}
}
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) {
if ($currentTick - $entity->lastUpdate > 1) {
$entity->scheduleUpdate();
}
if ($entity instanceof Arrow and $entity->onGround) {
if ($entity->dead !== true) {
$item = Item::get(Item::ARROW, 0, 1);
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$this->inventory->addItem(clone $item, $this);
$entity->kill();
}
} elseif ($entity instanceof DroppedItem) {
if ($entity->dead !== true and $entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$this->inventory->addItem(clone $item, $this);
$entity->kill();
}
}
}
}
}
if ($this->nextChunkOrderRun-- <= 0 or $this->chunk === null) {
$this->orderChunks();
}
if (count($this->loadQueue) > 0 or !$this->spawned) {
$this->sendNextChunk();
}
if (count($this->moveToSend) > 0) {
$pk = new MoveEntityPacket();
$pk->entities = $this->moveToSend;
$this->dataPacket($pk);
$this->moveToSend = [];
}
if (count($this->motionToSend) > 0) {
$pk = new SetEntityMotionPacket();
$pk->entities = $this->motionToSend;
$this->dataPacket($pk);
$this->motionToSend = [];
//.........这里部分代码省略.........
示例5: onPickupArrow
public function onPickupArrow(InventoryPickupArrowEvent $event)
{
$holder = $event->getInventory()->getHolder();
if (!$holder instanceof Player) {
return;
}
$session = $this->main->getSession($holder);
if (!$session instanceof Session) {
$event->setCancelled();
return;
}
if ($session->onPickupArrow($event) === false) {
$event->setCancelled();
}
}
示例6: checkNearEntities
protected function checkNearEntities($tickDiff)
{
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(0.5, 0.5, 0.5), $this) as $entity) {
$entity->scheduleUpdate();
if (!$entity->isAlive()) {
continue;
}
if ($entity instanceof Arrow and $entity->hadCollision) {
$item = Item::get(Item::ARROW, $entity->getPotionId(), 1);
$add = false;
if (!$this->server->allowInventoryCheats and !$this->isCreative()) {
if (!$this->getFloatingInventory()->canAddItem($item) or !$this->inventory->canAddItem($item)) {
//The item is added to the floating inventory to allow client to handle the pickup
//We have to also check if it can be added to the real inventory before sending packets.
continue;
}
$add = true;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
if ($add) {
$this->getFloatingInventory()->addItem(clone $item);
}
$entity->kill();
} elseif ($entity instanceof DroppedItem) {
if ($entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
$add = false;
if (!$this->server->allowInventoryCheats and !$this->isCreative()) {
if (!$this->getFloatingInventory()->canAddItem($item) or !$this->inventory->canAddItem($item)) {
continue;
}
$add = true;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk);
$pk = new TakeItemEntityPacket();
$pk->eid = 0;
$pk->target = $entity->getId();
$this->dataPacket($pk);
if ($add) {
$this->getFloatingInventory()->addItem(clone $item);
}
$entity->kill();
}
}
}
}
}
示例7: onUpdate
public function onUpdate($currentTick)
{
if (!$this->loggedIn) {
return \false;
}
if ($this->dead === \true and $this->spawned) {
++$this->deadTicks;
if ($this->deadTicks >= 10) {
$this->despawnFromAll();
}
return $this->deadTicks < 10;
}
$this->timings->startTiming();
if ($this->spawned) {
$this->processMovement($currentTick);
$this->entityBaseTick(1);
if ($this->onGround) {
$this->inAirTicks = 0;
} else {
if ($this->inAirTicks > 20 and $this->isSurvival() and !$this->isSleeping() and $this->spawned and !$this->server->getAllowFlight()) {
$expectedVelocity = -$this->gravity / $this->drag - -$this->gravity / $this->drag * \exp(-$this->drag * ($this->inAirTicks - 2));
$diff = ($this->speed->y - $expectedVelocity) ** 2;
if ($diff > 0.6 and $expectedVelocity < $this->speed->y) {
$this->kick("Disable fly mods.");
}
return \false;
} else {
++$this->inAirTicks;
}
}
foreach ($this->level->getNearbyEntities($this->boundingBox->grow(1, 0.5, 1), $this) as $entity) {
if ($currentTick - $entity->lastUpdate > 1) {
$entity->scheduleUpdate();
}
if ($entity instanceof Arrow and $entity->hadCollision) {
if ($entity->dead !== \true) {
$item = Item::get(Item::ARROW, 0, 1);
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupArrowEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
$this->inventory->addItem(clone $item);
$entity->kill();
}
} elseif ($entity instanceof DroppedItem) {
if ($entity->dead !== \true and $entity->getPickupDelay() <= 0) {
$item = $entity->getItem();
if ($item instanceof Item) {
if ($this->isSurvival() and !$this->inventory->canAddItem($item)) {
continue;
}
$this->server->getPluginManager()->callEvent($ev = new InventoryPickupItemEvent($this->inventory, $entity));
if ($ev->isCancelled()) {
continue;
}
switch ($item->getId()) {
case Item::WOOD:
$this->awardAchievement("mineWood");
break;
case Item::DIAMOND:
$this->awardAchievement("diamond");
break;
}
$pk = new TakeItemEntityPacket();
$pk->eid = $this->getId();
$pk->target = $entity->getId();
Server::broadcastPacket($entity->getViewers(), $pk->setChannel(Network::CHANNEL_ENTITY_SPAWNING));
$this->inventory->addItem(clone $item);
$entity->kill();
}
}
}
}
}
if ($this->nextChunkOrderRun-- <= 0 or $this->chunk === \null) {
$this->orderChunks();
}
if (\count($this->loadQueue) > 0 or !$this->spawned) {
$this->sendNextChunk();
}
if (\count($this->moveToSend) > 0) {
$pk = new MoveEntityPacket();
$pk->entities = $this->moveToSend;
$this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT));
$this->moveToSend = [];
}
if (\count($this->motionToSend) > 0) {
$pk = new SetEntityMotionPacket();
$pk->entities = $this->motionToSend;
$this->batchDataPacket($pk->setChannel(Network::CHANNEL_MOVEMENT));
$this->motionToSend = [];
}
if (\count($this->batchedPackets) > 0) {
//.........这里部分代码省略.........