layers = $r->readBoundedInt(3, self::MIN_LAYERS - 1, self::MAX_LAYERS - 1) + 1; } protected function encodeState(RuntimeDataWriter $w) : void{ $w->writeInt(3, $this->layers - 1); } public function getLayers() : int{ return $this->layers; } /** @return $this */ public function setLayers(int $layers) : self{ if($layers < self::MIN_LAYERS || $layers > self::MAX_LAYERS){ throw new \InvalidArgumentException("Layers must be in range " . self::MIN_LAYERS . " ... " . self::MAX_LAYERS); } $this->layers = $layers; return $this; } public function canBeReplaced() : bool{ return $this->layers < self::MAX_LAYERS; } /** * @return AxisAlignedBB[] */ protected function recalculateCollisionBoxes() : array{ //TODO: this zero-height BB is intended to stay in lockstep with a MCPE bug return [AxisAlignedBB::one()->trim(Facing::UP, $this->layers >= 4 ? 0.5 : 1)]; } public function getSupportType(int $facing) : SupportType{ if(!$this->canBeReplaced()){ return SupportType::FULL(); } return SupportType::NONE(); } private function canBeSupportedBy(Block $b) : bool{ return $b->getSupportType(Facing::UP)->equals(SupportType::FULL()); } public function place(BlockTransaction $tx, Item $item, Block $blockReplace, Block $blockClicked, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ if($blockReplace instanceof SnowLayer){ if($blockReplace->layers >= self::MAX_LAYERS){ return false; } $this->layers = $blockReplace->layers + 1; } if($this->canBeSupportedBy($blockReplace->getSide(Facing::DOWN))){ return parent::place($tx, $item, $blockReplace, $blockClicked, $face, $clickVector, $player); } return false; } public function ticksRandomly() : bool{ return true; } public function onRandomTick() : void{ if($this->position->getWorld()->getBlockLightAt($this->position->x, $this->position->y, $this->position->z) >= 12){ $ev = new BlockMeltEvent($this, VanillaBlocks::AIR()); $ev->call(); if(!$ev->isCancelled()){ $this->position->getWorld()->setBlock($this->position, $ev->getNewState()); } } } public function tickFalling() : ?Block{ return null; } public function getDropsForCompatibleTool(Item $item) : array{ return [ VanillaItems::SNOWBALL()->setCount(max(1, (int) floor($this->layers / 2))) ]; } }