Solved Getting Light Levels

Discussion in 'Plugin Development' started by xa112, Mar 28, 2014.

Thread Status:
Not open for further replies.
  1. Offline

    xa112

    Currently I have been attempting to get the light levels below a player so I loop through the blocks below the player until it hits a non-air block (going down). Then I use the .getLightLevel() function and I print it out using the logger but for some reason it always prints out 0.
    Code:java
    1. Block block = null;
    2. for(Location l = p.getLocation(); l.getY() >= 0; l.setY(l.getY() - 1)){
    3. if(l.getBlock().getType() != Material.AIR){
    4. block = l.getBlock();
    5. break;
    6. }
    7. }
    8. if(block != null){
    9. byte lightLevel = block.getState().getLightLevel();
    10. if(lightLevel <= 7){
    11. mainClass.logger.info(Integer.toString(lightLevel));
    12. //Do stuff
    13. }
    14. }

    Output every time (different time though): [20:02:22 INFO]: 0
     
  2. Offline

    RawCode

    add debug output, print block type and coordinates, other info.
     
  3. Offline

    xa112

    Okay will post tommorow morning :)

    New code in section to show more info:
    Code:java
    1. Block block = null;
    2. for(Location l = p.getLocation(); l.getY() >= 0; l.setY(l.getY() - 1)){
    3. if(l.getBlock().getType() != Material.AIR){
    4. block = l.getBlock();
    5. break;
    6. }
    7. }
    8. if(block != null){
    9. byte lightLevel = block.getState().getLightLevel();
    10. mainClass.logger.info("Light level: " + lightLevel);
    11. mainClass.logger.info("Light from sky: " + block.getLightFromSky());
    12. mainClass.logger.info("Light from blocks: " + block.getLightFromBlocks());
    13. Location loc = block.getState().getLocation();
    14. mainClass.logger.info("Location(x,y,z): " + loc.getX() + " " + block.getState().getY() + " " + loc.getZ());
    15. mainClass.logger.info("Block type" + block.getState().getType().toString());
    16. mainClass.logger.info("Humidty " + block.getHumidity());
    17. }



    Log:

    http://pastebucket.com/33942

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Jun 7, 2016
  4. Offline

    xa112

    RawCode Do you have any solutions? :)
     
  5. Offline

    Minnymin3

    xa112
    My guess: Only air blocks have light levels on them. Check the block above the first non air block's light level.
     
  6. Offline

    RawCode

    answer above is valid, non transparent blocks do block light, there is no light inside such block.

    this is very very obvious in case of proper testing (including testing transparent blocks and semi transparent, like leaves or ice)
     
  7. Offline

    xa112

  8. Offline

    Minnymin3

    RawCode
    Solid blocks will have a light level of 0 though and I think that is the problem with his current code.
     
Thread Status:
Not open for further replies.

Share This Page