Error with world generation

Discussion in 'Plugin Development' started by Peridot, Dec 2, 2017.

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

    Peridot

    Hi, i got following problem:
    I'm trying to make a custom world generator in bukkit 1.12.2 and this is the code in my generator class:
    Code:
        public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
            for (int X = 0; X < 16; X++) {
                for (int Z = 0; Z < 16; Z++) {
                        biome.setBiome(X, Z, Biome.PLAINS);
                        this.generateChunkData(world, random, x, z, biome).setBlock(X, 4, Z, Material.BEDROCK);
                }
            }
        
            return createChunkData((org.bukkit.World) world);
        }
    When i now try to generate a world using it i get an error that says i should use old methods that are stated deprecated in the bukkit javadoc:
    Code:
    ---- Minecraft Crash Report ----
    // Why is it breaking :(
    
    Time: 02.12.17 18:30
    Description: Exception generating new chunk
    
    java.lang.UnsupportedOperationException: Custom generator is missing required methods: generate(), generateBlockSections() and generateExtBlockSections()
        at org.bukkit.generator.ChunkGenerator.generate(ChunkGenerator.java:78)
        at org.bukkit.craftbukkit.v1_12_R1.generator.CustomChunkGenerator.getOrCreateChunk(CustomChunkGenerator.java:128)
        at net.minecraft.server.v1_12_R1.ChunkProviderServer.originalGetChunkAt(ChunkProviderServer.java:159)
        at net.minecraft.server.v1_12_R1.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:140)
        at net.minecraft.server.v1_12_R1.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:120)
        at net.minecraft.server.v1_12_R1.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:116)
        at org.bukkit.craftbukkit.v1_12_R1.CraftWorld.loadChunk(CraftWorld.java:268)
        at org.bukkit.craftbukkit.v1_12_R1.CraftWorld.loadChunk(CraftWorld.java:162)
        at org.bukkit.craftbukkit.v1_12_R1.CraftWorld.getHighestBlockYAt(CraftWorld.java:104)
        at org.bukkit.generator.ChunkGenerator.canSpawn(ChunkGenerator.java:270)
        at net.minecraft.server.v1_12_R1.WorldServer.canSpawn(WorldServer.java:258)
        at net.minecraft.server.v1_12_R1.WorldServer.b(WorldServer.java:980)
        at net.minecraft.server.v1_12_R1.WorldServer.a(WorldServer.java:902)
        at net.minecraft.server.v1_12_R1.MinecraftServer.a(MinecraftServer.java:267)
        at net.minecraft.server.v1_12_R1.DedicatedServer.init(DedicatedServer.java:248)
        at net.minecraft.server.v1_12_R1.MinecraftServer.run(MinecraftServer.java:522)
        at java.lang.Thread.run(Unknown Source)
    
    
    Could someone please explain why this is happening and what to do now or if my code is totally wrong.
    Thanks for reading this, and have a nice day
     
  2. Offline

    Caderape2

    @Peridot I'm not familiar with chunkGenerator, but if it can help, i show you how i generate a flat world with glass at 0 and 1, grass at 100, and dirt in the middle.

    I added the biome change. I did not test, but that should work.

    This code has someting like two years, so it's maybe not the most efficient way to do it.

    Code:
    public class CreativeGenerator extends ChunkGenerator
    {
    
    
        @SuppressWarnings("deprecation")
        public byte[] generate(World world, Random random, int cx, int cz)
        {
            byte[] result = new byte[32768];
    
            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    for (int y = 0; y <= 100; y++)
                    {  
                        if (y <= 1)
                        {
                             result[(x * 16 + z) * 128 + y] = (byte)Material.GLASS.getId();
                        }
                        else if (y == 100)
                        {
                             result[(x * 16 + z) * 128 + y] = (byte)Material.GRASS.getId();
                        }
                        else
                        {
                             result[(x * 16 + z) * 128 + y] = (byte)Material.DIRT.getId();
                        }
                      
                        int blockX = (cx << 4) + x;
                        int blockZ = (cz << 4) + z;
                      
                        world.getBlockAt(blockX, y, blockZ).setBiome(Biome.PLAINS);*
                    }
                }
            }
          
            world.refreshChunk(cx, cz);*
          
            return result;
        }
    }
    
    * i'm not sure if the biome method will work since the world is not fully loaded.


    Then implement in your mainclass the default method.
    Code:
        public ChunkGenerator getDefaultWorldGenerator(String worldName, String id)
        {
            if (worldName.equalsIgnoreCase("TheWorldYouWantToGenerate"))
            {
                return new CreativeGenerator();
            }
            return null;
          
        }
    
    And don't forget to load it on startup.
     
  3. Offline

    Peridot

    1. Thanks for replying so quickly
    2.
    That makes sense because its not been documented since 2011
    3. It sadly didn't work i get the same error even after i made changes that fixed the eclipse problems
    4. I guess that the ChunkGeneration API is just not working and that it has to be changed to work properly in 1.12
    5. Thank you very much for your reply, even though it didn't work (which isn't your fault of course), i am very grateful.
     
  4. Offline

    timtower Administrator Administrator Moderator

    @Peridot That old documentation still applies.
    The API is working, using it myself.
     
  5. Offline

    Peridot

    @timtower Ok, thanks for the info. But the what am I doing wrong, or should i use the deprecated ways?
     
  6. Offline

    timtower Administrator Administrator Moderator

    @Peridot Deprecated way is the only way currently.
     
  7. Offline

    Peridot

    @timtower Ok then, thank you very much, I'll try these and post further errors or
    successes here.

    @timtower Dude, i'm so thankful i thought that the deprecated methods didn't work anymore, i now tried dinnerbones moon generator, and it worked like a charm.
    Thank you very much you just solved all my problems :)

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Dec 3, 2017
    timtower likes this.
Thread Status:
Not open for further replies.

Share This Page