PocketMine-MP 5.39.3 git-400eb2dddf91a9c112aa09f3b498ffc8c85e98ed
Loading...
Searching...
No Matches
Netherrack.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
30use function mt_rand;
31
32class Netherrack extends Opaque{
33
34 public function burnsForever() : bool{
35 return true;
36 }
37
38 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
39 if($item instanceof Fertilizer){
40 if($this->tryTransform()){
41 $item->pop();
42 return true;
43 }
44 }
45 return false;
46 }
47
48 private function tryTransform() : bool{
49 $world = $this->position->getWorld();
50 $pos = $this->position;
51
52 if(!$world->getBlock($pos->up())->isTransparent()){
53 return false;
54 }
55
56 $hasWarpedNylium = false;
57 $hasCrimsonNylium = false;
58
59 for($x = -1; $x <= 1; $x++){
60 for($y = -1; $y <= 1; $y++){
61 for($z = -1; $z <= 1; $z++){
62 $blockTypeId = $world->getBlock($pos->add($x, $y, $z))->getTypeId();
63
64 if($blockTypeId === BlockTypeIds::WARPED_NYLIUM){
65 $hasWarpedNylium = true;
66 }elseif($blockTypeId === BlockTypeIds::CRIMSON_NYLIUM){
67 $hasCrimsonNylium = true;
68 }
69
70 if($hasWarpedNylium && $hasCrimsonNylium){
71 break 3;
72 }
73 }
74 }
75 }
76
77 if(!$hasWarpedNylium && !$hasCrimsonNylium){
78 return false;
79 }
80
81 $world->setBlock($pos, match(true){
82 $hasWarpedNylium && $hasCrimsonNylium => (mt_rand(0, 1) === 0 ? VanillaBlocks::WARPED_NYLIUM() : VanillaBlocks::CRIMSON_NYLIUM()),
83 $hasWarpedNylium => VanillaBlocks::WARPED_NYLIUM(),
84 $hasCrimsonNylium => VanillaBlocks::CRIMSON_NYLIUM(),
85 });
86 return true;
87 }
88}
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
pop(int $count=1)
Definition Item.php:427