Jump to content

[Solved][1.15.2] Trying to get light value


DarkNoobs12

Recommended Posts

Hi, I just started modding and tried to create a simple item that shows the light level the player is in, like in F3, but less debugging mode and more of a real item(for immersion purposes).

From all my trials so far it seems the functions for Light level have been changed recently, since all previous posts mention functions I haven't been able to find, or at least IntelliJ hasn't found them.

 

BlockPos pos = player.getPosition();

BlockState feet = world.getBlockState(pos);

System.out.println(feet.getLightValue(world,pos));

This is my code, but it outputs the light level the block is emitting, not the light level itself. Meaning I get 0 next to a torch, and 14 when I stand on the torch.

What function would give the value I'm looking for?

Edited by DarkNoobs12
Link to comment
Share on other sites

On a side note, what is up with this getLightValue() function? My coding background isn't really in Java, so I might be missing something, but I went into the source code for it and it looks useless and kind of a rabbit hole.

 

This is the getLightValue() I called, implemented in net.minecraftforge.common.extensions.IForgeBlockState:

 

default int getLightValue(IBlockReader world, BlockPos pos)
{
return getBlockState().getBlock().getLightValue(getBlockState(), world, pos);
}

 

It calls a different getLightValue(), which is in net.minecraftforge.common.extensions.IForgeBlock:

default int getLightValue(BlockState state, IBlockReader world, BlockPos pos)
{
return state.getLightValue();
}

 

This getLightValue() calls yet another getLightValue(), and it only requires the BlockState to be called. This getLightValue() is in the net.minecraft.block.BlockState:

public int getLightValue() {
return this.lightLevel;
}

 

Is this a java thing, or just the leftovers of previous versions?

Link to comment
Share on other sites

2 minutes ago, DarkNoobs12 said:

On a side note, what is up with this getLightValue() function?

You know how torches and glowstone....glow? getLightValue() returns the amount of light that a block emits.

 

3 minutes ago, DarkNoobs12 said:

Is this a java thing, or just the leftovers of previous versions?

Its a result of Forge trying to supply state-full versions of the method where vanilla does not, so that one block with multiple states can have a different light value for each state (if it so chooses).

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

2 minutes ago, Draco18s said:

You know how torches and glowstone....glow? getLightValue() returns the amount of light that a block emits.

 

Yea, I noticed its intended purpose from the behaviour of the outputs. I was talking more about the way it was coded through multiple functions that called each other. Again, my confusion probably came from a lack of Java background.

 

2 minutes ago, Draco18s said:

Its a result of Forge trying to supply state-full versions of the method where vanilla does not, so that one block with multiple states can have a different light value for each state (if it so chooses).

I see, seems to be a useful feature. Thanks for the answer ?

 

12 minutes ago, diesieben07 said:

You need to call World#getLight.

It worked, thank you!

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.

Announcements



×
×
  • Create New...

Important Information

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