layers - 1; } public function readStateFromData(int $id, int $stateMeta) : void{ $this->layers = BlockDataSerializer::readBoundedInt("layers", $stateMeta + 1, self::MIN_LAYERS, self::MAX_LAYERS); } public function getStateBitmask() : int{ return 0b111; } 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)]; } private function canBeSupportedBy(Block $b) : bool{ return $b->isSolid() || ($b instanceof SnowLayer && $b->isSameType($this) && $b->layers === self::MAX_LAYERS); } 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))) ]; } }