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