getLightLevel of a block clicked.

Discussion in 'Plugin Development' started by Scullyking, Jul 28, 2014.

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

    Scullyking

    The light level seems to always be 0. I've read posts about having to get the blockFace, but that takes an arg?

    Code:java
    1. Player player = event.getPlayer();
    2. if (!player.isOp()){
    3. if (event.getBlockPlaced().getType().equals(Material.TORCH)){
    4. player.sendMessage("Light level: " + event.getBlockAgainst().getLightLevel());
    5. if (event.getBlockAgainst().getLightLevel() < 9){
    6. player.sendMessage(ChatColor.YELLOW + "Torch placed, will last for 20 seconds");
    7. Torch.addTorch(event.getBlock().getLocation());
    8.  
    9. @SuppressWarnings("unused")
    10. BukkitTask regen = new TorchExtinguishRunnable(plugin, event.getBlock().getLocation()).runTaskLater(plugin, 400);
    11. } else {
    12. event.setCancelled(true);
    13. player.sendMessage(ChatColor.GRAY + "(It's not dark enough here for a torch)");
    14. }
    15.  
    16. } else {
    17. event.setCancelled(true);
    18. }
     
  2. Offline

    GameplayJDK

    Scullyking I think the block on which the torch is placed is solid and can't have another ll that 0. Try to check the ll of the torch block.
     
  3. Offline

    Scullyking

    Hm, well the light level of the torch block is 13. I guess I have to look for the nearest air block and grab it's level?
     
  4. Offline

    GameplayJDK

  5. Offline

    xTigerRebornx

    Scullyking Use the replaced block's state (BlockPlaceEvent has a method that returns it), and check the light level of that.
     
Thread Status:
Not open for further replies.

Share This Page