Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Issue with breaking blocks in a chunk (Unloaded chunk at x, y, z) #59

Open
Fisher2911 opened this issue Sep 9, 2023 · 3 comments
Open

Comments

@Fisher2911
Copy link

Basically, I'm trying to create an instance for a player in the PlayerLoginEvent, but it seems like when the player breaks a block, it throws an error in console and doesn't drop an item. This same code was working with regular Minestom.

Player login listener
CustomChunkGenerator
Block I'm trying to break that doesn't drop anything
createDefaultHandler method - this is where the error occurs
Version:

implementation("dev.hollowcube:minestom-ce:010fe985bb")

Error:

java.lang.NullPointerException: Unloaded chunk at -144,-64,112
	at net.minestom.server.instance.Instance.getBlock(Instance.java:596)
	at net.minestom.server.instance.block.Block$Getter.getBlock(Block.java:218)
	at net.minestom.server.instance.block.Block$Getter.getBlock(Block.java:226)
	at io.github.fisher2911.myserver.world.BlockHandlersKt$createDefaultHandler$3.onDestroy(BlockHandlers.kt:32)
	at net.minestom.server.instance.DynamicChunk.setBlock(DynamicChunk.java:111)
	at net.minestom.server.instance.Chunk.setBlock(Chunk.java:91)
	at net.minestom.server.instance.AnvilLoader.loadBlockEntities(AnvilLoader.java:300)
	at net.minestom.server.instance.AnvilLoader.loadMCA(AnvilLoader.java:129)
	at net.minestom.server.instance.AnvilLoader.loadChunk(AnvilLoader.java:87)
	at net.minestom.server.instance.InstanceContainer.lambda$retrieveChunk$6(InstanceContainer.java:294)
	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.run(CompletableFuture.java:1804)
	at java.base/java.util.concurrent.CompletableFuture$AsyncRun.exec(CompletableFuture.java:1796)
	at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
	at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
	at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
	at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
	at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
@Fisher2911
Copy link
Author

It only seems to be happening when loading chunks from a file

@Fisher2911
Copy link
Author

The issue seems to be that the chunk is cached after the chunk is generated

@Fisher2911
Copy link
Author

Fisher2911 commented Sep 12, 2023

If you want to reproduce, this causes it:

MinecraftServer.getBlockManager().registerHandler("minecraft:stone") {
    object : BlockHandler {
        override fun getNamespaceId(): NamespaceID {
            return NamespaceID.from("minecraft:stone")
        }
        override fun onDestroy(destroy: BlockHandler.Destroy) {
            println("destroyed stone")
            val position = destroy.blockPosition
            destroy.instance.getBlock(position)
        }
    }
}

instanceContainer.chunkLoader = AnvilLoader("worlds/${player.uuid}")
instanceContainer.setGenerator { unit: GenerationUnit -> unit.modifier().fillHeight(0, 40, Block.STONE)

private fun onPlayerLogout(
    globalEventHandler: GlobalEventHandler
) {
    globalEventHandler.addListener(
        PlayerDisconnectEvent::class.java
    ) { event: PlayerDisconnectEvent ->
        val player: Player = event.player
        player.instance.saveChunksToStorage()
    }
}

Steps:

  1. Join the server
  2. Leave
  3. Join back

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant