Get block (location) light-level?

Can’t seem to find anything expected browsing the javadocs…

Is this something that is going to be buried 3 or 4 levels deep in the data api, or am I overlooking a simple function on the wrong object?

Same question for the old bukkit check like isLiquid() to return if the block is solid or water/lava,is there a simple test or is it all deep in the data api as well?

There is

Optional<MatterProperty> optional = BlockTypes.STONE.getProperty(MatterProperty.class);
if (optional.isPresent())
    boolean isLiquid = optional.get().getValue().equals(MatterProperty.Matter.LIQUID);

Maybe there is a shorter way to do it?

All the block properties were refactored out to actual Properties and they are all implemented as expected, rather, I believe I implemented them all correctly.

So, what you can do is the following:

final Optional<LightEmissionProperty> optional = location.getProperty(LightEmissionProperty.class);
if (optional.isPresent()) {
  int emittedLight = optional.get().getValue();
 // do stuff with emmittedLight
1 Like

Alright, thats a fair bit better than it could have been. I’ll fiddle with the other properties as well using your code, @gabizou and give them all a spin to see how they handle and test your belief system :smile:

LightEmissionProperty works to evaluate if a block emits light or not - glowstone and sea-lanterns return 15, all others 0 … seems fine.

SkyLuminanceProperty is 0.0 at all times - I could not get it to change its value day/night, exposed or buried where testing locations. What exactly SHOULD this one be returning, as a true measure of what?

GroundLuminanceProperty is 0.0 at all times except if testing a sealantern/torch/glowstone block. Day/night, block right beside a light source, etc - always 0.0 if not the actual lit block.

It would seem something isn’t quite right for at least one of those properties. I see no other property lists that should be reporting a spectrum of values indicating how near or far to a light source the block is, or if the block is exposed to “skylight” or shaded

CORRECTIONS after Followup Testing, for anyone search-hitting this same issue:

The GroundIllumination does work (Dev-707 testing) by reporting the light level in the volume, not for which the block is exposed. IE: The block in the ground beside a lantern/lamp/torch has ground-illumination level of 0, while the volume the player stands in above those blocks will have illumination levels of 13-14.

Even if the ground is hollowed out between the lamp and a test block, the ground test block still reports 0.0, while after digging out the block, the volume of space now has a level of 10-12 for example. Unless the groundblock is something like glass, then it reports a nonzero

So this may very well be the Intentional results for this function, the light reaching “inside” the middle of of a solid block is 0, otherwise, the light inside the middle of the volume based on its transparancy/airness is able to be appreciated.
Ground-illumination of lanterns and torch blocks also is the max level for each.

@gabizou, MatterProperty not implements?
Code: String property = block.getProperty(MatterProperty.class).get().getValue().name();
He returns:
[13:25:03] [Server thread/ERROR] [Sponge/]: Could not pass InteractBlockEvent$Secondary$Impl to SpongePlugin:Grave{dev}
java.lang.AbstractMethodError: Method net/minecraft/block/state/BlockState$StateImplementation.getProperty(Ljava/lang/Class;)Ljava/util/Optional; is abstract
at net.minecraft.block.state.BlockState$StateImplementation.getProperty( ~[beg.class:?]
at ~[EventInteractSolidBlock.class:?]
at org.spongepowered.common.event.listener.SecondaryListener_EventInteractSolidBlock_onPlayerInteractBlock25.handle(Unknown Source) ~[?:?]
at org.spongepowered.common.event.RegisteredListener.handle( ~[RegisteredListener.class:1.8-1568-2.1-DEV-833]
at [SpongeModEventManager.class:1.8-1568-2.1-DEV-833]
at [SpongeModEventManager.class:1.8-1568-2.1-DEV-833]
at [SpongeModEventManager.class:1.8-1568-2.1-DEV-833]
at [SpongeModEventManager.class:1.8-1568-2.1-DEV-833]
at org.spongepowered.common.Sponge.postEvent( [Sponge.class:1.8-1568-2.1-DEV-833]
at net.minecraftforge.event.ForgeEventFactory.onPlayerInteract( [ForgeEventFactory.class:?]
at [qx.class:?]
at [rj.class:?]
at [rj.class:?]
at [mx.class:?]
at [mx.class:?]
at$1.onProcessPacket(SourceFile:63) [ih.class:?]
at$ [ih.class:?]
at java.util.concurrent.Executors$ Source) [?:1.8.0_66]
at Source) [?:1.8.0_66]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture( [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.func_71190_q( [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.func_71190_q( [po.class:?]
at net.minecraft.server.MinecraftServer.func_71217_p( [MinecraftServer.class:?]
at [MinecraftServer.class:?]
at Source) [?:1.8.0_66]