Solved Block.setType throws error in onChunkLoad event

Discussion in 'Plugin Development' started by MS27, May 6, 2021.

  1. Offline

    MS27

    i want to replace all grass blocks to gold block.
    this is my code:

    Code:
    @EventHandler
        public void onChunkLoaded(ChunkLoadEvent e)
        {
            int X = e.getChunk().getX() * 16;
            int Z = e.getChunk().getZ() * 16;
    
            for (int x = 0; x < 16; x++) // whole chunk
            {
                for (int z = 0; z < 16; z++) // whole chunk
                {
                    for (int y = 0; y < 80; y++) // any level between 1 - 40
                    {
                        if (e.getChunk().getWorld().getBlockAt(X+x, y, Z+z).getType().equals(Material.GRASS_BLOCK))
                        {
                            try {
                                e.getChunk().getWorld().getBlockAt(X + x, y, Z + z).setType(Material.GOLD_BLOCK);
                            }
                            catch (Exception exception){
                                Bukkit.getServer().getConsoleSender().sendMessage(exception.getMessage());
                            }
                        }
                    }
                }
            }
        }
    it throws at line e.getChunk().getWorld().getBlockAt(X + x, y, Z + z).setType(Material.GOLD_BLOCK):
    Code:
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              com.ms27.replacer.events.ReplacerEvents.onChunkLoaded(ReplacerEvents.java:24)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              java.base@11.0.11/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              java.base@11.0.11/java.lang.reflect.Method.invoke(Unknown Source)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.Chunk.loadCallback(Chunk.java:520)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.PlayerChunk.lambda$13(PlayerChunk.java:384)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.PlayerChunk$$Lambda$3521/0x0000000100ad1840.run(Unknown Source)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.PlayerChunkMap$CallbackExecutor.run(PlayerChunkMap.java:98)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.ChunkProviderServer$a.executeNext(ChunkProviderServer.java:567)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(SourceFile:127)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:121)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.World.getChunkAt(World.java:214)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.IWorldReader.getChunkAt(SourceFile:128)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.World.getChunkAt(World.java:209)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.World.getType(World.java:517)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.World.a(World.java:446)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.World.applyPhysics(World.java:409)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.WorldServer.update(WorldServer.java:1742)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.World.notifyAndUpdatePhysics(World.java:338)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.World.a(World.java:310)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//net.minecraft.server.v1_16_R3.World.setTypeAndData(World.java:225)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setTypeAndData(CraftBlock.java:199)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setBlockData(CraftBlock.java:184)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setType(CraftBlock.java:173)
    [03:46:05] [Spigot Watchdog Thread/ERROR]:              app//org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setType(CraftBlock.java:167)
    
    
    i also tried with chunk.setBlock but no differense.
    Can anyone help me? Thanks.
     
    Last edited by a moderator: May 6, 2021
  2. Online

    timtower Administrator Administrator Moderator

    @MS27 Why aren't you just printing the stacktrace instead?
     
    MS27 likes this.
  3. Offline

    MS27

    I think the execption is getting ignored in try, catch. and it doesn't work.
    i copied that error from my server logs
     
  4. Offline

    Kars

    You have to confirm you are getting the correct blocks because judging by the way you determine coordinates, i'm not sure that will work.
     
  5. Offline

    MS27

    So i changed my code to:
    Code:
        @EventHandler
        public void onChunkLoaded(ChunkLoadEvent e)
        {
    
            for (int x = 0; x < 16; x++) // whole chunk
            {
                for (int z = 0; z < 16; z++) // whole chunk
                {
                    for (int y = 0; y < 80; y++) // any level between 1 - 80
                    {
                        if (e.getChunk().getBlock(x, y, z).getType().equals(Material.GRASS_BLOCK))
                        {
                            e.getChunk().getBlock(x ,y, z).setType(Material.GOLD_BLOCK);
                        }
                    }
                }
            }
        }
    and the error is:
    ERROR (open)

    [09:53:47] [Worker-Main-2/ERROR]: Caught exception in thread Thread[Worker-Main-2,5,main]
    java.lang.StackOverflowError: null
    at java.util.Collections$UnmodifiableMap.entrySet(Unknown Source) ~[?:?]
    at java.util.HashMap.putMapEntries(Unknown Source) ~[?:?]
    at java.util.HashMap.putAll(Unknown Source) ~[?:?]
    at net.minecraft.server.v1_16_R3.Chunk.a(Chunk.java:737) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.Chunk.<init>(Chunk.java:142) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.PlayerChunkMap.lambda$33(PlayerChunkMap.java:595) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at com.mojang.datafixers.util.Either.lambda$mapLeft$0(Either.java:162) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at com.mojang.datafixers.util.Either$Left.map(Either.java:38) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at com.mojang.datafixers.util.Either.mapLeft(Either.java:162) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.PlayerChunkMap.lambda$31(PlayerChunkMap.java:588) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at java.util.concurrent.CompletableFuture$UniApply.tryFire(Unknown Source) ~[?:?]
    at java.util.concurrent.CompletableFuture$Completion.run(Unknown Source) ~[?:?]
    at net.minecraft.server.v1_16_R3.ChunkTaskQueueSorter.b(SourceFile:58) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeTask(SourceFile:144) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.ChunkProviderServer$a.executeTask(ChunkProviderServer.java:553) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.executeNext(SourceFile:118) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.ChunkProviderServer$a.executeNext(ChunkProviderServer.java:564) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:121) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getChunkAt(World.java:214) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.IWorldReader.getChunkAt(SourceFile:128) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getChunkAt(World.java:209) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getType(World.java:517) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.a(World.java:446) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.applyPhysics(World.java:413) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.WorldServer.update(WorldServer.java:1742) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.notifyAndUpdatePhysics(World.java:338) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.a(World.java:310) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.setTypeAndData(World.java:225) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setTypeAndData(CraftBlock.java:199) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setBlockData(CraftBlock.java:184) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setType(CraftBlock.java:173) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setType(CraftBlock.java:167) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at com.ms27.replacer.events.ReplacerEvents.onChunkLoaded(ReplacerEvents.java:23) ~[?:?]
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.Chunk.loadCallback(Chunk.java:520) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.PlayerChunk.lambda$13(PlayerChunk.java:384) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.PlayerChunkMap$CallbackExecutor.run(PlayerChunkMap.java:98) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.ChunkProviderServer$a.executeNext(ChunkProviderServer.java:567) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:121) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getChunkAt(World.java:214) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.IWorldReader.getChunkAt(SourceFile:128) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getChunkAt(World.java:209) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getType(World.java:517) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.a(World.java:446) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.applyPhysics(World.java:410) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.WorldServer.update(WorldServer.java:1742) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.notifyAndUpdatePhysics(World.java:338) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.a(World.java:310) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.setTypeAndData(World.java:225) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setTypeAndData(CraftBlock.java:199) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setBlockData(CraftBlock.java:184) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setType(CraftBlock.java:173) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setType(CraftBlock.java:167) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at com.ms27.replacer.events.ReplacerEvents.onChunkLoaded(ReplacerEvents.java:23) ~[?:?]
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.Chunk.loadCallback(Chunk.java:520) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.PlayerChunk.lambda$13(PlayerChunk.java:384) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.PlayerChunkMap$CallbackExecutor.run(PlayerChunkMap.java:98) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.ChunkProviderServer$a.executeNext(ChunkProviderServer.java:567) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.IAsyncTaskHandler.awaitTasks(SourceFile:127) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:121) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getChunkAt(World.java:214) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.IWorldReader.getChunkAt(SourceFile:128) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getChunkAt(World.java:209) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.getType(World.java:517) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.a(World.java:446) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.applyPhysics(World.java:410) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.WorldServer.update(WorldServer.java:1742) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.notifyAndUpdatePhysics(World.java:338) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.a(World.java:310) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.World.setTypeAndData(World.java:225) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setTypeAndData(CraftBlock.java:199) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setBlockData(CraftBlock.java:184) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setType(CraftBlock.java:173) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.craftbukkit.v1_16_R3.block.CraftBlock.setType(CraftBlock.java:167) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at com.ms27.replacer.events.ReplacerEvents.onChunkLoaded(ReplacerEvents.java:23) ~[?:?]
    at jdk.internal.reflect.GeneratedMethodAccessor2.invoke(Unknown Source) ~[?:?]
    at jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) ~[?:?]
    at java.lang.reflect.Method.invoke(Unknown Source) ~[?:?]
    at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:315) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:70) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:589) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:576) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    at net.minecraft.server.v1_16_R3.Chunk.loadCallback(Chunk.java:520) ~[spigot_server-1.16.5.jar:2991-Spigot-018b9a0-f3f3094]
    and more...
     
  6. Offline

    Kars

    @MS27 you are not getting the blocks correctly (i recon), which makes getType (or setType) throw the nullpointer.

    To confirm which is null, save chunk and block to variables and try/catch around further operations to print and see which is null.
     
    MS27 likes this.
  7. Offline

    MS27

    Thank you I'll try and let you know the result
     
  8. Offline

    davidclue

    @MS27 You can use this method to get the block in the chunk instead. Also if you are only changing grass blocks it might be a smarter idea to check if the chunk even contains grass blocks before iterating over it entirely. Also, why not just use a block populator or custom world generator instead?
     
    MS27 likes this.
  9. Offline

    MS27

    I hadn't heard about them until now. Thanks

    I learned a bit about ChunkGenerator and custom worlds.
    But i need to generate overworld chunk data in my custom world.
    then replace grass blocks to gold blocks.
    how can i do that (generate overworld)?
    Thanks for your help <3

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    EDIT2: I searched google and bukkit forum a lot but i didn't find anything :( i think it's impossible in bukkit
     
    Last edited: May 8, 2021
  10. Offline

    davidclue

    @MS27 Yes it is impossible to create a world generator with vanilla attributes without completely recoding the entire vanilla world generator. What you can do is add a block populator to the list of vanilla populators, and within that block populator change all grass blocks to gold blocks in the chunk.
     
    MS27 likes this.
  11. Offline

    MS27

    Thank you very much. it worked!

    This is my populate method in my Populator class
    Code:
        public void populate(World world, Random random, Chunk chunk) {
            for (int X = 0; X < 16; X++){
                for (int Y = 0; Y < 80; Y++){
                    for (int Z = 0; Z < 16; Z++){
                        Block block = chunk.getBlock(X, Y, Z);
    
                        if (block.getType().equals(Material.GRASS_BLOCK)){
                            block.setType(Material.GLASS);
                        }
                    }
                }
            }
        }
    Results :)
    upload_2021-5-9_11-11-47.png

    Thank you. Solved

    Oh sorry i forgot to send the results.
    The null pointer exception was fixed by your solution
    btw, there were some errors on block.setType (i think bcs of memory) and the server gets crashed.
    so i used block populator.
    thank you anyway
     
    Last edited: May 9, 2021
    Kars and davidclue like this.
  12. Offline

    davidclue

    @MS27 One last thing to make it faster, you only need to iterate between the y level where grass blocks spawn so you could just loop between y 60 - y 256 and just break out of the loop when you hit an air block so it would look like this.
    Code:
    public void populate(World world, Random random, Chunk chunk) {
        for (int X = 0; X < 16; X++){
            label:
            for (int Z = 0; Z < 16; Z++){
                for (int Y = 60; Y < 256; Y++){
                    Block block = chunk.getBlock(X, Y, Z);
    
                    if (block.getType().equals(Material.GRASS_BLOCK)) {
                        block.setType(Material.GLASS);
                        continue label;
                    } else if (block.getType().isAir()) continue label;
                }
            }
        }
    }
     
    MS27 likes this.

Share This Page