PocketMine-MP 5.23.3 git-976fc63567edab7a6fb6aeae739f43cf9fe57de4
Loading...
Searching...
No Matches
DaylightSensor.php
1<?php
2
3/*
4 *
5 * ____ _ _ __ __ _ __ __ ____
6 * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \
7 * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) |
8 * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/
9 * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_|
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * @author PocketMine Team
17 * @link http://www.pocketmine.net/
18 *
19 *
20 */
21
22declare(strict_types=1);
23
24namespace pocketmine\block;
25
26use pocketmine\block\utils\AnalogRedstoneSignalEmitterTrait;
27use pocketmine\block\utils\SupportType;
34use function cos;
35use function max;
36use function round;
37use const M_PI;
38
40 use AnalogRedstoneSignalEmitterTrait;
41
42 protected bool $inverted = false;
43
44 protected function describeBlockOnlyState(RuntimeDataDescriber $w) : void{
45 $w->boundedIntAuto(0, 15, $this->signalStrength);
46 $w->bool($this->inverted);
47 }
48
49 public function isInverted() : bool{
50 return $this->inverted;
51 }
52
56 public function setInverted(bool $inverted = true) : self{
57 $this->inverted = $inverted;
58 return $this;
59 }
60
61 public function getFuelTime() : int{
62 return 300;
63 }
64
65 protected function recalculateCollisionBoxes() : array{
66 return [AxisAlignedBB::one()->trim(Facing::UP, 10 / 16)];
67 }
68
69 public function getSupportType(int $facing) : SupportType{
70 return SupportType::NONE;
71 }
72
73 public function onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player = null, array &$returnedItems = []) : bool{
74 $this->inverted = !$this->inverted;
75 $this->signalStrength = $this->recalculateSignalStrength();
76 $this->position->getWorld()->setBlock($this->position, $this);
77 return true;
78 }
79
80 public function onScheduledUpdate() : void{
81 $world = $this->position->getWorld();
82 $signalStrength = $this->recalculateSignalStrength();
83 if($this->signalStrength !== $signalStrength){
84 $this->signalStrength = $signalStrength;
85 $world->setBlock($this->position, $this);
86 }
87 $world->scheduleDelayedBlockUpdate($this->position, 20);
88 }
89
90 private function recalculateSignalStrength() : int{
91 $world = $this->position->getWorld();
92 $lightLevel = $world->getRealBlockSkyLightAt($this->position->x, $this->position->y, $this->position->z);
93 if($this->inverted){
94 return 15 - $lightLevel;
95 }
96
97 $sunAngle = $world->getSunAnglePercentage();
98 return max(0, (int) round($lightLevel * cos(($sunAngle + ((($sunAngle < 0.5 ? 0 : 1) - $sunAngle) / 5)) * 2 * M_PI)));
99 }
100
101 //TODO
102}
onInteract(Item $item, int $face, Vector3 $clickVector, ?Player $player=null, array &$returnedItems=[])
describeBlockOnlyState(RuntimeDataDescriber $w)
setInverted(bool $inverted=true)