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