[1.7.2] [NMS] Create fake light sources

Discussion in 'Resources' started by Plo124, Aug 29, 2014.

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

    Plo124

    Using NMS it is possible to create fake light sources.
    The updating light code does not update the chunks so the player does not see the light. So you need to update the chunks as well.

    Code:java
    1. Chunk chunk = ((CraftChunk)e.getPlayer().getLocation().getChunk()).getHandle();
    2. Location loc = e.getPlayer().getLocation();
    3. chunk.a(EnumSkyBlock.BLOCK,loc.getBlockX() & 0xF,loc.getBlockY(),loc.getBlockZ() & 0xF,15);


    This will use any event which has e.getPlayer() in it and create a light source. The number 15 is the light level which is changeable.

    Now you need to update the chunks.
    If you are not concerned about bandwidth then you can use
    Code:java
    1. for (EntityPlayer p : (List<EntityPlayer>) chunk.world.players){
    2. p.chunkCoordIntPairQueue.add(new ChunkCoordIntPair(chunk.bukkitChunk.getX(), chunk.bukkitChunk.getZ()));
    3. }

    below every call of changing the light. This will send a LOT of chunk updates if you are setting lots of light sources. It is recommended you change all the lights you need, then send 1 change to the clients.

    So now you have a fake light source. This light is updated when you right click the block emitting the light so if you click it the light will go out.
     
    ChipDev and Skyost like this.
  2. Offline

    Bammerbom

    Plo124
    Wow never knew this was possible :D
     
  3. Offline

    Gamecube762

    Bammerbom Its been possible for a while with multiple threads about it. This works perfectly and in any way you expect to use it in. It never became popular due to the client's limitation of Chunk Updating. With the new Chunk Updating in 1.8, this will work perfectly and the dream of having torches light your way without placing them will finally come true!
     
  4. Offline

    Plo124

    Gamecube762
    The 1.8 update does not multi-thread the chunks for the server.
    The only noticable changes on the client in 1.8 is that these light sources will be visible eariler from a distance.
    The change on the server's side is the method "chunk.a" may change to a different letter, e.g. "chunk.cX"
     
  5. Offline

    AoH_Ruthless

    ChipDev
    Because there is no such method
     
    RenegadeEagle and Garris0n like this.
  6. Offline

    Plo124

    ChipDev
    Is that a thing?
    I just checked, and its not.
     
  7. Offline

    ChipDev

  8. Offline

    AoH_Ruthless

    ChipDev
    Maybe you confused it with Block#getLightLevel() .. but yeah, there is no Bukkit API method to change the lighting of a block.
     
  9. Offline

    ChipDev

    Oh. Lol ok :p Thought I saw it.
     
Thread Status:
Not open for further replies.

Share This Page