World generation/terrain.

Discussion in 'Spigot Plugin Development' started by avighnash, May 27, 2016.

  1. I have been interested in terrain generation, so I decided to look more farther into it. After some research, I learned how to make a flat world.
    Here is the code:

    Code (Text):
    package us.universalpvp.world;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;

    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.generator.BlockPopulator;
    import org.bukkit.generator.ChunkGenerator;
    import org.bukkit.plugin.java.JavaPlugin;

    public class WorldMain extends JavaPlugin {

        public void onEnable() {

        }

        public void onDisable() {

        }

        public ChunkGenerator getDefaultWorldGenerator(String worldName, String GenId) {
            return new us.universalpvp.world.WorldMain.BasicChunkGenerator();
        }

        public class BasicChunkGenerator extends ChunkGenerator {

            void setBlock(int x, int y, int z, byte[][] chunk, Material material) {
                if (chunk[y >> 4] == null)
                    chunk[y >> 4] = new byte[16 * 16 * 16];
                if (!(y <= 256 && y >= 0 && x <= 16 && x >= 0 && z <= 16 && z >= 0))
                    return;
                try {
                    chunk[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = (byte) material.getId();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public byte[][] generateBlockSections(World world, Random rand, int ChunkX, int ChunkZ, BiomeGrid biome) {
                return null;
            }

            @Override
            public List<BlockPopulator> getDefaultPopulators(World world) {
                ArrayList<BlockPopulator> pops = new ArrayList<BlockPopulator>();
                // Add Block populators here
                return pops;
            }
        }

    }
     
    the only problem, is that the world is not flat.
    I put this in my Bukkit.yml"

    Code (Text):
    worlds:
      world:
        generator: WorldGen
    but does not work.
    How do I fix this? Thanks!
     
  2. in your plugin.yml set Set load: STARTUP
     
  3. I did load: startup but not load: STARTUP... does case matter in it?
     
  4. mhm, i dont think so, give it a try though?
     
  5. does not work. is it because the world "world" is already made?
     
  6. tr y removing the current work.
     
  7. The server crashed with this error:

    Code (Text):
    [14:53:28 ERROR]: Encountered an unexpected exception
    net.minecraft.server.v1_8_R3.ReportedException: Exception generating new chunk        at net.minecraft.server.v1_8_R3.WorldServer.a(WorldServer.java:816) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:273) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.UnsupportedOperationException: Custom generator is missing required methods: generate(), generateBlockSections() and generateExtBlockSections()
            at org.bukkit.generator.ChunkGenerator.generate(ChunkGenerator.java:78) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.generator.CustomChunkGenerator.getOrCreateChunk(CustomChunkGenerator.java:129) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.originalGetChunkAt(ChunkProviderServer.java:142) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:118) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:97) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.loadChunk(CraftWorld.java:253) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.loadChunk(CraftWorld.java:150) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.getHighestBlockYAt(CraftWorld.java:99) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.generator.ChunkGenerator.canSpawn(ChunkGenerator.java:270) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.canSpawn(WorldServer.java:199) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.b(WorldServer.java:879) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.a(WorldServer.java:801) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            ... 4 more
    [14:53:28 ERROR]:       Cause of unexpected exception was
    java.lang.UnsupportedOperationException: Custom generator is missing required methods: generate(), generateBlockSections() and generateExtBlockSections()
            at org.bukkit.generator.ChunkGenerator.generate(ChunkGenerator.java:78) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.generator.CustomChunkGenerator.getOrCreateChunk(CustomChunkGenerator.java:129) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.originalGetChunkAt(ChunkProviderServer.java:142) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:118) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:97) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.loadChunk(CraftWorld.java:253) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.loadChunk(CraftWorld.java:150) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.getHighestBlockYAt(CraftWorld.java:99) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.generator.ChunkGenerator.canSpawn(ChunkGenerator.java:270) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.canSpawn(WorldServer.java:199) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.b(WorldServer.java:879) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.a(WorldServer.java:801) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:273) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
     
  8. Caused by: java.lang.UnsupportedOperationException: Custom generator is missing required methods: generate(), generateBlockSections() and generateExtBlockSections()
     
  9. Okay, new error:

    Code (Text):
    [15:24:15 ERROR]: Encountered an unexpected exception
    net.minecraft.server.v1_8_R3.ReportedException: Exception generating new chunk        at net.minecraft.server.v1_8_R3.WorldServer.a(WorldServer.java:816) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:273) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Caused by: java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R3.generator.CustomChunkGenerator.getOrCreateChunk(CustomChunkGenerator.java:130) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.originalGetChunkAt(ChunkProviderServer.java:142) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:118) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:97) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.loadChunk(CraftWorld.java:253) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.loadChunk(CraftWorld.java:150) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.getHighestBlockYAt(CraftWorld.java:99) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.generator.ChunkGenerator.canSpawn(ChunkGenerator.java:270) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.canSpawn(WorldServer.java:199) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.b(WorldServer.java:879) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.a(WorldServer.java:801) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            ... 4 more
    [15:24:15 ERROR]:       Cause of unexpected exception was
    java.lang.NullPointerException
            at org.bukkit.craftbukkit.v1_8_R3.generator.CustomChunkGenerator.getOrCreateChunk(CustomChunkGenerator.java:130) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.originalGetChunkAt(ChunkProviderServer.java:142) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:118) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:97) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.loadChunk(CraftWorld.java:253) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.loadChunk(CraftWorld.java:150) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.craftbukkit.v1_8_R3.CraftWorld.getHighestBlockYAt(CraftWorld.java:99) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at org.bukkit.generator.ChunkGenerator.canSpawn(ChunkGenerator.java:270) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.canSpawn(WorldServer.java:199) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.b(WorldServer.java:879) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.WorldServer.a(WorldServer.java:801) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.a(MinecraftServer.java:273) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.DedicatedServer.init(DedicatedServer.java:263) ~[spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at net.minecraft.server.v1_8_R3.MinecraftServer.run(MinecraftServer.java:525) [spigot.jar:git-Spigot-e4d4710-e1ebe52]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_91]
    Where is the NPE pointed to in my code?

    new class:

    Code (Text):
    package us.universalpvp.world;

    import java.util.ArrayList;
    import java.util.List;
    import java.util.Random;

    import org.bukkit.Material;
    import org.bukkit.World;
    import org.bukkit.generator.BlockPopulator;
    import org.bukkit.generator.ChunkGenerator;
    import org.bukkit.plugin.java.JavaPlugin;

    public class WorldMain extends JavaPlugin {

        public void onEnable() {

        }

        public void onDisable() {

        }

        public ChunkGenerator getDefaultWorldGenerator(String worldName, String GenId) {
            return new us.universalpvp.world.WorldMain.BasicChunkGenerator();
        }

        public class BasicChunkGenerator extends ChunkGenerator {

            void setBlock(int x, int y, int z, short[][] chunk, Material material) {
                if (chunk[y >> 4] == null)
                    chunk[y >> 4] = new short[16 * 16 * 16];
                if (!(y <= 256 && y >= 0 && x <= 16 && x >= 0 && z <= 16 && z >= 0))
                    return;
                try {
                    chunk[y >> 4][((y & 0xF) << 8) | (z << 4) | x] = (byte) material.getId();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            @Override
            public byte[][] generateBlockSections(World world, Random rand, int ChunkX, int ChunkZ, BiomeGrid biome) {
                return null;
            }

            @Override
            public List<BlockPopulator> getDefaultPopulators(World world) {
                ArrayList<BlockPopulator> pops = new ArrayList<BlockPopulator>();
                // Add Block populators here
                return pops;
            }

            public byte[] generate(World world, Random random, int x, int z) {
                return null;
            }

            public short[][] generateExtBlockSections(World world, Random rand, int x, int z) {
                return null;
            }
        }

    }
     
    I took a look at the bukkit java docs for this info.
     
  10. You are literally returning null on the generate methods, what do you expect to happen?
     
  11. Yes because I am not using those methods... well true. I'll see what I can do.
     
  12. Any ideas? I still have no luck.
     
  13. You wot m8
     
  14. Learning* oops xD
     
  15. Still get no answers :/
     
  16. Not many people know about world generation, the only person i know who does is @minelazz
     
  17. minelazz

    Supporter

    Simple, trash the bukkit API for world generators. It has been outdated a long time. Depending on what need it for, it might be completely unusable.

    If you have problems with these simple things, I would not recommend starting on a world generator. If really want to learn it, you could startof here;
    https://github.com/Wolf-in-a-bukkit...aftbukkit/generator/CustomChunkGenerator.java

    It is a tiny bit outdated, but explains how the world generators in minecraft works. It would basicly not create any terrain, as that is up to you to handle. It will only shows you how the mechanics around it works.


    Edit: To start of;
    Code (Text):
      public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome)
      {
        //TODO return new chunk data;
      }
     
    #18 minelazz, May 28, 2016
    Last edited: May 28, 2016
    • Like Like x 2
  18. Did you have to use this class for your custom world generator?