NucleoidMC / fantasy

Library to support creating dimensions at runtime
GNU Lesser General Public License v3.0
95 stars 26 forks source link

ServerboundMovePlayerPacket error when using changeDimension to fantasy dimensions, chunks do not generate #39

Open filloax opened 9 months ago

filloax commented 9 months ago

As title. Trying the lib by using a simple command that creates a temporary dimension and moves the player there, but I just get the classic pre-loading empty world on the client side as chunks never generate, with the error at the bottom of the issue post in the log.

The command code (in Kotlin, mojmap, fabric) is this:

object Commands {
    val worldConfig = { server: MinecraftServer ->
        RuntimeWorldConfig()
            .setDimensionType(BuiltinDimensionTypes.OVERWORLD)
            .setDifficulty(Difficulty.HARD)
            .setGameRule(GameRules.RULE_DAYLIGHT, false)
            .setGenerator(server.overworld().chunkSource.generator)
            .setSeed(1234L)
    }

    fun register(dispatcher: CommandDispatcher<CommandSourceStack>, registryAccess: CommandBuildContext, environment: Commands.CommandSelection) {
        //tmpdim: move to temporary dim
        dispatcher.register(literal("tmpdim").requires{ it.hasPermission(2) }
            .executes { ctx ->
                val fantasy = Fantasy.get(ctx.source.server)
                val worldHandle:= fantasy.openTemporaryWorld(worldConfig(ctx.source.server))
                val level = worldHandle.asWorld()
                ctx.source.playerOrException.changeDimension(level)

                1
            }
        )
    }
}

Am I doing something wrong?

[20:54:42] [Server thread/ERROR] (Minecraft) Failed to handle packet net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot@380fc290, suppressing error
 java.lang.NullPointerException: Cannot invoke "it.unimi.dsi.fastutil.objects.ObjectSet.remove(Object)" because "objectSet" is null
    at net.minecraft.server.level.DistanceManager.removePlayer(DistanceManager.java:225) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.level.ChunkMap.move(ChunkMap.java:1093) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.level.ServerChunkCache.move(ServerChunkCache.java:477) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.network.ServerGamePacketListenerImpl.handleMovePlayer(ServerGamePacketListenerImpl.java:928) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.handle(ServerboundMovePlayerPacket.java:31) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$PosRot.handle(ServerboundMovePlayerPacket.java:90) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.network.protocol.PacketUtils.method_11072(PacketUtils.java:34) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.TickTask.run(TickTask.java:20) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:143) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:797) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:189) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:114) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:780) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:774) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.util.thread.BlockableEventLoop.runAllTasks(BlockableEventLoop.java:103) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:760) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:696) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:252) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at java.lang.Thread.run(Thread.java:833) ~[?:?]
[20:54:42] [Server thread/ERROR] (Minecraft) Failed to handle packet net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos@5f723ccf, suppressing error
 java.lang.NullPointerException: Cannot invoke "it.unimi.dsi.fastutil.objects.ObjectSet.remove(Object)" because "objectSet" is null
    at net.minecraft.server.level.DistanceManager.removePlayer(DistanceManager.java:225) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.level.ChunkMap.move(ChunkMap.java:1093) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.level.ServerChunkCache.move(ServerChunkCache.java:477) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.network.ServerGamePacketListenerImpl.handleMovePlayer(ServerGamePacketListenerImpl.java:928) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket.handle(ServerboundMovePlayerPacket.java:31) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.network.protocol.game.ServerboundMovePlayerPacket$Pos.handle(ServerboundMovePlayerPacket.java:68) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.network.protocol.PacketUtils.method_11072(PacketUtils.java:34) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.TickTask.run(TickTask.java:20) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.util.thread.BlockableEventLoop.doRunTask(BlockableEventLoop.java:143) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.util.thread.ReentrantBlockableEventLoop.doRunTask(ReentrantBlockableEventLoop.java:24) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:797) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.doRunTask(MinecraftServer.java:189) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.util.thread.BlockableEventLoop.pollTask(BlockableEventLoop.java:114) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.pollTaskInternal(MinecraftServer.java:780) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.pollTask(MinecraftServer.java:774) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.util.thread.BlockableEventLoop.runAllTasks(BlockableEventLoop.java:103) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.waitUntilNextTick(MinecraftServer.java:760) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.runServer(MinecraftServer.java:696) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:252) ~[minecraft-common-c4cba8cea8-1.20.2-loom.mappings.1_20_2.layered+hash.405084424-v2.jar:?]
    at java.lang.Thread.run(Thread.java:833) ~[?:?]
filloax commented 9 months ago

For context, this is on 1.20.2, fabric ver 0.91.1+1.20.2, fantasy ver 0.4.11+1.20-rc1

Libreh commented 7 months ago

I can re-produce this as well.

Earthcomputer commented 4 months ago

For custom dimensions, you are supposed to use FabricDimensions.teleport or ServerPlayer.teleportTo instead of ServerPlayer.changeDimension.

Libreh commented 1 month ago

For custom dimensions, you are supposed to use FabricDimensions.teleport or ServerPlayer.teleportTo instead of ServerPlayer.changeDimension.

I forgot about this issue but yeah this fixed it for me in case anyone was wondering what the fix was/if it would work.

CaelTheColher commented 2 weeks ago

I'm having the same issue on 1.21 while using ServerPlayer.teleportTo, and Fabric Dimensions no longer exists in this version

edit: I think its an issue with trying to teleport the player as soon as the dimension is created? Creating the dimension earlier (in my case, on ServerLifecycleEvents.SERVER_STARTED) seems to stop this from happening.

CaelTheColher commented 2 weeks ago

Ok I'm back to having no clue. I made a command to create a dimension and another to teleport to it and that seems to work fine but then it breaks the original dimension created on server start? Even though they are two separate dimensions

Earthcomputer commented 2 weeks ago

@CaelTheColher in 1.21, FabricDimensions.teleport has been removed, you can just use Entity.teleportTo.

CaelTheColher commented 2 weeks ago

@CaelTheColher in 1.21, FabricDimensions.teleport has been removed, you can just use Entity.teleportTo.

I am already using teleportTo, but still getting the same error as op

CaelTheColher commented 2 weeks ago

I found the problem, I was teleporting on the ServerPlayConnectionEvents.JOIN event, but that is too early and it can mess things up

Libreh commented 2 weeks ago

I found the problem, I was teleporting on the ServerPlayConnectionEvents.JOIN event, but that is too early and it can mess things up

What I like to do is have a playerJoined UUID list and then teleport the player on next server tick, if you want compatibility with VMP you can also make sure the notInAnyWorld field is false before running anything.