Support the live daylight cycle #571
Closed
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.
Introduction
Thank you for your amazing project. BlueMap helps me a lot!
Just noticed that the feature is in Ideas board, so I try to implement it. #398
These changes implement the feature of a live daylight cycle on BlueMap webpages. I leverage the Minecraft API to get the ambient darkness of all dimensions and add an HTTP handler to allow frontend to retrieve this data.
Demo
Details
forge
andneoforge
sides, I utilizedlevel.getSkyDarken()
to get ambient darkness data. This method returns an integer ranging from 0 to 11, where 0 means day and 11 means night.fabric
side is similar to theforge
side; I usedworld.getAmbientDarkness()
, which has the same effect asgetSkyDarken()
.spigot
andsponge
sides, I couldn't find a similar function, so I used ticks and some hardcoding to implement the feature.SettingsMenu
. Users can toggle this button to turn the feature on or off. The frontend will request/live/brightness.json
every 2 seconds (or every 3 seconds if the request fails) and adjust thesunlightStrength
value accordingly. The data format is as follows:Test coverage
I tested forge, fabric, paper, and sponge on versions 1.19-1.20, and the feature works well. I can make more tests if you think this PR would be helpful for you.
If you find any errors or shortcomings in these changes, I will fix them as soon as possible! And the branch is allow edits by maintainers, you can make any improvement.