PocketMine-MP 5.35.1 git-e32e836dad793a3a3c8ddd8927c00e112b1e576a
Loading...
Searching...
No Matches
item/Trident.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\item;
25
29use pocketmine\entity\projectile\Trident as TridentEntity;
33use function min;
34
35class Trident extends Tool implements Releasable{
36
37 public function getMaxDurability() : int{
38 return 251;
39 }
40
41 public function onReleaseUsing(Player $player, array &$returnedItems) : ItemUseResult{
42 $location = $player->getLocation();
43
44 $diff = $player->getItemUseDuration();
45 if($diff < 14){
46 return ItemUseResult::FAIL;
47 }
48
49 $item = $this->pop();
50 if($player->hasFiniteResources()){
51 $item->applyDamage(1);
52 }
53 $entity = new TridentEntity(Location::fromObject(
54 $player->getEyePos(),
55 $player->getWorld(),
56 ($location->yaw > 180 ? 360 : 0) - $location->yaw,
57 -$location->pitch
58 ), $item, $player);
59 $p = $diff / 20;
60 $baseForce = min((($p ** 2) + $p * 2) / 3, 1) * 2.4;
61 $entity->setMotion($player->getDirectionVector()->multiply($baseForce));
62
63 $ev = new ProjectileLaunchEvent($entity);
64 $ev->call();
65 if($ev->isCancelled()){
66 $ev->getEntity()->flagForDespawn();
67 return ItemUseResult::FAIL;
68 }
69 $ev->getEntity()->spawnToAll();
70 $location->getWorld()->addSound($location, new TridentThrowSound());
71
72 return ItemUseResult::SUCCESS;
73 }
74
75 public function getAttackPoints() : int{
76 return 9;
77 }
78
79 public function canStartUsingItem(Player $player) : bool{
80 return $this->damage < $this->getMaxDurability();
81 }
82
83 public function onAttackEntity(Entity $victim, array &$returnedItems) : bool{
84 return $this->applyDamage(1);
85 }
86
87 public function onDestroyBlock(Block $block, array &$returnedItems) : bool{
88 if(!$block->getBreakInfo()->breaksInstantly()){
89 return $this->applyDamage(2);
90 }
91 return false;
92 }
93}
onAttackEntity(Entity $victim, array &$returnedItems)
onDestroyBlock(Block $block, array &$returnedItems)
onReleaseUsing(Player $player, array &$returnedItems)