signalStrength = $r->readBoundedInt(4, 0, 15); $this->inverted = $r->readBool(); } protected function encodeState(BlockDataWriter $w) : void{ $w->writeInt(4, $this->signalStrength); $w->writeBool($this->inverted); } 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 getSupportType(int $facing) : SupportType{ return SupportType::NONE(); } public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null) : bool{ $this->inverted = !$this->inverted; $this->signalStrength = $this->recalculateSignalStrength(); $this->position->getWorld()->setBlock($this->position, $this); return true; } public function onScheduledUpdate() : void{ $signalStrength = $this->recalculateSignalStrength(); if($this->signalStrength !== $signalStrength){ $this->signalStrength = $signalStrength; $this->position->getWorld()->setBlock($this->position, $this); } $this->position->getWorld()->scheduleDelayedBlockUpdate($this->position, 20); } private function recalculateSignalStrength() : int{ $lightLevel = $this->position->getWorld()->getRealBlockSkyLightAt($this->position->x, $this->position->y, $this->position->z); if($this->inverted){ return 15 - $lightLevel; } $sunAngle = $this->position->getWorld()->getSunAnglePercentage(); return max(0, (int) round($lightLevel * cos(($sunAngle + ((($sunAngle < 0.5 ? 0 : 1) - $sunAngle) / 5)) * 2 * M_PI))); } //TODO }