Rain fills holes w/ water

Discussion in 'Archived: Plugin Requests' started by hammale, Jan 12, 2012.

?

Would you use this?

  1. Yes!

    11 vote(s)
    68.8%
  2. No!

    5 vote(s)
    31.3%
  1. Offline

    hammale

    Well the title kind of says it all. Would any of you be interested in/is there already a plugin that can do this? I don't want to start making it only to have a perfectly good competitor/no users! :D
     
  2. Offline

    kalez

    ive thought about this in the past, but the biggest problem here is, how would you determine what is a hole?
     
  3. Offline

    hammale

    well looking at this plugins src I think i can cancel the normal weather when is generated and fake my own weather in a place where i can define a cuboid. i then just set up a repeating task to check each block for holes by checking the blocks up 1 and on all 4 sides. if there all blocks then its a hole :D although it may be a bit resource heavy and time consuming it SHOULD work :D i just dont know if i wanna try it!
     
  4. Offline

    AdvsNoob

    If you want i could give this a try
     
  5. Offline

    kalez

    so you mean like single block holes. otherwise i was going to say you could end up with a massive amount of massive lakes everywhere lol
     
  6. These lakes could decrease back to sea height if there's no rain... :D
     
  7. Offline

    Orcem12

    Is that a ravine? Nope that's an Ocean.
     
  8. Offline

    kalez

    thats true, or you could determine the largest area that could be filled, like if the area is larger than 10 blocks it wont fill. the next issue i see here though then is that every time its going to rain its going to do a massive block calculation, making it lag even more than it normally does when it rains... at least i assume it would. idk

    edit: then again that could cause issues for open caves.
     
  9. Offline

    amunro

    I agree with kalez. The only effective way to check if there is a 'hole' is search below a certain y value, and if it is in view of the sky, fill it with water. However this would cause all sorts of problems, mainly huge server resources. On an average sized map, you would be talking about 1000s of block changes instantly as soon as it started raining. This would almost surely crash any server and probably do irreversible damage to the map. (Have you ever tried world-editing something over 10k blocks...)
     
    ArcheCane likes this.
  10. Offline

    hammale

    well i was going to try it but yeah if u wanna give it a go no prob :D it looks like u'll need to import the craftbukkit.jar, and when theres a normal storm cancel it and generate your own in an area where you can make a cuboid and check for holes via an async task. If you can think of a better idea i'd LOVE to hear it :D
     
  11. 1. Only check loaded chunks.
    2. Use chunk.getHighestBlockAt(x, y);
    3. Don't use async tasks, they will fire ConcurrentModificationExceptions and other weird things.
     
  12. Offline

    hammale

    why would i want to get the highest block?
     
  13. Offline

    kalez

    so youre not calculating pointless air i would assume

    edit: it would also have to be by certain block types. you proly dont want water in a tree :p
     
  14. Cause at lower blocks it's not raining? ;)

    //EDIT: Block possibleHole = chunk.getHighestBlockAt(x, z).getRelative(BlockFace.UP);
    then do your hole check... ;)
     
  15. Offline

    hammale

    wait so you can check if a block is being rained on??? that would be great if i could just look at the top block and check if its being rained on...

    the hole code will be simple just getRelative(BlockFace.UP, 1) then check if all for sides on that block aren't air. If its not just set the data to 8 (or maybe 9 so it wont flow?). That would be easy to do in a loop if i could just get a cuboid of the blocks being rained on. The problem is i would have to put some form of delayed task otherwise it would just look like water is glitching into the holes. You could even store the location in a hashMap or arraylist and change them back to air after the rain is over. The problem is just getting that cuboid....

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 23, 2016
  16. Something like this (untested):
    Code:java
    1. if(!world.hasStorm())
    2. return;
    3. for(Chunk chunk: world.getLoadedChunks())
    4. {
    5. int sx = chunk.getX() * 16;
    6. int sz = chunk.getZ() * 16;
    7. for(int x = sx; x < sx + 16; sx++)
    8. {
    9. for(int z = sz; z < sz + 16; sz++)
    10. {
    11. Block b = chunk.getHighestBlockAt(x, y).getRelative(BlockFace.UP);
    12. if(b == null)
    13. continue;
    14. Biome bio = b.getBiome();
    15. if(bio == Biome.DESERT || bio == Biome.FROZEN_OCEAN || ...)
    16. continue;
    17. if(b.getRelative(BlockFace.NORTH).getType() == Material.AIR || b.getRelative(BlockFace.WEST).getType() == Material.AIR || b.getRelative(BlockFace.SOUTH).getType() == Material.AIR || b.getRelative(BlockFace.EAST).getType() == Material.AIR)
    18. continue;
    19. b.setBlockIdAndData(Material.WATER.getID(), 9);
    20. }
    21. }
    22. }

    ? :D
     
  17. Offline

    hammale

    yeah but when theres a storm it doesnt rain on EVERY loaded chunk does it? if it does on all but deserts and snow areas then this plugin just got a WHOLE lot eaiser :D
     
  18. Offline

    AdvsNoob

    I don't think it does. On the server i play on me and my friend would be in two different areas and it would rain in one location and not the other
     
  19. It should rain in all biomes that support rain. There's no rain per chunk, only rain per world. ;)
     
  20. Offline

    hammale

    well what i heard is that the server tells the client "TIME TO RAIN!" and then the client chooses how do handle it. Thats why i started to look at the src for this.
     
  21. Yes, but server and client have to be synced (damaging Enderman, for example) for it to work. So both sides set the rain based on biomes. It's per-world rain. Just trust me.
    That's pretty advanced stuff (faking packages) and has nothing to do with the notch rain. ;)
     
  22. Offline

    hammale

    ok ima gonna trust you :D for better or worse!
     
  23. Offline

    AdvsNoob

    Code:
    package me.advsnoob.rainHole;
    
    
    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.Chunk;
    import org.bukkit.block.Biome;
    import org.bukkit.block.Block;
    import org.bukkit.block.BlockFace;
    import org.bukkit.event.weather.WeatherChangeEvent;
    import org.bukkit.event.weather.WeatherListener;
    
    
    
    public class WorldWeatherListener extends WeatherListener{
        public void hasStorm(WeatherChangeEvent event){
            World world = event.getWorld();
    
            if(!world.hasStorm())
                  return;
                for(Chunk chunk: world.getLoadedChunks())
                {
                  int sx = chunk.getX() * 16;
                  int sz = chunk.getZ() * 16;
                  for(int x = sx; x < sx + 16; sx++)
                  {
                    for(int z = sz; z < sz + 16; sz++)
                    {
                    Block b = chunk.getWorld().getHighestBlockAt(x, z).getRelative(BlockFace.UP);
                    if(b == null)
                          continue;
                    Biome bio = b.getBiome();
                    if(bio == Biome.DESERT || bio == Biome.FROZEN_OCEAN)
                          continue;
                      if(b.getRelative(BlockFace.NORTH).getType() == Material.AIR || b.getRelative(BlockFace.WEST).getType() == Material.AIR || b.getRelative(BlockFace.SOUTH).getType() == Material.AIR || b.getRelative(BlockFace.EAST).getType() == Material.AIR)
                         continue;
                      b.setType(Material.WATER);
                    }
                  }
                }
        }
    }
    
    Slightly Modified code from V10lator
    Doesn't seem to want to work. Any advice you guys? I do know java just haven't really worked in bukkit before :p
     
  24. Offline

    hammale

    Why r u using BlockFace.UP from the highest block? It should be down right?
     
  25. @hammale: No, cause you want the air block above the highest (non air) block. ;)

    //EDIT: @AdvsNoob: Your code will never be executed. Use bukkits scheduler for it, not a listener!
     
  26. Offline

    AdvsNoob


    Like i said before im new to bukkik, i have no idea how to do that :/
     
  27. Offline

    hammale

    look here, thats where i learned :D if i remember rite u want an ASYNC task!!
     
  28. Offline

    DirtyStarfish

    Might be better to use a sync task, not async.
     
  29. Offline

    hammale

    lol i stand corrected :D
     
  30. Offline

    AdvsNoob

    Bleh, i remember reading this. It confused the H*** out of me XD. Can anyone further explain?

    All i know for bukkit is how to use listeners :/ I have no clue about this stuff so i don't know what to change or not to change :p Pretty bad huh?
     

Share This Page