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