rutgerkok / WorldGeneratorApi

Minecraft Spigot plugin that enables other plugins to customize world generation
MIT License
96 stars 9 forks source link

BaseNoiseGenerator stone and water materials are null #44

Closed tastybento closed 3 years ago

tastybento commented 3 years ago

Describe the bug The default settings for TerrainSettings.stoneBlock and TerrainSetting.waterBlock are null in BaseNoiseGenerator so throw a NPE when invoked.

Stack trace:

[19:28:40 ERROR]: [BentoBox] java.lang.NullPointerException: Cannot invoke "org.bukkit.craftbukkit.v1_17_R1.block.data.CraftBlockData.getState()" because "settings.stoneBlock" is null
    at nl.rutgerkok.worldgeneratorapi.internal.bukkitoverrides.NoiseToTerrainGenerator.createNoiseSettings(NoiseToTerrainGenerator.java:75)
    at nl.rutgerkok.worldgeneratorapi.internal.bukkitoverrides.NoiseToTerrainGenerator.<init>(NoiseToTerrainGenerator.java:101)
    at nl.rutgerkok.worldgeneratorapi.internal.WorldGeneratorImpl.toBaseTerrainGenerator(WorldGeneratorImpl.java:241)
    at nl.rutgerkok.worldgeneratorapi.WorldGenerator.setBaseNoiseGenerator(WorldGenerator.java:114)
    at world.bentobox.boxed.generators.BoxedChunkGenerator.lambda$getGenerator$0(BoxedChunkGenerator.java:31)
    at nl.rutgerkok.worldgeneratorapi.internal.WorldGeneratorApiImpl.lambda$1(WorldGeneratorApiImpl.java:123)
    at java.base/java.util.HashMap.computeIfAbsent(HashMap.java:1224)
    at nl.rutgerkok.worldgeneratorapi.internal.WorldGeneratorApiImpl.getForWorld(WorldGeneratorApiImpl.java:110)
    at nl.rutgerkok.worldgeneratorapi.internal.WorldGeneratorApiImpl.onWorldAddOrRemove(WorldGeneratorApiImpl.java:183)
    at nl.rutgerkok.worldgeneratorapi.internal.WorldGeneratorApiImpl.lambda$2(WorldGeneratorApiImpl.java:158)
    at nl.rutgerkok.worldgeneratorapi.internal.ChangeListeningMap.put(ChangeListeningMap.java:64)
    at org.bukkit.craftbukkit.v1_17_R1.CraftServer.addWorld(CraftServer.java:1279)
    at net.minecraft.server.level.WorldServer.<init>(WorldServer.java:384)
    at org.bukkit.craftbukkit.v1_17_R1.CraftServer.createWorld(CraftServer.java:1177)
    at org.bukkit.Bukkit.createWorld(Bukkit.java:615)
    at org.bukkit.WorldCreator.createWorld(WorldCreator.java:380)
    at world.bentobox.boxed.Boxed.getWorld(Boxed.java:198)
    at world.bentobox.boxed.Boxed.createWorlds(Boxed.java:170)
    at world.bentobox.bentobox.managers.AddonsManager.enableAddon(AddonsManager.java:288)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at java.base/java.util.stream.ReferencePipeline$2$1.accept(ReferencePipeline.java:179)
    at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1625)
    at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
    at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
    at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
    at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
    at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
    at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
    at world.bentobox.bentobox.managers.AddonsManager.enableAddons(AddonsManager.java:237)
    at world.bentobox.bentobox.BentoBox.completeSetup(BentoBox.java:186)
    at world.bentobox.bentobox.BentoBox.lambda$onEnable$0(BentoBox.java:172)
    at org.bukkit.craftbukkit.v1_17_R1.scheduler.CraftTask.run(CraftTask.java:100)
    at org.bukkit.craftbukkit.v1_17_R1.scheduler.CraftScheduler.mainThreadHeartbeat(CraftScheduler.java:468)
    at net.minecraft.server.MinecraftServer.x(MinecraftServer.java:1127)
    at net.minecraft.server.MinecraftServer.lambda$spin$0(MinecraftServer.java:320)
    at java.base/java.lang.Thread.run(Thread.java:831)

To Reproduce

This is the code to return the generator:

public ChunkGenerator getGenerator() {
        return WorldGeneratorApi
                .getInstance(addon.getPlugin(), 0, 5)
                .createCustomGenerator(wordRef, generator -> {
                    // Set the noise generator
                    generator.setBaseNoiseGenerator(new OverWorldGenerator(addon, addon.getSettings().getSeed()));
                    if (!addon.getSettings().isAllowStructures()) {
                        generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.SURFACE_STRUCTURES);
                    }
                    if (!addon.getSettings().isAllowStrongholds()) {
                        generator.getWorldDecorator().withoutDefaultDecorations(DecorationType.STRONGHOLDS);
                    }
                    generator.setBiomeGenerator(new BoxedBiomeGenerator(addon));
                });
    }

Class OverWorldGenerator implements BaseNoiseGenerator. With the previous API, it was not required to override getTerrainSettings, except when you wanted to change stone and water to something else, e.g., for the nether or end. However in this API, it appears it is required even for the over-world otherwise you get the above NPE. So, I was able to work around the error by explicitly overriding this method, i.e.:

    @Override
    public TerrainSettings getTerrainSettings() {
        TerrainSettings ts = new TerrainSettings();
        ts.stoneBlock = Material.STONE.createBlockData();
        ts.waterBlock = Material.WATER.createBlockData();
        return ts;
    }

I looked through BaseNoiseGenerator and the these fields are set to null with the comment Set to null to use the server default.. As this code has not changed for a long time, I assume the server default is no longer set, so remains null?

I assume this is a bug?

rutgerkok commented 3 years ago

Thanks for reporting! It's a bug indeed. It should be fixed in the latest dev build (build 42):

https://ci.codemc.io/job/rutgerkok/job/WorldGeneratorApi/

(Code change: https://github.com/rutgerkok/WorldGeneratorApi/commit/8b901bafc6c98c8c37cd1bd114a892032fc35329 )