PaperMC / Paper

The most widely used, high performance Minecraft server that aims to fix gameplay and mechanics inconsistencies
https://papermc.io/
Other
9.73k stars 2.27k forks source link

using RegistryKey.STRUCTURE as a brigadier argument makes clients unable to connect #10991

Closed Hinterhaeltiger closed 2 months ago

Hinterhaeltiger commented 3 months ago

Stack trace

[15:29:09 WARN]: [io.netty.channel.DefaultChannelPipeline] An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.channel.StacklessClosedChannelException: null
    at io.netty.channel.AbstractChannel$AbstractUnsafe.write(Object, ChannelPromise)(Unknown Source) ~[netty-transport-4.1.97.Final.jar:4.1.97.Final]

Plugin and Datapack List

Spark, My own plugin

Actions to reproduce (if known)

Register a command with an argument of the Registry.STRUCTURE type:

commands.register(Commands.literal("structureargumentcommand")
                            .then(
                                    Commands.argument("structure", ArgumentTypes.resource(RegistryKey.STRUCTURE))
                                            .executes(ctx -> {
                                                ctx.getSource().getSender().sendRichMessage(ctx.getArgument("structure", Structure.class).getKey().toString());
                                                return Command.SINGLE_SUCCESS;
                                            })
                            ).build());

then try to join the server. You will get an Exception that immediately reaches the end of the pipeline. Also note that RegistryKey.STRUCTURE seems to be a duplicate of RegistryKey.STRUCTURETYPE (which works just fine) nonetheless. The client will display "Network Protocol Error". Client Log:

[15:37:53] [Render thread/ERROR]: Failed to handle packet net.minecraft.class_2641@5ddae6a6
java.lang.IllegalStateException: Registry minecraft:worldgen/structure not found
    at net.minecraft.class_7225$class_7874.method_46763(class_7225.java:107) ~[client-intermediary.jar:?]
    at java.base/java.util.Optional.orElseThrow(Optional.java:403) ~[?:?]
    at net.minecraft.class_7225$class_7874.method_46762(class_7225.java:107) ~[client-intermediary.jar:?]
    at net.minecraft.class_7733.<init>(class_7733.java:49) ~[client-intermediary.jar:?]
    at net.minecraft.class_7733$class_7734$class_7735.method_45617(class_7733.java:127) ~[client-intermediary.jar:?]
    at net.minecraft.class_7733$class_7734$class_7735.method_41730(class_7733.java:118) ~[client-intermediary.jar:?]
    at net.minecraft.class_2641$class_7232.method_42070(class_2641.java:170) ~[client-intermediary.jar:?]
    at net.minecraft.class_2641$class_7234.method_42077(class_2641.java:336) ~[client-intermediary.jar:?]
    at net.minecraft.class_2641$class_7234.method_42077(class_2641.java:348) ~[client-intermediary.jar:?]
    at net.minecraft.class_2641$class_7234.method_42077(class_2641.java:348) ~[client-intermediary.jar:?]
    at net.minecraft.class_2641.method_11403(class_2641.java:266) ~[client-intermediary.jar:?]
    at net.minecraft.class_634.method_11145(class_634.java:1453) ~[client-intermediary.jar:?]
    at net.minecraft.class_2641.method_11404(class_2641.java:262) ~[client-intermediary.jar:?]
    at net.minecraft.class_2641.method_11054(class_2641.java:39) ~[client-intermediary.jar:?]
    at net.minecraft.class_2600.method_11072(class_2600.java:25) ~[client-intermediary.jar:?]
    at net.minecraft.class_1255.method_18859(class_1255.java:162) [client-intermediary.jar:?]
    at net.minecraft.class_4093.method_18859(class_4093.java:23) [client-intermediary.jar:?]
    at net.minecraft.class_1255.method_16075(class_1255.java:136) [client-intermediary.jar:?]
    at net.minecraft.class_1255.method_5383(class_1255.java:121) [client-intermediary.jar:?]
    at net.minecraft.class_310.method_1523(class_310.java:1275) [client-intermediary.jar:?]
    at net.minecraft.class_310.method_1514(class_310.java:888) [client-intermediary.jar:?]
    at net.minecraft.client.main.Main.main(Main.java:265) [client-intermediary.jar:?]
    at net.fabricmc.loader.impl.game.minecraft.MinecraftGameProvider.launch(MinecraftGameProvider.java:470) [fabric-loader-0.15.11.jar:?]
    at net.fabricmc.loader.impl.launch.knot.Knot.launch(Knot.java:74) [fabric-loader-0.15.11.jar:?]
    at net.fabricmc.loader.impl.launch.knot.KnotClient.main(KnotClient.java:23) [fabric-loader-0.15.11.jar:?]
    at org.prismlauncher.launcher.impl.StandardLauncher.launch(StandardLauncher.java:100) [NewLaunch.jar:?]
    at org.prismlauncher.EntryPoint.listen(EntryPoint.java:129) [NewLaunch.jar:?]
    at org.prismlauncher.EntryPoint.main(EntryPoint.java:70) [NewLaunch.jar:?]

Paper version

Paper version 1.20.6-147-ver/1.20.6@e41d44f (2024-06-17T19:24:35Z) (Implementing API version 1.20.6-R0.1-SNAPSHOT)

Other

Really weird issue, maybe it just is not meant to be used as an argument type

Hinterhaeltiger commented 3 months ago

I should maybe add that I'm registering this using the plugin Bootstrapper. Dunno if that has an impact on that though

lynxplay commented 2 months ago

Replicable, the server does not sync said registry with the client, as such the client cannot parse such an argument. This won't be fixable, however we might be able to pretty up the error.

(you can fix this rn by switching to resourceKey instead of resource)

lynxplay commented 2 months ago

Opening this in a new issue, as it is only a documentation issue/error handling.

For people looking at this, see https://jd.papermc.io/paper/1.21/io/papermc/paper/command/brigadier/argument/ArgumentTypes.html#resourceKey(io.papermc.paper.registry.RegistryKey) for most usecases.