PocketMine-MP 5.15.1 git-be6754494fdbbb9dd57c058ba0e33a4a78c4581f
ChorusFruit.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
30use function min;
31use function mt_rand;
32
33class ChorusFruit extends Food{
34
35 public function getFoodRestore() : int{
36 return 4;
37 }
38
39 public function getSaturationRestore() : float{
40 return 2.4;
41 }
42
43 public function requiresHunger() : bool{
44 return false;
45 }
46
47 public function onConsume(Living $consumer) : void{
48 $world = $consumer->getWorld();
49
50 $origin = $consumer->getPosition();
51 $minX = $origin->getFloorX() - 8;
52 $minY = min($origin->getFloorY(), $consumer->getWorld()->getMaxY()) - 8;
53 $minZ = $origin->getFloorZ() - 8;
54
55 $maxX = $minX + 16;
56 $maxY = $minY + 16;
57 $maxZ = $minZ + 16;
58
59 $worldMinY = $world->getMinY();
60
61 for($attempts = 0; $attempts < 16; ++$attempts){
62 $x = mt_rand($minX, $maxX);
63 $y = mt_rand($minY, $maxY);
64 $z = mt_rand($minZ, $maxZ);
65
66 while($y >= $worldMinY && !$world->getBlockAt($x, $y, $z)->isSolid()){
67 $y--;
68 }
69 if($y < $worldMinY){
70 continue;
71 }
72
73 $blockUp = $world->getBlockAt($x, $y + 1, $z);
74 $blockUp2 = $world->getBlockAt($x, $y + 2, $z);
75 if($blockUp->isSolid() || $blockUp instanceof Liquid || $blockUp2->isSolid() || $blockUp2 instanceof Liquid){
76 continue;
77 }
78
79 //Sounds are broadcasted at both source and destination
80 $world->addSound($origin, new EndermanTeleportSound());
81 $consumer->teleport($target = new Vector3($x + 0.5, $y + 1, $z + 0.5));
82 $world->addSound($target, new EndermanTeleportSound());
83
84 break;
85 }
86 }
87
88 public function getCooldownTicks() : int{
89 return 20;
90 }
91}
teleport(Vector3 $pos, ?float $yaw=null, ?float $pitch=null)
Definition: Entity.php:1437
onConsume(Living $consumer)
Definition: ChorusFruit.php:47