Uploaded image for project: 'Spigot'
  1. Spigot
  2. SPIGOT-4578

Using Block.getChunk() inside BlockPhysicsEvent causes errors due to chunkgen

XMLWordPrintable

    • This server is running CraftBukkit version git-Spigot-518206a-c4a67ee (MC: 1.13.2) (Implementing API version 1.13.2-R0.1-SNAPSHOT)
    • Traincarts (since resolved)
    • Yes

      A bug found by the users of my plugin that is quite interesting. During chunk generation, block physics events fire. Calling Block.getChunk() in that handler that caused a very confusing error:

      [20:31:12] [Server thread/ERROR]: Could not pass event BlockPhysicsEvent to Train_Carts v1.13.2-v1
      org.bukkit.event.EventException: null
          at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:309) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.plugin.RegisteredListener.callEvent(RegisteredListener.java:62) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.plugin.SimplePluginManager.fireEvent(SimplePluginManager.java:500) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.plugin.SimplePluginManager.callEvent(SimplePluginManager.java:485) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.event.CraftEventFactory.callBlockPhysicsEvent(CraftEventFactory.java:1239) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.BlockPlant.updateState(BlockPlant.java:18) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.BlockTallPlant.updateState(BlockTallPlant.java:17) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.IBlockData.updateState(SourceFile:297) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.DefinedStructure.a(SourceFile:319) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.VoxelShapeDiscrete.a(SourceFile:305) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.VoxelShapeDiscrete.a(SourceFile:282) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.DefinedStructure.a(SourceFile:310) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.DefinedStructure.a(SourceFile:183) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.DefinedStructurePiece.a(SourceFile:59) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.WorldGenShipwreck$a.a(SourceFile:139) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.StructureStart.a(SourceFile:62) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.StructureGenerator.generate(StructureGenerator.java:48) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.WorldGenDecoratorEmpty.a(SourceFile:16) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.WorldGenDecoratorEmpty.a(SourceFile:13) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.WorldGenFeatureComposite.a(SourceFile:27) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.BiomeBase.a(SourceFile:504) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkGeneratorAbstract.addDecorations(ChunkGeneratorAbstract.java:97) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.generator.NormalChunkGenerator.addDecorations(NormalChunkGenerator.java:59) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkTaskDecorate.a(SourceFile:12) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkTask.a(SourceFile:35) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkStatus.a(SourceFile:95) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkTaskScheduler.a(ChunkTaskScheduler.java:75) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkTaskScheduler.a(ChunkTaskScheduler.java:1) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:147) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:602) ~[?:1.8.0_151]
          at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577) ~[?:1.8.0_151]
          at java.util.concurrent.CompletableFuture$Completion.run(CompletableFuture.java:442) ~[?:1.8.0_151]
          at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:260) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at java.util.concurrent.CompletableFuture$UniCompletion.claim(CompletableFuture.java:529) ~[?:1.8.0_151]
          at java.util.concurrent.CompletableFuture.uniApply(CompletableFuture.java:599) ~[?:1.8.0_151]
          at java.util.concurrent.CompletableFuture$UniApply.tryFire(CompletableFuture.java:577) ~[?:1.8.0_151]
          at java.util.concurrent.CompletableFuture.uniApplyStage(CompletableFuture.java:617) ~[?:1.8.0_151]
          at java.util.concurrent.CompletableFuture.thenApplyAsync(CompletableFuture.java:1993) ~[?:1.8.0_151]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:147) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at java.util.Map.computeIfAbsent(Map.java:957) ~[?:1.8.0_151]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:137) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:143) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkStatus.a(SourceFile:105) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkStatus.a(SourceFile:22) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:143) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at java.util.Map.computeIfAbsent(Map.java:957) ~[?:1.8.0_151]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:137) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:143) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkStatus.a(SourceFile:105) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkStatus.a(SourceFile:22) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:143) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at java.util.Map.computeIfAbsent(Map.java:957) ~[?:1.8.0_151]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:137) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:143) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkStatus.a(SourceFile:105) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkStatus.a(SourceFile:22) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:143) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at java.util.Map.computeIfAbsent(Map.java:957) ~[?:1.8.0_151]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:137) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler$a.a(SourceFile:115) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.Scheduler.a(SourceFile:61) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1590) [?:1.8.0_151]
          at com.google.common.util.concurrent.MoreExecutors$DirectExecutorService.execute(MoreExecutors.java:260) [my.jar:git-Spigot-f56e2e7-4385562]
          at java.util.concurrent.CompletableFuture.asyncSupplyStage(CompletableFuture.java:1604) [?:1.8.0_151]
          at java.util.concurrent.CompletableFuture.supplyAsync(CompletableFuture.java:1830) [?:1.8.0_151]
          at net.minecraft.server.v1_13_R2.Scheduler.a(SourceFile:62) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.SchedulerBatch.a(SourceFile:39) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:109) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.PlayerChunk.a(SourceFile:87) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.PlayerChunkMap.flush(PlayerChunkMap.java:135) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.WorldServer.doTick(WorldServer.java:291) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.MinecraftServer.b(MinecraftServer.java:952) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.DedicatedServer.b(DedicatedServer.java:417) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.MinecraftServer.a(MinecraftServer.java:831) [my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.MinecraftServer.run(MinecraftServer.java:729) [my.jar:git-Spigot-f56e2e7-4385562]
          at java.lang.Thread.run(Thread.java:748) [?:1.8.0_151]
      Caused by: net.minecraft.server.v1_13_R2.ReportedException: Exception generating new chunk
          at net.minecraft.server.v1_13_R2.ChunkProviderServer.a(ChunkProviderServer.java:172) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:114) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.CraftWorld.getChunkAt(CraftWorld.java:144) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.CraftWorld.getChunkAt(CraftWorld.java:148) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock.getChunk(CraftBlock.java:104) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at com.bergerkiller.bukkit.tc.TCListener.onBlockPhysics(TCListener.java:858) ~[TrainCarts-1.13.2-v1.jar:?]
          at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source) ~[?:?]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]
          at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]
          at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[my.jar:git-Spigot-f56e2e7-4385562]
          ... 75 more
      Caused by: java.lang.RuntimeException: Batch already started.
          at net.minecraft.server.v1_13_R2.SchedulerBatch.b(SourceFile:27) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:108) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.CraftWorld.getChunkAt(CraftWorld.java:144) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.CraftWorld.getChunkAt(CraftWorld.java:148) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock.getChunk(CraftBlock.java:104) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at com.bergerkiller.bukkit.tc.TCListener.onBlockPhysics(TCListener.java:858) ~[TrainCarts-1.13.2-v1.jar:?]
          at sun.reflect.GeneratedMethodAccessor101.invoke(Unknown Source) ~[?:?]
          at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_151]
          at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_151]
          at org.bukkit.plugin.java.JavaPluginLoader$1.execute(JavaPluginLoader.java:305) ~[my.jar:git-Spigot-f56e2e7-4385562]
          ... 75 more
      

      Relevant part:

          at net.minecraft.server.v1_13_R2.SchedulerBatch.b(SourceFile:27) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at net.minecraft.server.v1_13_R2.ChunkProviderServer.getChunkAt(ChunkProviderServer.java:108) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.CraftWorld.getChunkAt(CraftWorld.java:144) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.CraftWorld.getChunkAt(CraftWorld.java:148) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at org.bukkit.craftbukkit.v1_13_R2.block.CraftBlock.getChunk(CraftBlock.java:104) ~[my.jar:git-Spigot-f56e2e7-4385562]
          at com.bergerkiller.bukkit.tc.TCListener.onBlockPhysics(TCListener.java:858) ~[TrainCarts-1.13.2-v1.jar:?]
      

      Further digging into it, I found out that this has to do with the fact the chunk is being populated (trees are placed, etc.) and that during this, the chunk can not be obtained using getChunk(), as it is not yet available.

      I managed to fix the error on my end by not calling getChunk() inside the block physics event handler, as there was another way to do what it was using getChunk() for.

      One of my users did report that this started happening once players wander into the newly introduced ocean biomes, but I can not confirm that. My guess then would be that block physics events are (incorrectly?) fired during the populating of certain ocean biome structures/plants.

      For me it's fixed, but I find it quite likely that there will be other plugins that call getChunk() inside that event without thinking about it. Since this bug is not documented, I think it's worth posting a report about so someone more knowledgable in the chunk generation logic can have a look at it.

            Unassigned Unassigned
            bergerkiller Irmo van den Berge
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: