PocketMine-MP 5.36.1 git-eaa7c4834c8fe2f379d24e7f0ee6cc63cfb18ccc
Loading...
Searching...
No Matches
Nylium.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
33use function count;
34
35class Nylium extends Opaque{
36
40 public function __construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, private readonly array $vegetation){
41 parent::__construct($idInfo, $name, $typeInfo);
42 }
43
44 public function getDropsForCompatibleTool(Item $item) : array{
45 return [
46 VanillaBlocks::NETHERRACK()->asItem()
47 ];
48 }
49
50 public function isAffectedBySilkTouch() : bool{
51 return true;
52 }
53
54 public function ticksRandomly() : bool{
55 return true;
56 }
57
58 public function onRandomTick() : void{
59 $world = $this->position->getWorld();
60 $above = $this->getSide(Facing::UP);
61 if(!$above->isTransparent()){
62 BlockEventHelper::spread($this, VanillaBlocks::NETHERRACK(), $this);
63 return;
64 }
65
66 $random = new Random();
67 for($i = 0; $i < 4; ++$i){
68 $pos = $this->position->add($random->nextRange(-1, 1), $random->nextRange(-2, 0), $random->nextRange(-1, 1));
69 $block = $world->getBlock($pos);
70 if($block->getTypeId() === BlockTypeIds::NETHERRACK && $world->getBlock($pos->up())->isTransparent()){
71 BlockEventHelper::spread($block, $this, $this);
72 }
73 }
74 }
75
76 public function onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
77 if($item instanceof Fertilizer && $this->getSide(Facing::UP)->getTypeId() === BlockTypeIds::AIR){
78 $item->pop();
79 $this->growVegetation(new Random());
80 return true;
81 }
82 return false;
83 }
84
85 private function growVegetation(Random $random) : void{
86 $world = $this->position->getWorld();
87
88 for($x = -2; $x <= 2; ++$x){
89 for($z = -2; $z <= 2; ++$z){
90 if($random->nextBoundedInt(3) === 0){
91 $pos = $this->position->add($x, 1, $z);
92 $replace = $world->getBlock($pos);
93 $place = $this->vegetation[$random->nextBoundedInt(count($this->vegetation))];
94 if($world->isInWorld($pos->x, $pos->y, $pos->z) && $replace->getTypeId() === BlockTypeIds::AIR && $place->canBePlacedAt($replace, Vector3::zero(), Facing::DOWN, true)){
95 $world->setBlock($pos, $place);
96 }
97 }
98 }
99 }
100 }
101}
getDropsForCompatibleTool(Item $item)
Definition Nylium.php:44
__construct(BlockIdentifier $idInfo, string $name, BlockTypeInfo $typeInfo, private readonly array $vegetation)
Definition Nylium.php:40
onInteract(Item $item, Facing $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
Definition Nylium.php:76
pop(int $count=1)
Definition Item.php:431