47 use StaticSupportTrait;
49 public const MAX_AGE = 25;
52 private int $growthFace;
55 $this->growthFace = $growthFace;
56 parent::__construct($idInfo, $name, $typeInfo);
67 private function canBeSupportedAt(
Block $block) : bool{
68 $supportBlock = $block->getSide(
Facing::opposite($this->growthFace));
69 return $supportBlock->
getSupportType($this->growthFace)->hasCenterSupport() || $supportBlock->hasSameTypeId($this);
75 private function seekToTip() : NetherVines{
77 while(($next = $top->getSide($this->growthFace)) instanceof NetherVines && $next->hasSameTypeId($this)){
84 $this->age = mt_rand(0, self::MAX_AGE - 1);
85 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
90 if($this->grow($player, mt_rand(1, 5))){
99 return $this->age < self::MAX_AGE;
103 if($this->age < self::MAX_AGE && mt_rand(1, 10) === 1){
104 if($this->getSide($this->growthFace)->canBeReplaced()){
110 private function grow(?
Player $player,
int $growthAmount = 1) : bool{
111 $top = $this->seekToTip();
113 $pos = $top->position;
114 $world = $pos->getWorld();
117 $tx =
new BlockTransaction($world);
119 for($i = 1; $i <= $growthAmount; $i++){
120 $growthPos = $pos->getSide($this->growthFace, $i);
121 if(!$world->isInWorld($growthPos->getFloorX(), $growthPos->getFloorY(), $growthPos->getFloorZ()) || !$world->getBlock($growthPos)->canBeReplaced()){
124 $tx->addBlock($growthPos, (clone $top)->setAge(min(++$age, self::MAX_AGE)));
128 if($changedBlocks > 0){
129 $ev =
new StructureGrowEvent($top, $tx, $player);
132 if($ev->isCancelled()){
147 $entity->resetFallDistance();
157 return [$this->asItem()];
163 return SupportType::NONE;
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)