Add artificial light to player when they are in a cave / underground

Discussion in 'Plugin Development' started by AVOCARDO, Jan 13, 2013.

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

    AVOCARDO

    Hi all

    I would like to thank everyone in advance for there time in helping me to pin this one down. I am looking for a way to artificially add light into the game.

    I am planning on having an ability on my plugin to add light when a player is underground. This is what I have so far.

    Code:
    if (TORCHLIGHT.getActive()) {
        if (p.getLocation().getBlock().getRelative(BlockFace.DOWN).getLightFromSky() < 8) {
            if (p.getItemInHand().getTypeId() == 50) {
                p.getLocation().getBlock().getRelative(BlockFace.DOWN).setType(Material.GLOWSTONE);               
                for (Player online : Bukkit.getOnlinePlayers()) {
                    online.sendBlockChange(p.getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation(), Material.AIR, p.getLocation().getBlock().getData());
                }
                // Add block to HashMap<Player, Block> so that Glowstone can be removed on next block place
            }
        }
    }
    Quite obviously this attempt did not work... :mad: and so many of my previous ideas have fallen to the same fate !

    Does anyone have any ideas?

    Regards

    AVO
     
  2. Offline

    Spectre93

    What exactly doesn't work? The idea isn't that bad.
     
  3. Offline

    xize

    Hello,

    What exactly do you mean with TORCHLIGHT.getActive ?
    Do you want if somebody places a torch a block change to glowstone underneath you?
    or just if you walk with a torch in hand the stone underneath you change to glowstone?
    However I place some code maybe its exactly what you want maybe not.

    Code:
    public class cavelighter extends JavaPlugin implements Listener {
    Logger log = Logger.getLogger("Minecraft");
    public void onDisable() {
      log.info("[yourplugin] has been disabled!");
    }
    public void onEnable() {
      log.info("[yourplugin] has been enabled!");
      this.getServer().getPluginManager().registerEvents(this, this);
    }
    public HashMap<String, Block> hash = new HashMap<String, Block>();
    @EventHandler
    public void GlowStone(PlayerMoveEvent e) {
      if(e.getPlayer().getLocation().getBlock().getRelative(BlockFace.DOWN).getLightFromSky() < 8) {
      if(e.getPlayer().getItemInHand().getTypeId() == 50) {
        for(Player online : e.getPlayer().getServer().getOnlinePlayers()) {
                      online.sendBlockChange(e.getPlayer().getLocation().getBlock().getRelative(BlockFace.DOWN).getLocation(), Material.GLOWSTONE, e.getPlayer().getLocation().getBlock().getData());
        }
        hash.put(e.getPlayer().getName(),e.getPlayer().getLocation().getBlock());
      }
      }
     
    }
    
    soz if the code is a bit messy I hope you see something here which helps you.
     
  4. Offline

    stover78

    what if the block under a person was rock but had the properties of giving off light like glowstone.......just some input.
     
  5. Offline

    Ugleh

    From what I am aware of Bukkit does not have the api to set a blocks light, however you can probably do it using net.minecraft as someone else did in the past.
     
  6. Offline

    stover78

    can you not use a potion of night vision? or are you looking for a different affect?
     
  7. Offline

    AVOCARDO

    Night Vision potion is not the same effect. TORCHLIGHT is the ability class variable and getActive() is whether it is active for that player. It is based in the onPlayerMove event and it was an attempt to add glowstone light in a cave while the player holds a torch and then conceal the fact that there is glowstone their however obviously sending the block change to the player stops the players client side from rendering the light.

    I am aware lighting has been a massive issue and there have been many requests to Bukkit to allow it in the API however its more complicated than first thought as its the clients side that renders light every tick.

    Can someone please specify how this was done in the past? Was it done linking into craftbukkit.jar or ??? where is net.minecraft located?

    Regards

    AVOCARDO
     
  8. Offline

    phondeux

  9. Offline

    AVOCARDO

    Is there anyone out there willing to create a LightAPI plugin simular to TagAPI for colored names above players heads?

    Regards

    AVO
     
  10. Offline

    Miner_Fil

    This is the wrong forum to ask for a Plugin
     
Thread Status:
Not open for further replies.

Share This Page