Skip to content

Weather 5.46.0 ​

final class · pocketmine\world\weather\Weather · source

Weather of a world (Overworld only): clear, rain (snow in cold biomes) and thunderstorms, with the vanilla cycle.

State (level.dat, Bedrock tags): rainLevel and lightningLevel are the current intensities (0 = off; the intensity is what clients get in the START_RAIN/START_THUNDER level events), rainTime and lightningTime the ticks left until the rain and the thunder toggle. Like vanilla, the timers run independently and thunder only happens while it rains. A timer at 0 first draws the duration of the current state: clear 12000-180000 ticks, rain 12000-24000, no thunder 12000-180000, thunder 3600-15600. The cycle can be turned off (doweathercycle).

Effects handled here, per ticked chunk (so they follow the random tick budget): 1/16 chance per tick to pick a random column, where water freezes and snow settles in cold biomes and the top block gets the precipitation (Block::onPrecipitation(): cauldrons fill); and in a thunderstorm a 1/100000 chance per tick of a lightning strike, aimed at a lightning rod (within Weather::LIGHTNING_ROD_RANGE blocks, top of its column) or at a living entity under the open sky near the column, with a chance of a skeleton trap horse instead.

Constants ​

CLEAR_MAX_TICKS ​

php
public const CLEAR_MAX_TICKS = 180000

CLEAR_MIN_TICKS ​

php
public const CLEAR_MIN_TICKS = 12000

COMMAND_MAX_TICKS ​

php
public const COMMAND_MAX_TICKS = 18000

COMMAND_MIN_TICKS ​

php
public const COMMAND_MIN_TICKS = 6000

Default duration of /weather without one (Bedrock: 300-900 seconds).

LIGHTNING_CHANCE ​

php
public const LIGHTNING_CHANCE = 100000

One strike per this many ticks per loaded chunk near a player in a thunderstorm (vanilla).

LIGHTNING_RANGE ​

php
public const LIGHTNING_RANGE = 128

Distance in blocks from a player within which loaded chunks get natural lightning (~200 chunks, vanilla).

LIGHTNING_ROD_RANGE ​

php
public const LIGHTNING_ROD_RANGE = 64

Horizontal range in which lightning rods attract a natural strike.

NO_THUNDER_MAX_TICKS ​

php
public const NO_THUNDER_MAX_TICKS = 180000

NO_THUNDER_MIN_TICKS ​

php
public const NO_THUNDER_MIN_TICKS = 12000

PRECIPITATION_CHANCE ​

php
public const PRECIPITATION_CHANCE = 16

Chance per ticked chunk per tick of a precipitation update on a random column (vanilla).

RAIN_MAX_TICKS ​

php
public const RAIN_MAX_TICKS = 24000

RAIN_MIN_TICKS ​

php
public const RAIN_MIN_TICKS = 12000

THUNDER_MAX_TICKS ​

php
public const THUNDER_MAX_TICKS = 15600

THUNDER_MIN_TICKS ​

php
public const THUNDER_MIN_TICKS = 3600

Methods ​

__construct() ​

php
public function __construct(\pocketmine\world\World $world, \pocketmine\world\format\io\WorldData $data)

broadcast() ​

php
public function broadcast(\pocketmine\player\Player ...$targets) : void

Sends the weather to the given players (all the players of the world if none).

findLightningRod() ​

php
public function findLightningRod(int $x, int $y, int $z) : ?\pocketmine\math\Vector3

Returns the nearest lightning rod within Weather::LIGHTNING_ROD_RANGE blocks that is the top block of its column, or null. Only the sub-chunks whose palette has a lightning rod are searched.

findLightningTarget() ​

php
public function findLightningTarget(int $x, int $z) : ?\pocketmine\math\Vector3

Where a natural strike near the column lands: on a lightning rod in range, else on a random living entity under the open sky within 3 blocks of the column, else on top of the column. Null if the chunk is not loaded.

getLightningLevel() ​

php
public function getLightningLevel() : float

Thunder intensity sent to clients (0 without a thunderstorm).

getLightningTime() ​

php
public function getLightningTime() : int

Ticks until the thunder starts or stops.

getPrecipitationAt() ​

php
public function getPrecipitationAt(int $x, int $y, int $z) : \pocketmine\world\weather\Precipitation

What falls at the given position when it rains, depending on the biome and the height (whether it actually rains is not checked).

getPrecipitationHeight() ​

php
public function getPrecipitationHeight(int $x, int $z) : ?int

Returns the Y of the lowest block that rain and snow reach in the column (one above the highest solid or liquid block; flowers, grass, torches and other non-solid blocks let the rain through), or null if the chunk is not loaded.

getRainLevel() ​

php
public function getRainLevel() : float

Rain intensity sent to clients (0 when not raining).

getRainStrength() ​

php
public function getRainStrength() : float

Darkening of the sky by rain, 0-1 (fades in and out over 100 ticks).

getRainTime() ​

php
public function getRainTime() : int

Ticks until the rain starts or stops.

getThunderStrength() ​

php
public function getThunderStrength() : float

Darkening of the sky by thunder, 0-1.

hasWeather() ​

php
public function hasWeather() : bool

Whether the world has weather at all (only the Overworld: no rain in the Nether or the End).

isClear() ​

php
public function isClear() : bool

isExposedToSky() ​

php
public function isExposedToSky(int $x, int $y, int $z) : bool

Whether the given block is exposed to the sky (nothing that stops the rain above it).

isRaining() ​

php
public function isRaining() : bool

Whether it rains (or snows) in the world. Dry biomes stay dry: see Weather::isRainingAt().

isRainingAt() ​

php
public function isRainingAt(int $x, int $y, int $z) : bool

Whether rain (not snow) falls on the given block right now: it rains, the biome isn't dry or cold and the block is under the open sky. This is what puts out burning entities, wets endermen and keeps farmland moist.

isThundering() ​

php
public function isThundering() : bool

Whether there is a thunderstorm (rain with thunder).

isWeatherCycleEnabled() ​

php
public function isWeatherCycleEnabled() : bool

resetCycle() ​

php
public function resetCycle() : void

Stops the rain and the thunder and restarts both timers, like waking up after sleeping through the night.

save() ​

php
public function save(\pocketmine\world\format\io\WorldData $data) : void

setClear() ​

php
public function setClear(?int $duration = null) : bool

Clear weather for the given number of ticks (random 6000-18000 if null), like /weather clear. Returns false if a plugin cancelled it.

setRain() ​

php
public function setRain(?int $duration = null) : bool

Rain without thunder for the given number of ticks, like /weather rain.

setThunder() ​

php
public function setThunder(?int $duration = null) : bool

A thunderstorm for the given number of ticks, like /weather thunder.

setWeatherCycleEnabled() ​

php
public function setWeatherCycleEnabled(bool $enabled) : void

Turns the natural weather cycle on or off (Bedrock gamerule doweathercycle). The current weather stays.

strike() ​

php
public function strike(\pocketmine\math\Vector3 $pos, bool $visualOnly = false, int $cause = \pocketmine\event\world\LightningStrikeEvent::CAUSE_CUSTOM) : ?\pocketmine\entity\object\LightningBolt

Spawns a lightning bolt at the given position (a visual-only bolt does no damage, sets no fire and powers no lightning rod). Returns null if a plugin cancelled the strike.

tickPrecipitation() ​

php
public function tickPrecipitation(int $x, int $z) : void

Precipitation on one column: water freezes in cold biomes (also when it doesn't snow), snow settles while it snows, and the top block gets the rain or snow.

tryNaturalStrike() ​

php
public function tryNaturalStrike(int $x, int $z) : ?\pocketmine\entity\object\LightningBolt

A natural strike near the given column: aimed like vanilla (see the class doc); nothing happens if it doesn't rain or snow there. Returns the bolt, or null.

VanillaMine is a fork of PocketMine-MP, maintained by Luxury Nodes. Not affiliated with the PMMP team or Mojang.