Solved Bukkit ChunkGenerator causing floating dirt

Discussion in 'Spigot Plugin Development' started by Hex_27, Feb 22, 2020.

  1. This is the only code that I have in my chunk generator. No block populators. However, if I were to till some soil, the soil will never get wet, and it will instead spawn a dirt block above it. I'm not sure how to fix it. Here's an image of what happens:
    upload_2020-2-22_9-32-9.png

    This is my generateChunkData method. It's the only method in the class.
    Code (Java):
        @Override
        public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biome) {
            ChunkData chunk = createChunkData(world);    
            if(map == null) map = new HeightMap();
            TerraformWorld tw = TerraformWorld.get(world);
            //Bukkit.getLogger().info("Attempting gen: " + chunkX + "," + chunkZ);
           
            for (int x = 0; x < 16; x++){
                for (int z = 0; z < 16; z++) {
                    int rawX = chunkX*16+x;
                    int rawZ = chunkZ*16+z;

                    int height = map.getHeight(tw, rawX, rawZ);

                    BiomeBank bank = tw.getBiomeBank(rawX, height, rawZ);

                    Material[] crust = bank.getHandler().getSurfaceCrust(random);
                    //biome.setBiome(x, z, bank.getHandler().getBiome());
                    for(int y = 255; y >= 0; y--){
                       
                        if(chunk.getType(x,y,z) != null&&
                                chunk.getType(x,y,z) != Material.AIR) continue;
                       
                        if(y > seaLevel && y > height){
                            chunk.setBlock(x, y, z, Material.AIR);
                        }else if(y <= seaLevel && y > height){
                            chunk.setBlock(x, y, z, Material.WATER);
                        }else if(y >= height-crust.length+1){
                            chunk.setBlock(x,y,z,Material.DIRT);
                            //chunk.setBlock(x,y,z,crust[height-y]);
                        }else if(y > 3){
                            chunk.setBlock(x, y, z, Material.STONE);
                        }else if(y > 0){
                            chunk.setBlock(x, 2, z, Material.BEDROCK);
                            chunk.setBlock(x, 1, z, Material.BEDROCK);
                        }else{
                            chunk.setBlock(x, 0, z, Material.BEDROCK);
                        }
                    }
                }
            }
            //Bukkit.getLogger().info("Finished: " + chunkX + "," + chunkZ);
           
            return chunk;
        }
     
    • Agree Agree x 1
  2. I struggled with this problem for a very long time. This needs to be investigated by more people. :(
     
  3. Update, this code solves the problem, but isn't satisfactory:
    Code (Java):
        @Override
        public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biome) {
            ChunkData chunk = this.createChunkData(world);  
            //if(map == null) map = new HeightMap();
           // TerraformWorld tw = TerraformWorld.get(world);
            //Bukkit.getLogger().info("Attempting gen: " + chunkX + "," + chunkZ);
         
            for (int x = 0; x < 16; x++){
                for (int z = 0; z < 16; z++) {
                    int rawX = chunkX*16+x;
                    int rawZ = chunkZ*16+z;

                    //Not the height map's fault.
                    int height = 70;//map.getHeight(tw, rawX, rawZ);

                    //BiomeBank bank = tw.getBiomeBank(rawX, height, rawZ);
                 
                    //Not the crust's fault
                    //Material[] crust = bank.getHandler().getSurfaceCrust(random);
                    //biome.setBiome(x, z, bank.getHandler().getBiome());
                    for(int y = 255; y >= 0; y--){
                     
                        if(chunk.getType(x,y,z) != null&&
                                chunk.getType(x,y,z) != Material.AIR) continue;
                     
                        if(y > seaLevel && y > height){
                            //chunk.setBlock(x, y, z, Material.AIR);
                        }else if(y <= seaLevel && y > height){
                            //chunk.setBlock(x, y, z, Material.WATER);
                        }else if(y >= 65){//if(y >= height-crust.length+1){
                            //chunk.setBlock(x,y,z,Material.DIRT);
                            //chunk.setBlock(x,y,z,crust[height-y]);
                        }else if(y > 3){
                            chunk.setBlock(x, y, z, Material.STONE);
                        }else if(y > 0){
                            chunk.setBlock(x, y, z, Material.BEDROCK);
                        }else{
                            chunk.setBlock(x, y, z, Material.BEDROCK);
                        }
                    }
                }
            }
            return chunk;
        }
    Basically I commented out setting air, water and dirt. But I need them, and I don't know why they're causing it. Will look further.
     
  4. Try using BlockData rather than Material when using chunk.setBlock(x, y, z, _ );
     
  5. Same result.

    Right now, I cleaned it and compressed it. Same problems.

    Code (Java):
    public class CG extends ChunkGenerator{

        public static final int seaLevel = 62;
     
        public ChunkData generateChunkData(World world, Random random, int chunkX, int chunkZ, BiomeGrid biome) {
            ChunkData chunk = this.createChunkData(world);
            int height = 70;
            for(int x = 0; x < 16; x++){
                for(int z = 0; z < 16; z++){
                    for(int y = 255; y >= 0; y--){
                     
                        if(chunk.getType(x,y,z) != null&&
                                chunk.getType(x,y,z) != Material.AIR) continue;
                     
                        if(y > seaLevel && y > height){
                            chunk.setBlock(x, y, z, Bukkit.createBlockData(Material.AIR));
                        }else if(y <= seaLevel && y > height){
                            chunk.setBlock(x, y, z, Bukkit.createBlockData(Material.WATER));
                        }else if(y >= 65){
                            chunk.setBlock(x,y,z,Bukkit.createBlockData(Material.DIRT));
                        }else if(y > 3){
                            chunk.setBlock(x, y, z, Bukkit.createBlockData(Material.STONE));
                        }else if(y > 0){
                            chunk.setBlock(x, y, z, Bukkit.createBlockData(Material.BEDROCK));
                        }else{
                            chunk.setBlock(x, y, z, Bukkit.createBlockData(Material.BEDROCK));
                        }
                    }
                }
            }
            return chunk;
        }
    }
     
    #5 Hex_27, Feb 22, 2020
    Last edited: Feb 22, 2020
  6. Been trying to trace the stacks of where the dirt physics is being updated. I'll leave the stack traces here for reference.

    Natural physics update
    Code (Text):
    java.lang.Exception
    [14:22:56] [Server thread/WARN]:        at org.terraform.main.BlockPhysicsFixer.onBlockPhysics(BlockPhysicsFixer.java:43)
    [14:22:56] [Server thread/WARN]:        at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    [14:22:56] [Server thread/WARN]:        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [14:22:56] [Server thread/WARN]:        at java.lang.reflect.Method.invoke(Unknown Source)
    [14:22:56] [Server thread/WARN]:        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315)
    [14:22:56] [Server thread/WARN]:        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70)
    [14:22:56] [Server thread/WARN]:        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:541)
    [14:22:56] [Server thread/WARN]:        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:528)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.World.a(World.java:423)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.World.applyPhysics(World.java:384)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.World.update(World.java:371)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.World.notifyAndUpdatePhysics(World.java:298)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.ItemStack.placeItem(ItemStack.java:245)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.PlayerInteractManager.a(PlayerInteractManager.java:481)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.PlayerConnection.a(PlayerConnection.java:1251)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:27)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.PacketPlayInUseItem.a(PacketPlayInUseItem.java:1)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.PlayerConnectionUtils.lambda$0(PlayerConnectionUtils.java:19)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.TickTask.run(SourceFile:18)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeTask(SourceFile:144)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.IAsyncTaskHandlerReentrant.executeTask(SourceFile:23)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.executeNext(SourceFile:118)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.MinecraftServer.ba(MinecraftServer.java:918)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.MinecraftServer.executeNext(MinecraftServer.java:911)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.IAsyncTaskHandler.awaitTasks(SourceFile:127)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.MinecraftServer.sleepForTick(MinecraftServer.java:895)
    [14:22:56] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:828)
    [14:22:56] [Server thread/WARN]:        at java.lang.Thread.run(Unknown Source
    Bugged physics update
    Code (Text):
    [14:20:57] [Server thread/WARN]: java.lang.Exception
    [14:20:57] [Server thread/WARN]:        at org.terraform.main.BlockPhysicsFixer.onBlockPhysics(BlockPhysicsFixer.java:43)
    [14:20:57] [Server thread/WARN]:        at sun.reflect.GeneratedMethodAccessor3.invoke(Unknown Source)
    [14:20:57] [Server thread/WARN]:        at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [14:20:57] [Server thread/WARN]:        at java.lang.reflect.Method.invoke(Unknown Source)
    [14:20:57] [Server thread/WARN]:        at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315)
    [14:20:57] [Server thread/WARN]:        at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70)
    [14:20:57] [Server thread/WARN]:        at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:541)
    [14:20:57] [Server thread/WARN]:        at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:528)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.World.notifyAndUpdatePhysics(World.java:312)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.World.setTypeAndData(World.java:270)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.World.setTypeUpdate(World.java:358)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.BlockSoil.fade(BlockSoil.java:105)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.BlockSoil.tick(BlockSoil.java:63)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.Block.b(Block.java:366)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.IBlockData.b(SourceFile:267)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.WorldServer.a(WorldServer.java:496)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.ChunkProviderServer.lambda$9(ChunkProviderServer.java:427)
    [14:20:57] [Server thread/WARN]:        at org.bukkit.craftbukkit.libs.it.unimi.dsi.fastutil.longs.Long2ObjectLinkedOpenHashMap$1.forEach(Long2ObjectLinkedOpenHashMap.java:1661)
    [14:20:57] [Server thread/WARN]:        at com.google.common.collect.Iterables$UnmodifiableIterable.forEach(Iterables.java:105)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.ChunkProviderServer.tickChunks(ChunkProviderServer.java:369)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.ChunkProviderServer.tick(ChunkProviderServer.java:339)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.WorldServer.doTick(WorldServer.java:308)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.MinecraftServer.b(MinecraftServer.java:1082)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.DedicatedServer.b(DedicatedServer.java:406)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.MinecraftServer.a(MinecraftServer.java:984)
    [14:20:57] [Server thread/WARN]:        at net.minecraft.server.v1_15_R1.MinecraftServer.run(MinecraftServer.java:824)
    [14:20:57] [Server thread/WARN]:        at java.lang.Thread.run(Unknown Source)
     
  7. Don't tihnk you will have much luck with it,this bug happend(bit differently) with vanilla generation where big sides of a cave would be completly dark even when lava is next to them
     
  8. I think its just the chunk not being updated after,it get's generated your way but it stops there,(ex the gravel roof on caves dont get updated till someone breaks or does something to it)
     
  9. I don't think that's a bug though, you can fix that by refreshing lava with a block populator, which is what I'm doing right now. This includes sand and gravel.
    What OP is talking about looks much more like a bug than that imo.
     
  10. It feels like the problem comes down to incorrect coordinates passed to the physics.
     
  11. #13 Hex_27, Feb 23, 2020
    Last edited: Feb 23, 2020