Skip to content
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

Support the live daylight cycle #571

Closed
wants to merge 2 commits into from

Conversation

Soulter
Copy link

@Soulter Soulter commented Jul 11, 2024

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

Night Dawn Day
8d02837c0ac024d74127f7997db35c64 0301e8c17bf7e7436630777f6564c382 d79d4a90344fd588753191702535af61

Details

  • For the forge and neoforge sides, I utilized level.getSkyDarken() to get ambient darkness data. This method returns an integer ranging from 0 to 11, where 0 means day and 11 means night.
  • The fabric side is similar to the forge side; I used world.getAmbientDarkness(), which has the same effect as getSkyDarken().
  • For the spigot and sponge sides, I couldn't find a similar function, so I used ticks and some hardcoding to implement the feature.
  • On the frontend, I added a switch button in the 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 the sunlightStrength value accordingly. The data format is as follows:
    {
        "brightness": [
            {
                "dimension": "overworld",
                "val": 3
            },
            {
                "dimension": "the_nether",
                "val": 0
            },
            {
                "dimension": "the_end",
                "val": 0
            }
        ]
    }

*I figured out a way to calculate ambient darkness as shown below, but it requires too many computational resources, so I didn't implement it for the spigot and sponge sides.

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.

Copy link
Member

@TBlueF TBlueF left a comment

Choose a reason for hiding this comment

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

Thanks a lot for taking the time to make a PR!

Unfortunately you didn't speak to me about this before implementing it, because i don't think bluemap is ready for this feature yet.. let me explain:

What i really don't like about this is the need to have yet another additional constant request-spam to the webserver for each update.
This is already something i want to change about the player/marker updates.

The plan is to eventually switch to a websocket/SSE based updating, with possibly a fallback to a single live-data request interface for all updates -> markers, players and additional updates like this daylight thing.
With that we can then have a lot more live-updates a lot faster without spamming too many http-requests ^^'

For this reason I want to finish that websocket/SSE switch first, before adding any more live updates on the webapp.

Additionally there is plans to completely rewrite the webapp etc.. all which is tied tightly together with SOO many ideas i have and want to implement. The issue is that most of those ideas and plans i have not written down anywhere ^^' Which is my fault, but it basically makes it impossible for someone to make a PR for bluemap that doesn't clash with any of my plans :/

if (!fileData || !fileData.brightness) {
reject("Failed to parse brightness.json");
}
let world_name = this.mapViewer.map.data.name.match(/\(([^)]+)\)/)[1].toLowerCase();
Copy link
Member

Choose a reason for hiding this comment

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

The map-name can be changed and is not at all guaranteed to include the world-id/dimension, so we can't use this to identify the dimension-key of a map

@@ -99,6 +101,9 @@ default Optional<ServerWorld> getServerWorld(Object world) {
@DebugDump
Collection<Player> getOnlinePlayers();

@DebugDump
Map<Key, Integer> getSkyBrightness();
Copy link
Member

Choose a reason for hiding this comment

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

I think this should be something like a int getSkyBrightness() or maybe even int getWorldTime() in the ServerWorld interface instead

@Soulter Soulter closed this Jul 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants