PocketMine-MP 5.33.2 git-1133d49c924b4358c79d44eeb97dcbf56cb4d1eb
Loading...
Searching...
No Matches
DragonEgg.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\block;
25
27use pocketmine\block\utils\FallableTrait;
28use pocketmine\block\utils\SupportType;
33use pocketmine\player\GameMode;
37use function max;
38use function min;
39use function mt_rand;
40
41class DragonEgg extends Transparent implements Fallable{
42 use FallableTrait;
43
44 public function getLightLevel() : int{
45 return 1;
46 }
47
48 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
49 $this->teleport();
50 return true;
51 }
52
53 public function onAttack(Item $item, Facing $face, ?Player $player = null) : bool{
54 if($player !== null && $player->getGamemode() !== GameMode::CREATIVE){
55 $this->teleport();
56 return true;
57 }
58 return false;
59 }
60
61 public function teleport() : void{
62 $world = $this->position->getWorld();
63 for($tries = 0; $tries < 16; ++$tries){
64 $block = $world->getBlockAt(
65 $this->position->x + mt_rand(-16, 16),
66 max(World::Y_MIN, min(World::Y_MAX - 1, $this->position->y + mt_rand(-8, 8))),
67 $this->position->z + mt_rand(-16, 16)
68 );
69 if($block instanceof Air){
70 $ev = new BlockTeleportEvent($this, $block->position);
71 $ev->call();
72 if($ev->isCancelled()){
73 break;
74 }
75
76 $blockPos = $ev->getTo();
77 $world->addParticle($this->position, new DragonEggTeleportParticle($this->position->x - $blockPos->x, $this->position->y - $blockPos->y, $this->position->z - $blockPos->z));
78 $world->setBlock($this->position, VanillaBlocks::AIR());
79 $world->setBlock($blockPos, $this);
80 break;
81 }
82 }
83 }
84
85 public function getSupportType(Facing $facing) : SupportType{
86 return SupportType::NONE;
87 }
88}
onAttack(Item $item, Facing $face, ?Player $player=null)
Definition DragonEgg.php:53
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition DragonEgg.php:48
getSupportType(Facing $facing)
Definition DragonEgg.php:85