GenisysPro  for Minecraft PE/Windows 10 v1.1.x
Feature-rich server software for Minecraft PE and Windows 10 Edition
Weather Class Reference

Public Member Functions

 __construct (Level $level, $duration=1200)
 
 canCalculate ()
 
 setCanCalculate (bool $canCalc)
 
 calcWeather ($currentTick)
 
 setWeather (int $wea, int $duration=12000)
 
 getRandomWeatherData ()
 
 setRandomWeatherData (array $randomWeatherData)
 
 getWeather ()
 
 isSunny ()
 
 isRainy ()
 
 isRainyThunder ()
 
 isThunder ()
 
 getStrength ()
 
 sendWeather (Player $p)
 
 sendWeatherToAll ()
 

Static Public Member Functions

static getWeatherFromString ($weather)
 

Data Fields

const CLEAR = 0
 
const SUNNY = 0
 
const RAIN = 1
 
const RAINY = 1
 
const RAINY_THUNDER = 2
 
const THUNDER = 3
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Level  $level,
  $duration = 1200 
)

Weather constructor.

Parameters
Level$level
int$duration
58  {
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);
64  }

Member Function Documentation

◆ calcWeather()

calcWeather (   $currentTick)
Parameters
$currentTick
83  {
84  if($this->canCalculate()){
85  $tickDiff = $currentTick - $this->lastUpdate;
86  $this->duration -= $tickDiff;
87 
88  if($this->duration <= 0){
89  $duration = mt_rand(
90  min($this->level->getServer()->weatherRandomDurationMin, $this->level->getServer()->weatherRandomDurationMax),
91  max($this->level->getServer()->weatherRandomDurationMin, $this->level->getServer()->weatherRandomDurationMax));
92 
93  if($this->weatherNow === self::SUNNY){
94  $weather = $this->randomWeatherData[array_rand($this->randomWeatherData)];
95  $this->setWeather($weather, $duration);
96  }else{
97  $weather = self::SUNNY;
98  $this->setWeather($weather, $duration);
99  }
100  }
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));
109  }
110  }
111  }
112  $this->lastUpdate = $currentTick;
113  }

◆ canCalculate()

canCalculate ( )
Returns
bool
69  : bool{
70  return $this->canCalculate;
71  }

◆ getRandomWeatherData()

getRandomWeatherData ( )
Returns
array
133  : array{
134  return $this->randomWeatherData;
135  }

◆ getStrength()

getStrength ( )
Returns
array
213  : array{
214  return [$this->strength1, $this->strength2];
215  }

◆ getWeather()

getWeather ( )
Returns
int
147  : int{
148  return $this->weatherNow;
149  }

◆ getWeatherFromString()

static getWeatherFromString (   $weather)
static
Parameters
$weather
Returns
int
156  {
157  if(is_int($weather)){
158  if($weather <= 3){
159  return $weather;
160  }
161  return self::SUNNY;
162  }
163  switch(strtolower($weather)){
164  case "clear":
165  case "sunny":
166  case "fine":
167  return self::SUNNY;
168  case "rain":
169  case "rainy":
170  return self::RAINY;
171  case "thunder":
172  return self::THUNDER;
173  case "rain_thunder":
174  case "rainy_thunder":
175  case "storm":
176  return self::RAINY_THUNDER;
177  default:
178  return self::SUNNY;
179  }
180  }

◆ isRainy()

isRainy ( )
Returns
bool
192  : bool{
193  return $this->getWeather() === self::RAINY;
194  }

◆ isRainyThunder()

isRainyThunder ( )
Returns
bool
199  : bool{
200  return $this->getWeather() === self::RAINY_THUNDER;
201  }

◆ isSunny()

isSunny ( )
Returns
bool
185  : bool{
186  return $this->getWeather() === self::SUNNY;
187  }

◆ isThunder()

isThunder ( )
Returns
bool
206  : bool{
207  return $this->getWeather() === self::THUNDER;
208  }

◆ sendWeather()

sendWeather ( Player  $p)
Parameters
Player$p
220  {
221  $pks = [
222  new LevelEventPacket(),
223  new LevelEventPacket()
224  ];
225 
226  //Set defaults. These will be sent if the case statement defaults.
227  $pks[0]->evid = LevelEventPacket::EVENT_STOP_RAIN;
228  $pks[0]->data = $this->strength1;
229  $pks[1]->evid = LevelEventPacket::EVENT_STOP_THUNDER;
230  $pks[1]->data = $this->strength2;
231 
232  switch($this->weatherNow){
233  //If the weather is not clear, overwrite the packet values with these
234  case self::RAIN:
235  $pks[0]->evid = LevelEventPacket::EVENT_START_RAIN;
236  $pks[0]->data = $this->strength1;
237  break;
238  case self::RAINY_THUNDER:
239  $pks[0]->evid = LevelEventPacket::EVENT_START_RAIN;
240  $pks[0]->data = $this->strength1;
242  $pks[1]->data = $this->strength2;
243  break;
244  case self::THUNDER:
246  $pks[1]->data = $this->strength2;
247  break;
248  default:
249  break;
250  }
251 
252  foreach($pks as $pk){
253  $p->dataPacket($pk);
254  }
255  $p->weatherData = [$this->weatherNow, $this->strength1, $this->strength2];
256  }

◆ sendWeatherToAll()

sendWeatherToAll ( )
258  {
259  foreach($this->level->getPlayers() as $player){
260  $this->sendWeather($player);
261  }
262  }

◆ setCanCalculate()

setCanCalculate ( bool  $canCalc)
Parameters
bool$canCalc
76  {
77  $this->canCalculate = $canCalc;
78  }

◆ setRandomWeatherData()

setRandomWeatherData ( array  $randomWeatherData)
Parameters
array$randomWeatherData
140  {
141  $this->randomWeatherData = $randomWeatherData;
142  }

◆ setWeather()

setWeather ( int  $wea,
int  $duration = 12000 
)
Parameters
int$wea
int$duration
119  {
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); //If we're clearing the weather, it doesn't matter what strength values we set
124  $this->strength2 = mt_rand(30000, 40000);
125  $this->duration = $ev->getDuration();
126  $this->sendWeatherToAll();
127  }
128  }

Field Documentation

◆ CLEAR

const CLEAR = 0

◆ RAIN

const RAIN = 1

◆ RAINY

const RAINY = 1

◆ RAINY_THUNDER

const RAINY_THUNDER = 2

◆ SUNNY

const SUNNY = 0

◆ THUNDER

const THUNDER = 3

The documentation for this class was generated from the following file: