这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@GroXzaLYs
Copy link

@GroXzaLYs GroXzaLYs commented Oct 28, 2025

Note

The weather isn't as perfect as vanilla yet (can be continued later).

  • Allowing edits by maintainers

For every world, add a dynamic, automatic transitioning weather system including rain and thunderstorms.

Here, a simple weather manager is added which manages rain, thunder and lightning. It changes the state of the world, sends the appropriate packets to the players, and synchronizes the players’ visuals and sounds.


Related issues & PRs


Changes

API changes

  • Lightning world/weather Lightning entity

  • New methods in src/world/World.php:

    • setWeather(), getWeather(), and tickWeather(), autoChange(), spawnLightning(), setRainLevel(), getRainLevel(), setThunderLevel(), and getThunderLevel()

Behavioural changes

  • Weather will transition back and forth between clear, rain, and thunder.

  • Thunderstorms will shoot lightning a random amount of times.

  • Clients will all see the rain effect and thunder sound, and the changes to the sky.


Backwards compatibility

No breaking changes.

Worlds without weather support behave the same.


Follow-up

  • Gradual brightness transition.

  • Adding rain variability.


Tests

Minecraft_2025-10-28-21-49-18.mp4

Manual tests show:

  • /weather rain and /weather thunder all work as intended.

  • Thunder sounds and lightning visuals are synced.

  • No lag or crashing was able to be reproduced.

@GroXzaLYs GroXzaLYs requested a review from a team as a code owner October 28, 2025 10:50
@GroXzaLYs GroXzaLYs changed the base branch from stable to minor-next October 28, 2025 12:03
@dktapps dktapps added Category: API Related to the plugin API Category: Gameplay Related to Minecraft gameplay experience Status: Waiting on Author Type: Enhancement Contributes features or other improvements to PocketMine-MP labels Oct 28, 2025
@GroXzaLYs GroXzaLYs requested a review from dktapps October 30, 2025 04:00
Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also I don't know what editor you're using but it's made an enormous mess of your indentation. Indents should use tabs.

@dktapps
Copy link
Member

dktapps commented Oct 30, 2025

Overall this is looking better since the last time I reviewed, but there's still some work left to do. Thanks for sticking with it 🙂

@GroXzaLYs GroXzaLYs requested a review from dktapps November 7, 2025 21:46
Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks mostly OK now, code-wise.

I think my main sticking points remaining are:

  • There doesn't appear to be any way to disable the system, short of just setting the weather to clear for a very large duration. People aren't going to want it to rain in their lobbies.
  • I don't like that we're constrained to clear/rainy/thunder.
    • setRainLevel and setThunderLevel will not update the WeatherType, so that means plugins can make the /weather command return wrong results anyway.
    • Instead of generally constraining it by the type, it would be better to have the /weather command dynamically decide the weather type based on the rain and thunder amount (e.g. rain=0 + thunder=0 = clear, rain>0 + thunder=0 = rainy, thunder > 0 = thunder (whether or not it's raining)).

@GroXzaLYs
Copy link
Author

@dktapps Would it be better if we add an on off argument in WeatherCommand?

@dktapps
Copy link
Member

dktapps commented Nov 8, 2025

That might be a good idea. But I'm more thinking about an enable-weather setting for server.properties.

Normally weather cycle would be controlled by game rules, but we don't have a general system for those currently. But we should still save the appropriate NBT in level.dat.

Actually, I just noticed this doesn't save anything related to weather in level.dat. You'll need to fix that.

@Dasciam
Copy link
Contributor

Dasciam commented Nov 8, 2025

My idea is, to save doweathercycle key in level.dat, if the state of whether weather cycle is changed, by default we apply setting from server.properties or pocketmine.yml(best case), but not saving it

@dktapps
Copy link
Member

dktapps commented Nov 8, 2025

I don't want to put this in pocketmine.yml. pocketmine.yml is supposed to be the place for "don't touch, might break stuff" settings. Something this simple should be easily accessible.


$this->register(LightningBolt::class, function(World $world, CompoundTag $nbt) : LightningBolt{
return new LightningBolt(Helper::parseLocation($nbt, $world), $nbt);
}, ['lightning_bolt', 'minecraft:lightning_bolt']);
Copy link
Contributor

@Dasciam Dasciam Nov 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nvm

Copy link
Member

@ShockedPlot7560 ShockedPlot7560 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What I saw when I did a quick review

Comment on lines +49 to +53
if($sender instanceof Player){
$world = $sender->getWorld();
}else{
$world = $sender->getServer()->getWorldManager()->getDefaultWorld();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It could be better to have the ability to give world name or use the current/default as default. Even though, in my opinion, the name should be mandatory if it is not a player.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These commands are typically meant to match vanilla, there's no option to specify world for other commands

Comment on lines +70 to +75
$type = match(strtolower($args[0])){
"clear" => WeatherType::CLEAR,
"rain" => WeatherType::RAIN,
"thunder" => WeatherType::THUNDER,
default => throw new InvalidCommandSyntaxException(),
};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As it's an enum, why not using WeatherType::from or tryFrom ?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from() / tryFrom() can’t really be used here since the enum has no string values and the command input is lowercase. A manual mapping like this is still the simplest option.

Comment on lines +686 to +687
$rainInt = (int) ($this->rainLevel * 65535);
$thunderInt = (int) ($this->thunderLevel * 65535);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will be clearer by using floor or round instead of casting to an int

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since the packet requires an int, the final value needs to stay integer. The fields are floats, so casting is fine, but using round() before casting can make the conversion more explicit.

@GroXzaLYs
Copy link
Author

Okay, maybe I’ll continue this later, since I have other things to do.

@GroXzaLYs
Copy link
Author

I don't know how to save to level.dat

Copy link
Member

@dktapps dktapps left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On closer inspection there's a few features related to rain that need to be implemented:

  • Fire should be extinguished when raining
  • Rain should extinguish burning entities
  • Farmland should hydrate when raining

Basically most stuff in this section needs to be implemented: https://minecraft.wiki/w/Rain#Effects


public function getWeather() : WeatherType{
return $this->weather;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As I said previously, "weather type" should be confined to commands only. It doesn't make sense anywhere else considering the dynamic rain & thunder strengths.


public function setWeatherEnabled(bool $enabled) : void{
$this->compoundTag->setByte(self::TAG_WEATHER_ENABLED, $enabled ? 1 : 0);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • These are not used anywhere
  • The tag name likely doesn't match vanilla (check the wiki)
  • It should be added to the WorldData interface
  • Other world data types also need to implement something for this

}

public function setWeatherEnabled(bool $enabled) : void{
$this->compoundTag->setByte(self::TAG_WEATHER_ENABLED, $enabled ? 1 : 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is also not correct here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Category: API Related to the plugin API Category: Gameplay Related to Minecraft gameplay experience Status: Waiting on Author Type: Enhancement Contributes features or other improvements to PocketMine-MP

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

4 participants