How do I create a plot style world?

Discussion in 'Spigot Plugin Development' started by RandomPanda30, Jul 1, 2015.

  1. Hello there, I have never before created custom worlds using Bukkit. I was wondering if someone could teach me how to make a plot style world? Thanks!
     
  2. Take a look at how PlotSquared did it, as frankhawk12 said.
     
  3. That's a positive start!

    I could do this although I'd rather not root through a ton of source code which I don't understsand and rather have someone explain how it's done. I'll have a try but can't really do much when I don't know what's going on.
     
    • Agree Agree x 1
  4. You can download a plugin with a world generator such as PlotMe, when creating a world with Multiverse or MultiWorld. You can specify the generation type in the string
    EXAMPLE:
    Multiverse
    Code (Text):
    /mv create plotworld normal -g PlotMe
    MultiWorld
    Code (Text):
    /mw create plotworld plugin:PlotMe
     
  5. I'm on about Bukkit code sorry. About the basics of how to create a world in Bukkit and make a plotme type of world
     
  6. Can I just clarify, I'm looking for someone to explain to me how I would create a world with a Plot type of layout .-. Using Java and Spigot may I add.
     
    • Like Like x 1
    • Informative Informative x 1
  7. Okay, might want to decompile the PlotMe-DefaultGenerator jar and see if you can pick apart its pieces. Just make sure not to make it a premium resource if you use too many similar methods from their code...
     
    • Like Like x 1
  8. I'm only making a plugin for learning anyway so it's alright; just filling in a lot of gaps in my knowledge. Thank you very much for specifying the actual thing I need to look at as well. Anymore help or suggestions is much appreciated!
     
  9. The default PlotSquared generator isn't the best place to start, it's overly complex for what you want to do:
    - There's the PlotGenerator class which is a wrapper around ChunkGenerator, and it can be wrapped into a BlockPopulator using the AugmentedPopulator class so it can be injected into other generators.
    - The generator itself is a mix of schematic generation and plot generation
    - It also has some crazy optimizations jammed in for various things like schematic pasting and plot clearing which are built directly into the generator.

    The PlotMe generator also probably isn't very useful since it looks like this.

    If you want to learn how to use generators, here's a useful tutorial.
    http://bukkit.org/threads/the-alway...ation-part-one-prerequisites-and-setup.93982/

    I've written up a fast plot generator here, which has the basics of what you'd expect in a plot generator:
    https://gist.github.com/boy0001/e12ff4a80ad06a15ff24

    If you want to sacrifice functionality, there are also some neat optimizations you can make:

    This is the old PlotSquared generator that used cuboids to reduce the loop depth:
    https://github.com/boy0001/ClassicPlotGenerator/tree/master/src/com/empcraft/classic
    - It's not simple, but the benefit is that there was no logic or checks inside the loops making it fairly efficient
    - Kind of the opposite of PlotMe which appears to put as much logic inside loops as it can
    - The downside to this is that it's incredibly difficult to have anything apart from simple cuboids making up the plot, so schematics in generation are out of the question

    This is a simple generator that has one plot per chunk:
    https://github.com/boy0001/BasicPlotGenerator/tree/master/src/com/boydti/basicplots
    - It's fast as it generates the array for the chunk when it initializes and returns that same array for every chunk
    - The downside is that plots need to be the size of a chunk so it's not very customizable

    This is a simple generator that uses region files for generation:
    https://github.com/boy0001/PlotSquaredMG/tree/master/src/com/boydti/psmg
    - It takes ages to load up, but allows large areas of custom terrain
    - Since it's using region files, it can easily pre-generate the map on startup, and since the plot size is a multiple of 16, it calculates all the chunk arrays during startup
    - The obvious downside is the long startup time, and that plots must be huge (multiples of 512)

    Once you have a generator, to then create the world with code, you can use the WorldCreator class. Here's what PlotSquared uses to create the worlds:
    https://github.com/IntellectualSite...lot/util/bukkit/BukkitSetupUtils.java#L76-L79
    please note that you need to do some other stuff if you want Multiverse or MultiWorld to recognize the world.
     
    #12 Empire92, Jul 2, 2015
    Last edited: Jul 21, 2015
    • Informative Informative x 4
    • Like Like x 2
  10. Why has this been moved to a irrelevant thread? Please move it back to plugin development since I need help developing a plugin!
     
  11. Thank you so so much! Really I cannot thank you enough for the help. I'll post the source code once I've coded it! Thank you!
     
  12. Ok so looking at this code that I've found and managed to copy -

    PHP:
    int worldChunkX = chunkX * 16;
            int worldChunkZ = chunkZ * 16;

            for (int x = 0; x < 16; x++) {
                for (int z = 0; z < 16; z++) {
                    // setBlockAt(chunk, x, 0, z, this.bedId);

                    for (int y = 1; y < this.plotHeight; y++) {
                        // setBlockAt(chunk, x, y, z, this.baseId);
                    }

                    if ((isGateBlock(worldChunkX + x, worldChunkZ + z))
                            || (isPathBlock(worldChunkX + x, worldChunkZ + z))) {
                        setBlockAt(chunk, x, this.plotHeight, z,
                                (byte) Material.AIR.getId());
                        setBlockAt(chunk, x, this.plotHeight, z + 1,
                                (byte) Material.AIR.getId());

                        biomes.setBiome(x, z, this.pathBiome);
                    } else if (isWallBlock(worldChunkX + x, worldChunkZ + z)) {
                        setBlockAt(chunk, x, this.plotHeight, z,
                                (byte) Material.AIR.getId());
                        setBlockAt(chunk, x, this.plotHeight + 1, z,
                                (byte) Material.AIR.getId());
                        setBlockAt(chunk, x, this.plotHeight + 2, z,
                                (byte) Material.AIR.getId());

                        biomes.setBiome(x, z, this.pathBiome);
                    } else {
                        setBlockAt(chunk, x, this.plotHeight, z,
                                (byte) Material.AIR.getId());

                        biomes.setBiome(x, z, this.plotBiome);
                    }
                }
            }
    I want to learn how to make the spacing between the paths bigger although I cannot think of how to do this. Does anyone have any suggestions?
     
  13. Bump anyone. Need help and this thread is actually in the wrong section ;-;
     
    • Optimistic Optimistic x 1
  14. Thank you for moving!
     
  15. The code responsible for the spacing would be in `isGateBlock` and `isWallBlock`.

    Assuming the "wallBlock" in this is the stuff between the plots, and the "gate" is around each plot. Some psuedocode (you pass the reduced x, z values to these methods)

    if x < wall lower or z < wall lower or x > wall upper or z > wall upper
    then is wall block


    if x = wall lower or z = wall lower or x = wall upper or z = wall upper
    then is gate block


    To reduce the x, or z coordinate:
    x (reduced) = x < 0 ? (x % total width) + total width : x % total width
    z (reduced) = z < 0 ? (z % total width) + total width : z % total width


    Some other changes you should make:
    - You set the biome in each if/else if/else block - you should instead move this up out of the if/else if/else as you do it regardless of that result
    - The isWallBlock should be in the if and the isGateBlock should be in the else if, unless you want the gate cutting through the wall intersection
     
  16. Youre on the wrong forum m8. This is Spigot Plugin Development
     
  17. Ok so I did as you said and did this:

    PHP:
    byte[][] chunk = new byte[(int) Math
                    .ceil((this.plotHeight + 2.0D) / 16.0D)][4096];

            int worldChunkX = chunkX * 16;
            int worldChunkZ = chunkZ * 16;

            for (int x = 0; x < 16; x++) {
                for (int z = 0; z < 16; z++) {
                    // setBlockAt(chunk, x, 0, z, this.bedId);

                    for (int y = 1; y < this.plotHeight; y++) {
                        // setBlockAt(chunk, x, y, z, this.baseId);
                    }

                    if (isWallBlock(worldChunkX + x, worldChunkZ + z)) {
                        setBlockAt(chunk, x, this.plotHeight, z, this.hiddenId);
                        setBlockAt(chunk, x, this.plotHeight + 1, z, this.pathId);
                    } else if ((isGateBlock(worldChunkX + x, worldChunkZ + z))
                            || (isPathBlock(worldChunkX + x, worldChunkZ + z))) {
                        setBlockAt(chunk, x, this.plotHeight, z,
                                (byte) (this.surfaceId == Material.GRASS.getId()
                                        ? Material.DIRT.getId() : this.surfaceId));
                        setBlockAt(chunk, x, this.plotHeight + 1, z,
                                this.wallLowerId);
                        setBlockAt(chunk, x, this.plotHeight + 2, z,
                                this.wallUpperId);
                    } else {
                        setBlockAt(chunk, x, this.plotHeight, z, this.surfaceId);
                    }

                    biomes.setBiome(x, z, this.plotBiome);
                }
            }
    And it produces this:

    [​IMG]

    The air represents the path. I set it as dirt by accident and the grass grew over it but I'll change it later. After understanding about this small part now, I'm grateful but still baffled how the path can be made wider.

    Note: This isn't my code. I found a plot style plugin and I'm using the source code from that to actually learn how to do plots etc... ;P Just to clarify that.