PocketMine-MP 5.32.2 git-237b304ef9858756b018e44e8f298093f66f823b
Loading...
Searching...
No Matches
AmethystCluster.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
26use pocketmine\block\utils\AmethystTrait;
28use pocketmine\block\utils\AnyFacingTrait;
30use pocketmine\block\utils\SupportType;
41
42final class AmethystCluster extends Transparent implements AnyFacing{
43 use AmethystTrait;
44 use AnyFacingTrait;
45
46 public const STAGE_SMALL_BUD = 0;
47 public const STAGE_MEDIUM_BUD = 1;
48 public const STAGE_LARGE_BUD = 2;
49 public const STAGE_CLUSTER = 3;
50
51 private int $stage = self::STAGE_CLUSTER;
52
53 public function describeBlockItemState(RuntimeDataDescriber $w) : void{
54 $w->boundedIntAuto(self::STAGE_SMALL_BUD, self::STAGE_CLUSTER, $this->stage);
55 }
56
57 public function getStage() : int{ return $this->stage; }
58
59 public function setStage(int $stage) : self{
60 if($stage < self::STAGE_SMALL_BUD || $stage > self::STAGE_CLUSTER){
61 throw new \InvalidArgumentException("Size must be in range " . self::STAGE_SMALL_BUD . " ... " . self::STAGE_CLUSTER);
62 }
63 $this->stage = $stage;
64 return $this;
65 }
66
67 public function getLightLevel() : int{
68 return match($this->stage){
69 self::STAGE_SMALL_BUD => 1,
70 self::STAGE_MEDIUM_BUD => 2,
71 self::STAGE_LARGE_BUD => 4,
72 self::STAGE_CLUSTER => 5,
73 default => throw new AssumptionFailedError("Invalid stage $this->stage"),
74 };
75 }
76
77 protected function recalculateCollisionBoxes() : array{
78 $myAxis = Facing::axis($this->facing);
79
80 $box = AxisAlignedBB::one();
81 foreach([Axis::Y, Axis::Z, Axis::X] as $axis){
82 if($axis === $myAxis){
83 continue;
84 }
85 $box->squash($axis, $this->stage === self::STAGE_SMALL_BUD ? 4 / 16 : 3 / 16);
86 }
87 $box->trim($this->facing, 1 - ($this->stage === self::STAGE_CLUSTER ? 7 / 16 : ($this->stage + 3) / 16));
88
89 return [$box];
90 }
91
92 private function canBeSupportedAt(Block $block, int $facing) : bool{
93 return $block->getAdjacentSupportType($facing) === SupportType::FULL;
94 }
95
96 public function getSupportType(int $facing) : SupportType{
97 return SupportType::NONE;
98 }
99
100 public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{
101 if(!$this->canBeSupportedAt($blockReplace, Facing::opposite($face))){
102 return false;
103 }
104
105 $this->facing = $face;
106 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
107 }
108
109 public function onNearbyBlockChange() : void{
110 if(!$this->canBeSupportedAt($this, Facing::opposite($this->facing))){
111 $this->position->getWorld()->useBreakOn($this->position);
112 }
113 }
114
115 public function isAffectedBySilkTouch() : bool{
116 return true;
117 }
118
119 public function getDropsForCompatibleTool(Item $item) : array{
120 if($this->stage === self::STAGE_CLUSTER){
121 return [VanillaItems::AMETHYST_SHARD()->setCount(FortuneDropHelper::weighted($item, min: 4, maxBase: 4))];
122 }
123
124 return [];
125 }
126
127 public function getDropsForIncompatibleTool(Item $item) : array{
128 if($this->stage === self::STAGE_CLUSTER){
129 return [VanillaItems::AMETHYST_SHARD()->setCount(FortuneDropHelper::weighted($item, min: 2, maxBase: 2))];
130 }
131
132 return [];
133 }
134}
describeBlockItemState(RuntimeDataDescriber $w)
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)