46 use StaticSupportTrait;
48 public const MAX_AGE = 25;
51 private int $growthFace;
54 $this->growthFace = $growthFace;
55 parent::__construct($idInfo, $name, $typeInfo);
66 private function canBeSupportedAt(
Block $block) : bool{
67 $supportBlock = $block->getSide(
Facing::opposite($this->growthFace));
68 return $supportBlock->
getSupportType($this->growthFace)->hasCenterSupport() || $supportBlock->hasSameTypeId($this);
74 private function seekToTip() : NetherVines{
76 while(($next = $top->getSide($this->growthFace)) instanceof NetherVines && $next->hasSameTypeId($this)){
83 $this->age = mt_rand(0, self::MAX_AGE - 1);
84 return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player);
89 if($this->grow($player, mt_rand(1, 5))){
98 return $this->age < self::MAX_AGE;
102 if($this->age < self::MAX_AGE && mt_rand(1, 10) === 1){
103 if($this->getSide($this->growthFace)->canBeReplaced()){
109 private function grow(?
Player $player,
int $growthAmount = 1) : bool{
110 $top = $this->seekToTip();
112 $pos = $top->position;
113 $world = $pos->getWorld();
116 $tx =
new BlockTransaction($world);
118 for($i = 1; $i <= $growthAmount; $i++){
119 $growthPos = $pos->getSide($this->growthFace, $i);
120 if(!$world->isInWorld($growthPos->getFloorX(), $growthPos->getFloorY(), $growthPos->getFloorZ()) || !$world->getBlock($growthPos)->canBeReplaced()){
123 $tx->addBlock($growthPos, (clone $top)->setAge(min(++$age, self::MAX_AGE)));
127 if($changedBlocks > 0){
128 $ev =
new StructureGrowEvent($top, $tx, $player);
131 if($ev->isCancelled()){
146 $entity->resetFallDistance();
156 return [$this->asItem()];
162 return SupportType::NONE;
place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player=null)