Weather 5.46.0
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
public const CLEAR_MAX_TICKS = 180000CLEAR_MIN_TICKS
public const CLEAR_MIN_TICKS = 12000COMMAND_MAX_TICKS
public const COMMAND_MAX_TICKS = 18000COMMAND_MIN_TICKS
public const COMMAND_MIN_TICKS = 6000Default duration of /weather without one (Bedrock: 300-900 seconds).
LIGHTNING_CHANCE
public const LIGHTNING_CHANCE = 100000One strike per this many ticks per loaded chunk near a player in a thunderstorm (vanilla).
LIGHTNING_RANGE
public const LIGHTNING_RANGE = 128Distance in blocks from a player within which loaded chunks get natural lightning (~200 chunks, vanilla).
LIGHTNING_ROD_RANGE
public const LIGHTNING_ROD_RANGE = 64Horizontal range in which lightning rods attract a natural strike.
NO_THUNDER_MAX_TICKS
public const NO_THUNDER_MAX_TICKS = 180000NO_THUNDER_MIN_TICKS
public const NO_THUNDER_MIN_TICKS = 12000PRECIPITATION_CHANCE
public const PRECIPITATION_CHANCE = 16Chance per ticked chunk per tick of a precipitation update on a random column (vanilla).
RAIN_MAX_TICKS
public const RAIN_MAX_TICKS = 24000RAIN_MIN_TICKS
public const RAIN_MIN_TICKS = 12000THUNDER_MAX_TICKS
public const THUNDER_MAX_TICKS = 15600THUNDER_MIN_TICKS
public const THUNDER_MIN_TICKS = 3600Methods
__construct()
public function __construct(\pocketmine\world\World $world, \pocketmine\world\format\io\WorldData $data)broadcast()
public function broadcast(\pocketmine\player\Player ...$targets) : voidSends the weather to the given players (all the players of the world if none).
findLightningRod()
public function findLightningRod(int $x, int $y, int $z) : ?\pocketmine\math\Vector3Returns 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()
public function findLightningTarget(int $x, int $z) : ?\pocketmine\math\Vector3Where 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()
public function getLightningLevel() : floatThunder intensity sent to clients (0 without a thunderstorm).
getLightningTime()
public function getLightningTime() : intTicks until the thunder starts or stops.
getPrecipitationAt()
public function getPrecipitationAt(int $x, int $y, int $z) : \pocketmine\world\weather\PrecipitationWhat falls at the given position when it rains, depending on the biome and the height (whether it actually rains is not checked).
getPrecipitationHeight()
public function getPrecipitationHeight(int $x, int $z) : ?intReturns 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()
public function getRainLevel() : floatRain intensity sent to clients (0 when not raining).
getRainStrength()
public function getRainStrength() : floatDarkening of the sky by rain, 0-1 (fades in and out over 100 ticks).
getRainTime()
public function getRainTime() : intTicks until the rain starts or stops.
getThunderStrength()
public function getThunderStrength() : floatDarkening of the sky by thunder, 0-1.
hasWeather()
public function hasWeather() : boolWhether the world has weather at all (only the Overworld: no rain in the Nether or the End).
isClear()
public function isClear() : boolisExposedToSky()
public function isExposedToSky(int $x, int $y, int $z) : boolWhether the given block is exposed to the sky (nothing that stops the rain above it).
isRaining()
public function isRaining() : boolWhether it rains (or snows) in the world. Dry biomes stay dry: see Weather::isRainingAt().
isRainingAt()
public function isRainingAt(int $x, int $y, int $z) : boolWhether 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()
public function isThundering() : boolWhether there is a thunderstorm (rain with thunder).
isWeatherCycleEnabled()
public function isWeatherCycleEnabled() : boolresetCycle()
public function resetCycle() : voidStops the rain and the thunder and restarts both timers, like waking up after sleeping through the night.
save()
public function save(\pocketmine\world\format\io\WorldData $data) : voidsetClear()
public function setClear(?int $duration = null) : boolClear weather for the given number of ticks (random 6000-18000 if null), like /weather clear. Returns false if a plugin cancelled it.
setRain()
public function setRain(?int $duration = null) : boolRain without thunder for the given number of ticks, like /weather rain.
setThunder()
public function setThunder(?int $duration = null) : boolA thunderstorm for the given number of ticks, like /weather thunder.
setWeatherCycleEnabled()
public function setWeatherCycleEnabled(bool $enabled) : voidTurns the natural weather cycle on or off (Bedrock gamerule doweathercycle). The current weather stays.
strike()
public function strike(\pocketmine\math\Vector3 $pos, bool $visualOnly = false, int $cause = \pocketmine\event\world\LightningStrikeEvent::CAUSE_CUSTOM) : ?\pocketmine\entity\object\LightningBoltSpawns 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()
public function tickPrecipitation(int $x, int $z) : voidPrecipitation 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()
public function tryNaturalStrike(int $x, int $z) : ?\pocketmine\entity\object\LightningBoltA 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.
