-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
feat: implement weather system #6870
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
GroXzaLYs
wants to merge
17
commits into
pmmp:minor-next
Choose a base branch
from
GroXzaLYs:feature/weather-system
base: minor-next
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+563
−8
Open
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
f5e9121
feat: implement weather system with rain and thunder effects
GroXzaLYs 7e2359f
Update Entity.php
GroXzaLYs 4774584
...
GroXzaLYs a83cc98
?
GroXzaLYs 2dd7fbb
..
GroXzaLYs 3d12235
..
GroXzaLYs 73aff4e
..
GroXzaLYs 77fcfdb
Merge branch 'minor-next' into feature/weather-system
GroXzaLYs c9413ce
?
GroXzaLYs ddf86e3
?
GroXzaLYs 47880e3
Change thunderLevel to lightningLevel & fix phpstan
GroXzaLYs 417f787
Merge branch 'minor-next' into feature/weather-system
GroXzaLYs ca9e548
like this?
GroXzaLYs 6ed7d34
..
GroXzaLYs 76b20ef
Merge branch 'minor-next' into feature/weather-system
GroXzaLYs 6ddc80c
Merge branch 'minor-next' into feature/weather-system
GroXzaLYs a86d404
Merge branch 'minor-next' into feature/weather-system
GroXzaLYs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| <?php | ||
|
|
||
| /* | ||
| * | ||
| * ____ _ _ __ __ _ __ __ ____ | ||
| * | _ \ ___ ___| | _____| |_| \/ (_)_ __ ___ | \/ | _ \ | ||
| * | |_) / _ \ / __| |/ / _ \ __| |\/| | | '_ \ / _ \_____| |\/| | |_) | | ||
| * | __/ (_) | (__| < __/ |_| | | | | | | | __/_____| | | | __/ | ||
| * |_| \___/ \___|_|\_\___|\__|_| |_|_|_| |_|\___| |_| |_|_| | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Lesser General Public License as published by | ||
| * the Free Software Foundation, either version 3 of the License, or | ||
| * (at your option) any later version. | ||
| * | ||
| * @author PocketMine Team | ||
| * @link http://www.pocketmine.net/ | ||
| * | ||
| * | ||
| */ | ||
|
|
||
| declare(strict_types=1); | ||
|
|
||
| namespace pocketmine\command\defaults; | ||
|
|
||
| use pocketmine\command\Command; | ||
| use pocketmine\command\CommandSender; | ||
| use pocketmine\command\utils\InvalidCommandSyntaxException; | ||
| use pocketmine\lang\KnownTranslationFactory; | ||
| use pocketmine\permission\DefaultPermissionNames; | ||
| use pocketmine\player\Player; | ||
| use pocketmine\utils\AssumptionFailedError; | ||
| use function count; | ||
| use function max; | ||
| use function strtolower; | ||
|
|
||
| class WeatherCommand extends VanillaCommand{ | ||
|
|
||
| public function __construct(){ | ||
| parent::__construct( | ||
| "weather", | ||
| KnownTranslationFactory::pocketmine_command_weather_description(), | ||
| KnownTranslationFactory::pocketmine_command_weather_usage(), | ||
| ); | ||
| $this->setPermission(DefaultPermissionNames::COMMAND_WEATHER); | ||
| } | ||
|
|
||
| public function execute(CommandSender $sender, string $label, array $args) : void{ | ||
| if($sender instanceof Player){ | ||
| $world = $sender->getWorld(); | ||
| }else{ | ||
| $world = $sender->getServer()->getWorldManager()->getDefaultWorld(); | ||
| } | ||
|
|
||
| if($world === null){ | ||
| throw new AssumptionFailedError("Failed to retrieve world instance. Default world is not loaded."); | ||
| } | ||
|
|
||
| if(!$world->isWeatherEnabled()){ | ||
| $sender->sendMessage(KnownTranslationFactory::pocketmine_command_weather_disable()); | ||
| return; | ||
| } | ||
|
|
||
| if(count($args) < 1){ | ||
| $rainLevel = $world->getRainLevel(); | ||
| $thunderLevel = $world->getThunderLevel(); | ||
|
|
||
| if($rainLevel > 0.0 && $thunderLevel > 0.0){ | ||
| $current = "thunder"; | ||
| }elseif($rainLevel > 0.0){ | ||
| $current = "rain"; | ||
| }else{ | ||
| $current = "clear"; | ||
| } | ||
|
|
||
| $stateName = match($current){ | ||
| "clear" => KnownTranslationFactory::commands_weather_query_clear(), | ||
| "rain" => KnownTranslationFactory::commands_weather_query_rain(), | ||
| "thunder" => KnownTranslationFactory::commands_weather_query_thunder(), | ||
| }; | ||
|
|
||
| $sender->sendMessage(KnownTranslationFactory::commands_weather_query($stateName)); | ||
| return; | ||
| } | ||
|
|
||
| $type = match(strtolower($args[0])){ | ||
| "clear" => "clear", | ||
| "rain" => "rain", | ||
| "thunder" => "thunder", | ||
| default => throw new InvalidCommandSyntaxException(), | ||
| }; | ||
GroXzaLYs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| $rainLevel = 0.0; | ||
| $thunderLevel = 0.0; | ||
| $duration = max(100, (int) ($args[1] ?? 6000)); | ||
|
|
||
| switch($type){ | ||
| case "rain": | ||
| $rainLevel = 1.0; | ||
| $thunderLevel = 0.0; | ||
| break; | ||
|
|
||
| case "thunder": | ||
| $rainLevel = 1.0; | ||
| $thunderLevel = 1.0; | ||
| break; | ||
| } | ||
GroXzaLYs marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| $world->setWeather($rainLevel, $thunderLevel, $duration); | ||
|
|
||
| Command::broadcastCommandMessage($sender, | ||
| match($type){ | ||
| "clear" => KnownTranslationFactory::commands_weather_clear(), | ||
| "rain" => KnownTranslationFactory::commands_weather_rain(), | ||
| "thunder" => KnownTranslationFactory::commands_weather_thunder(), | ||
| } | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.