◆ __construct()
__construct |
( |
Level |
$level, |
|
|
|
$duration = 1200 |
|
) |
| |
Weather constructor.
- Parameters
-
59 $this->level = $level;
60 $this->weatherNow = self::SUNNY;
61 $this->duration = $duration;
62 $this->lastUpdate = $level->getServer()->getTick();
63 $this->temporalVector =
new Vector3(0, 0, 0);
◆ calcWeather()
calcWeather |
( |
|
$currentTick | ) |
|
- Parameters
-
85 $tickDiff = $currentTick - $this->lastUpdate;
86 $this->duration -= $tickDiff;
88 if($this->duration <= 0){
90 min($this->level->getServer()->weatherRandomDurationMin, $this->level->getServer()->weatherRandomDurationMax),
91 max($this->level->getServer()->weatherRandomDurationMin, $this->level->getServer()->weatherRandomDurationMax));
93 if($this->weatherNow === self::SUNNY){
94 $weather = $this->randomWeatherData[array_rand($this->randomWeatherData)];
97 $weather = self::SUNNY;
101 if(($this->weatherNow >= self::RAINY_THUNDER) and ($this->level->getServer()->lightningTime > 0) and is_int($this->duration / $this->level->getServer()->lightningTime)){
102 $players = $this->level->getPlayers();
103 if(count($players) > 0){
104 $p = $players[array_rand($players)];
105 $x = $p->x + mt_rand(-64, 64);
106 $z = $p->z + mt_rand(-64, 64);
107 $y = $this->level->getHighestBlockAt($x, $z);
108 $this->level->spawnLightning($this->temporalVector->setComponents($x, $y, $z));
112 $this->lastUpdate = $currentTick;
◆ canCalculate()
- Returns
- bool
70 return $this->canCalculate;
◆ getRandomWeatherData()
- Returns
- array
134 return $this->randomWeatherData;
◆ getStrength()
- Returns
- array
214 return [$this->strength1, $this->strength2];
◆ getWeather()
- Returns
- int
148 return $this->weatherNow;
◆ getWeatherFromString()
static getWeatherFromString |
( |
|
$weather | ) |
|
|
static |
- Parameters
-
- Returns
- int
157 if(is_int($weather)){
163 switch(strtolower($weather)){
172 return self::THUNDER;
174 case "rainy_thunder":
176 return self::RAINY_THUNDER;
◆ isRainy()
◆ isRainyThunder()
- Returns
- bool
200 return $this->
getWeather() === self::RAINY_THUNDER;
◆ isSunny()
◆ isThunder()
◆ sendWeather()
- Parameters
-
222 new LevelEventPacket(),
223 new LevelEventPacket()
228 $pks[0]->data = $this->strength1;
230 $pks[1]->data = $this->strength2;
232 switch($this->weatherNow){
236 $pks[0]->data = $this->strength1;
238 case self::RAINY_THUNDER:
240 $pks[0]->data = $this->strength1;
242 $pks[1]->data = $this->strength2;
246 $pks[1]->data = $this->strength2;
252 foreach($pks as $pk){
255 $p->weatherData = [$this->weatherNow, $this->strength1, $this->strength2];
◆ sendWeatherToAll()
259 foreach($this->level->getPlayers() as $player){
◆ setCanCalculate()
setCanCalculate |
( |
bool |
$canCalc | ) |
|
◆ setRandomWeatherData()
setRandomWeatherData |
( |
array |
$randomWeatherData | ) |
|
- Parameters
-
141 $this->randomWeatherData = $randomWeatherData;
◆ setWeather()
setWeather |
( |
int |
$wea, |
|
|
int |
$duration = 12000 |
|
) |
| |
- Parameters
-
120 $this->level->getServer()->getPluginManager()->callEvent($ev =
new WeatherChangeEvent($this->level, $wea, $duration));
121 if(!$ev->isCancelled()){
122 $this->weatherNow = $ev->getWeather();
123 $this->strength1 = mt_rand(90000, 110000);
124 $this->strength2 = mt_rand(30000, 40000);
125 $this->duration = $ev->getDuration();
◆ CLEAR
◆ RAIN
◆ RAINY
◆ RAINY_THUNDER
◆ SUNNY
◆ THUNDER
The documentation for this class was generated from the following file:
- src/pocketmine/level/weather/Weather.php