-
Notifications
You must be signed in to change notification settings - Fork 0
/
BoatItem.php
63 lines (56 loc) · 1.79 KB
/
BoatItem.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace MonoAdrian23\FunBoats;
use pocketmine\block\{
Block, Planks
};
use pocketmine\item\Boat as BoatItemPM;
use pocketmine\math\Vector3;
use pocketmine\Player;
class BoatItem extends BoatItemPM{
/**
* BoatItem constructor.
*
* @param int $meta
*/
public function __construct(int $meta = 0){
parent::__construct($meta);
$this->name = $this->getVanillaName();
}
/**
* Returns the vanilla name of the item, disregarding custom names.
*
* @return string
*/
public function getVanillaName() : string{
static $names = [
Planks::OAK => "%item.boat.oak.name",
Planks::SPRUCE => "%item.boat.spruce.name",
Planks::BIRCH => "%item.boat.birch.name",
Planks::JUNGLE => "%item.boat.jungle.name",
Planks::ACACIA => "%item.boat.acacia.name",
Planks::DARK_OAK => "%item.boat.dark_oak.name",
];
return $names[$this->meta] ?? "Boat";
}
/**
* Called when a player uses this item on a block.
*
* @param Player $player
* @param Block $blockReplace
* @param Block $blockClicked
* @param int $face
* @param Vector3 $clickVector
*
* @return bool
*/
public function onActivate(Player $player, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector) : bool{
//Spawn boat entity
$nbt = BoatEntity::createBaseNBT($blockClicked->getSide($face)->add(0.5, 0.5, 0.5));
$nbt->setInt(BoatEntity::TAG_WOOD_ID, $this->meta);
$boat = new BoatEntity($player->getLevel(), $nbt);
$boat->spawnToAll();
//Reduce boat item count
--$this->count;
return true;
}
}