Getting a Redstone Lamp.

Discussion in 'Plugin Development' started by shohouku, May 14, 2014.

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

    shohouku

    How would I get a Redstone Lamp block from the whole world?

    I'm also using a scheduler that is in OnEnable.
     
  2. Offline

    Bailey Payne

    Copy and Paste code in and tell us more about what you need.
     
  3. Offline

    shohouku


    Code:java
    1. final Location REDSTONE_LAMP_LOCATION = new Location( Bukkit.getWorld("world"), 0, 0, 0);
    2. Plugin plugin = Bukkit.getPluginManager().getPlugin("HoboSpawn");
    3.  
    4. Bukkit.getScheduler().runTaskTimer(plugin, new Runnable() {
    5. @Override
    6. public void run() {
    7. World world = REDSTONE_LAMP_LOCATION.getWorld();
    8. if (world.getTime() >= 12000 && world.getTime() <= 24000) {
    9. if (REDSTONE_LAMP_LOCATION.getBlock().getType() != Material.REDSTONE_LAMP_ON) {
    10. REDSTONE_LAMP_LOCATION.getBlock().setType(Material.REDSTONE_LAMP_ON);
    11. }
    12. } else {
    13. if (REDSTONE_LAMP_LOCATION.getBlock().getType() != Material.REDSTONE_LAMP_OFF) {
    14. REDSTONE_LAMP_LOCATION.getBlock().setType(Material.REDSTONE_LAMP_OFF);
    15. }
    16. }
    17. }
    18. }, 0L, 0L);


    Instead of getting the location of the block, I'm trying to get all of the blocks that are in the world.

    I don't know what block the redstone lamp is called in eclipse.
     
  4. Offline

    Bailey Payne

    Sorry I don't quite know what your trying to do, are you trying to make them glow without a source of redstone?!?
     
  5. Offline

    rsod

    You can not get ALL lamps from entrie world. You can:
    1) Write all lamps locations that you want to interact with into configuration file
    2) Get all loaded chunks, and search for lamps operating with them. Also handle ChunkLoadEvent to operate with lamps that was just loaded.
    Both methods, especially second one, are resource heavy. You need to think twice before doing that.

    Also you can't just
    Code:
    REDSTONE_LAMP_LOCATION.getBlock().setType(Material.REDSTONE_LAMP_ON);
    You'll need:
    Code:
    ((CraftWorld)REDSTONE_LAMP_LOCATION.getBlock().getWorld()).getHandle().isStatic = true;
    REDSTONE_LAMP_LOCATION.getBlock().setType(Material.REDSTONE_LAMP_ON);
    ((CraftWorld)REDSTONE_LAMP_LOCATION.getBlock().getWorld()).getHandle().isStatic = false;
    [code]
     
  6. Offline

    shohouku


    Yeah I was planning to swap it around once I got my code fixed up.
     
  7. Sure you can! You just shouldn't.
     
  8. Offline

    shohouku

    Okay, my MAIN idea is just to turn off the red stone lamps at day time and turn them on at night time!

    I know it's possible, I'v seen it before.

    I'v tried multiple methods on trying to do this but couldn't find my answer...
     
  9. Offline

    rsod

    what about daylight sensors? :D
    I told you how to do it, 2 ways. Better to use first one
     
Thread Status:
Not open for further replies.

Share This Page