How can I make an infinite snow biome?

Discussion in 'Plugin Development' started by bogdacutu, Jan 5, 2012.

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

    bogdacutu

    Basically, I want a snow biome as large as the map. It should snow, the water should freeze. But randomly, not all at once (//snow), just like in SkyBlock. Is there any way to do this with only server-side code?
     
  2. Offline

    Jacek

    I wanted to do something similar, what I found is that the weather that is used is decided on by the client based on the seed and the sever just tells the client if it's raining or not.

    You could add some timed code to freeze water and add snow, but it would not be possible to make it actually snow instead of raining without doing something weird like changing the seed that is sent to the client as the players moves around to keep them in a snow biome.
     
  3. Offline

    bogdacutu

    I don't really care about the actual weather, I only want snow and ice. Weather will be disabled anyway.
     
  4. Offline

    Jacek

    Well in that case you can schedule a task to freeze and put-snow-on a few random blocks from each loaded chunk at some interval.
     
  5. Offline

    bogdacutu

    I'm a newbie, what's a scheduled task? :p
     
  6. The most eficient way is to hook every new chunk that is created and add snow on top of each block... that would require you to delete the existing chunks (not the whole world, keep level.dat to allow it to regen the same way).

    But if you want to slowly convert or instantly convert, you need to loop through each chunk and use tasks for the slow one... you can search about tasks, there are alot of examples :p
     
  7. Offline

    Jacek

    Ah sorry ;)

    A scheduled task is the same as it is in Windows, so you can have something repeat every X seconds. To set one up to repeat every 5 seconds you would use this in your plugins onEnable() method

    Code:
    this.getServer().getScheduler().scheduleSyncRepeatingTask(this, new PluginNameSnowTask(), 100, 100);
    The 100 is because the delay is actually in ticks not seconds and there are 20 ticks per second so 20 * 5 = 100

    The PluginNameSnowTask could then look something like this.

    Code:
    public class PluginNameSnowTask implements Runnable {
    
        public void run(){
    
        }
    
    }
    what ever code you put in the rum() method will then be executed every 5 seconds. So all that is left is to work out the snow thing. You need to add snow for every loaded chunk in every world at not cover the entire thing just some of it, you could do that like this

    Code:
    public class PluginNameSnowTask implements Runnable {
    
        private Random rand;
    
        public PluginNameSnowTask(){
            this.rand = new Random();
        }
    
        public void run(){
            int x, y, z, type;
    
            for (World world : Bukkit.getServer().getWorlds()){
                for (Chunk chunk : world.getLoadedChunks()){
                    x = this.rand.nextInt(16);
                    z = this.rand.nextInt(16);
    
                    for (y = 100; y > 0 && chunk.getChunkSnapshot().getBlockTypeId(x, y, z) == 0; --y);
    
                    type = chunk.getChunkSnapshot().getBlockTypeId(x, y, z);
    
                    if (type == Material.STATIONARY_WATER.getId()){
                        chunk.getBlock(x, y, z).setType(Material.ICE);
                    }else if (type != Material.SNOW.getId()){
                        chunk.getBlock(x, y + 1, z).setType(Material.SNOW);
                    }
                }
            }
        }
    
    }
    I didn't test this so it will need some tweaking. Also bare in mind that doing something for every block in every chunk is going to be a fairly intensive operation so you should test it locally.

    Does that help ?

    You could add a BlockPopulator to the world too to add the snow. :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 22, 2016
  8. @Jacek yes, that's what I meant, I dunno how they're called because I never used :p
     
  9. Offline

    bogdacutu

    I'm going to do it, like every 1 minute or something, and my server will be plot-based, so I'll also make it snow only on plots with players on them; no need to bother anyone else's stuff.
     
  10. Offline

    Jacek

    getLoadedChunk to a rough approximation will give you all chunks where players can see so that will be pretty much done for you.
     
Thread Status:
Not open for further replies.

Share This Page