1.15.2 Trouble getting random blocks for a sky grid generator.

Discussion in 'Spigot Plugin Development' started by hobblyhobo, Jan 19, 2020.

  1. I am making a sky grid generator but I am having trouble grabbing random materials to set for the chunk generator.

    Here is my code:

    Code (Java):
    public class GridGenerator extends ChunkGenerator {

        private int materialSize = Material.values().length;

        @Override
        public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
            ChunkData data = createChunkData(world);
            Material material;

            for (int X = 0; X < 8; X++) {
                for (int Z = 0; Z < 8; Z++) {
                    for (int Y = 0; Y < 128; Y++) {
                        material = Material.values()[random.nextInt(materialSize)];
                        while (!material.isBlock() || material.isAir()) {
                            material = Material.values()[random.nextInt(materialSize)];
                        }
                        data.setBlock(X*2, Y*2, Z*2, material);
                    }
                }
            }
            return data;
        }
    }
    I am getting a strange error that does not point to my code but is somehow caused by it:

    Code (Text):
    [13:23:49 ERROR]: Encountered an unexpected exception
    net.minecraft.server.v1_15_R1.ReportedException: Exception generating new chunk
            at net.minecraft.server.v1_15_R1.MinecraftServer.initWorld(MinecraftServer.java:515) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:451) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.DedicatedServer.init(DedicatedServer.java:290) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:884) ~[patched_1.15.1.jar:git-Paper-30]
            at java.lang.Thread.run(Unknown Source) [?:1.8.0_231]
    Caused by: java.lang.NullPointerException
            at net.minecraft.server.v1_15_R1.ProtoChunk.setTileEntity(ProtoChunk.java:230) ~[patched_1.15.1.jar:git-Paper-30]
            at org.bukkit.craftbukkit.v1_15_R1.generator.CustomChunkGenerator.buildBase(CustomChunkGenerator.java:135) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ChunkStatus.lambda$static$6(ChunkStatus.java:51) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ChunkStatus$d.doWork(ChunkStatus.java:240) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ChunkStatus.a(ChunkStatus.java:186) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.PlayerChunkMap.lambda$null$20(PlayerChunkMap.java:672) ~[patched_1.15.1.jar:git-Paper-30]
            at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.PlayerChunkMap.lambda$b$22(PlayerChunkMap.java:670) ~[patched_1.15.1.jar:git-Paper-30]
            at java.util.concurrent.CompletableFuture.uniCompose(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.CompletableFuture$UniCompose.tryFire(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.CompletableFuture$Completion.run(Unknown Source) ~[?:1.8.0_231]
            at net.minecraft.server.v1_15_R1.ChunkTaskQueueSorter.b(SourceFile:58) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ThreadedMailbox.e(SourceFile:83) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ThreadedMailbox.a(SourceFile:123) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ThreadedMailbox.run(SourceFile:91) ~[patched_1.15.1.jar:git-Paper-30]
            at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) ~[?:1.8.0_231]
    [13:23:49 ERROR]:       Cause of unexpected exception was
    java.lang.NullPointerException: null
            at net.minecraft.server.v1_15_R1.ProtoChunk.setTileEntity(ProtoChunk.java:230) ~[patched_1.15.1.jar:git-Paper-30]
            at org.bukkit.craftbukkit.v1_15_R1.generator.CustomChunkGenerator.buildBase(CustomChunkGenerator.java:135) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ChunkStatus.lambda$static$6(ChunkStatus.java:51) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ChunkStatus$d.doWork(ChunkStatus.java:240) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ChunkStatus.a(ChunkStatus.java:186) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.PlayerChunkMap.lambda$null$20(PlayerChunkMap.java:672) ~[patched_1.15.1.jar:git-Paper-30]
            at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.PlayerChunkMap.lambda$b$22(PlayerChunkMap.java:670) ~[patched_1.15.1.jar:git-Paper-30]
            at java.util.concurrent.CompletableFuture.uniCompose(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.CompletableFuture$UniCompose.tryFire(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.CompletableFuture$Completion.run(Unknown Source) ~[?:1.8.0_231]
            at net.minecraft.server.v1_15_R1.ChunkTaskQueueSorter.b(SourceFile:58) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ThreadedMailbox.e(SourceFile:83) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ThreadedMailbox.a(SourceFile:123) ~[patched_1.15.1.jar:git-Paper-30]
            at net.minecraft.server.v1_15_R1.ThreadedMailbox.run(SourceFile:91) ~[patched_1.15.1.jar:git-Paper-30]
            at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.ForkJoinTask.doExec(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.ForkJoinPool.runWorker(Unknown Source) ~[?:1.8.0_231]
            at java.util.concurrent.ForkJoinWorkerThread.run(Unknown Source) ~[?:1.8.0_231]
    The closest thing I can think of given the error is tile entities are causing it however when I tried filtering out material tile entities I failed.
     
  2. Did you try and print which material caused this error?
     
  3. Try to do this:
    Code (Text):

    public class GridGenerator extends ChunkGenerator {

        @Override
        public ChunkData generateChunkData(World world, Random random, int x, int z, BiomeGrid biome) {
            ChunkData data = createChunkData(world);
            Material material;

            for (int X = 0; X < 8; X++) {
                for (int Z = 0; Z < 8; Z++) {
                    for (int Y = 0; Y < 128; Y++) {
                        do {
                            material = Material.values[random.nextInt(Material.values().length)];
                        } while (!material.isBlock() || material.isAir() || material == null)
                        data.setBlock(X*2, Y*2, Z*2, material);
                    }
                }
            }
            return data;
        }
    }