inverted ? $this->idInfo->getSecondId() : parent::getId(); } protected function writeStateToMeta() : int{ return $this->signalStrength; } public function readStateFromData(int $id, int $stateMeta) : void{ $this->signalStrength = BlockDataSerializer::readBoundedInt("signalStrength", $stateMeta, 0, 15); $this->inverted = $id === $this->idInfo->getSecondId(); } public function getStateBitmask() : int{ return 0b1111; } public function isInverted() : bool{ return $this->inverted; } /** * @return $this */ public function setInverted(bool $inverted = true) : self{ $this->inverted = $inverted; return $this; } public function getFuelTime() : int{ return 300; } /** * @return AxisAlignedBB[] */ protected function recalculateCollisionBoxes() : array{ return [AxisAlignedBB::one()->trim(Facing::UP, 10 / 16)]; } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->inverted = !$this->inverted; $this->signalStrength = $this->recalculateSignalStrength(); $this->pos->getWorld()->setBlock($this->pos, $this); return true; } public function onScheduledUpdate() : void{ $signalStrength = $this->recalculateSignalStrength(); if($this->signalStrength !== $signalStrength){ $this->signalStrength = $signalStrength; $this->pos->getWorld()->setBlock($this->pos, $this); } $this->pos->getWorld()->scheduleDelayedBlockUpdate($this->pos, 20); } private function recalculateSignalStrength() : int{ $lightLevel = $this->pos->getWorld()->getRealBlockSkyLightAt($this->pos->x, $this->pos->y, $this->pos->z); if($this->inverted){ return 15 - $lightLevel; } $sunAngle = $this->pos->getWorld()->getSunAnglePercentage(); return max(0, (int) round($lightLevel * cos(($sunAngle + ((($sunAngle < 0.5 ? 0 : 1) - $sunAngle) / 5)) * 2 * M_PI))); } //TODO }