Jump to content

Getting accurate light of player's position.


NathanYearout

Recommended Posts

Hello, been searching around for a while trying to figure this out but I'm stumped. I'm trying to return the players light level, this should include skylight and block-light. This code below works but doesn't take into account for the actual brightness it is at different times of the day since it will always be 15. Is there any function that can help me accomplish this? I've tried getting the information from chunks, lightEngine, and still not the result I want. Thanks in advance.

    // Returns the brightness around the players position
    public static float lightLevel() {
        Minecraft minecraft = Minecraft.getInstance();
        Level world = minecraft.level;
        BlockPos playerPos = minecraft.player.blockPosition();

        var blockLight = world.getBrightness(LightLayer.BLOCK, playerPos);
        var skyLight = world.getBrightness(LightLayer.SKY, playerPos);

        System.out.println("Blocklight: " + blockLight);
        System.out.println("SkyLight: " + skyLight);

        return world.getBrightness(LightLayer.BLOCK, playerPos) + world.getBrightness(LightLayer.SKY, playerPos);
    }

 

Edited by NathanYearout
Syntax highlight
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.