GeyserMC / Geyser

A bridge/proxy allowing you to connect to Minecraft: Java Edition servers with Minecraft: Bedrock Edition.
https://geysermc.org
MIT License
4.73k stars 682 forks source link

Error translating block mappings when breaking Polymer custom blocks represented by player heads #4555

Closed eclipseisoffline closed 7 months ago

eclipseisoffline commented 7 months ago

Describe the bug

Hello, I'm using a Polymer mod (Universal Shops) on a private server with Geyser. This mod uses player heads to represent custom blocks, which seem a bit buggy when on Bedrock, especially when trying to break them.

Notably, when starting to break a block in survival mode (on a Bedrock client), this error pops up in the server logs:

[13:46:17] [Geyser player thread-5-1/ERROR]: Could not translate packet PlayerActionPacket
java.lang.NullPointerException: Cannot invoke "org.geysermc.geyser.registry.type.BlockMapping.getJavaBlockId()" because "blockMapping" is null
        at org.geysermc.geyser.session.cache.TagCache.isShearsEffective(TagCache.java:195) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.util.BlockUtils.getBreakTime(BlockUtils.java:138) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.util.BlockUtils.getSessionBreakTime(BlockUtils.java:180) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.translator.protocol.bedrock.entity.player.BedrockActionTranslator.translate(BedrockActionTranslator.java:166) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.translator.protocol.bedrock.entity.player.BedrockActionTranslator.translate(BedrockActionTranslator.java:61) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.registry.PacketTranslatorRegistry.translate0(PacketTranslatorRegistry.java:89) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.registry.PacketTranslatorRegistry.lambda$translate$0(PacketTranslatorRegistry.java:69) ~[Geyser-Fabric.jar:?]
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) ~[netty-common-4.1.97.Final.jar:?]
        at io.netty.channel.DefaultEventLoop.run(DefaultEventLoop.java:54) ~[netty-transport-4.1.97.Final.jar:?]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.97.Final.jar:?]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.97.Final.jar:?]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.97.Final.jar:?]
        at java.lang.Thread.run(Thread.java:840) ~[?:?]

And another error pops up when finishing breaking a block:

[13:46:19] [Geyser player thread-5-1/ERROR]: Could not translate packet ClientboundBlockDestructionPacket
java.lang.NullPointerException: Cannot invoke "org.geysermc.geyser.registry.type.BlockMapping.getJavaBlockId()" because "blockMapping" is null
        at org.geysermc.geyser.session.cache.TagCache.isShearsEffective(TagCache.java:195) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.util.BlockUtils.getBreakTime(BlockUtils.java:138) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.translator.protocol.java.level.JavaBlockDestructionTranslator.translate(JavaBlockDestructionTranslator.java:45) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.translator.protocol.java.level.JavaBlockDestructionTranslator.translate(JavaBlockDestructionTranslator.java:39) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.registry.PacketTranslatorRegistry.translate0(PacketTranslatorRegistry.java:89) ~[Geyser-Fabric.jar:?]
        at org.geysermc.geyser.registry.PacketTranslatorRegistry.lambda$translate$0(PacketTranslatorRegistry.java:69) ~[Geyser-Fabric.jar:?]
        at io.netty.util.concurrent.AbstractEventExecutor.runTask(AbstractEventExecutor.java:174) ~[netty-common-4.1.97.Final.jar:?]
        at io.netty.channel.DefaultEventLoop.run(DefaultEventLoop.java:54) ~[netty-transport-4.1.97.Final.jar:?]
        at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.97.Final.jar:?]
        at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.97.Final.jar:?]
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.97.Final.jar:?]
        at java.lang.Thread.run(Thread.java:840) ~[?:?]

In the end, Bedrock players are unable to destroy these blocks in survival mode (it leads to a desync). Notably, Bedrock players in creative mode can destroy them fine with no errors popping up in the logs. I have tried setting the Geyser use-direct-connection to false to fix the issue, but with no success.

To Reproduce

Setup a simple Fabric server with Geyser (optionally Floodgate as well, this was used in my testing environment) and any mod using the library Polymer to create custom blocks represented by player heads (in my testing environment Universal Shops).

Join the server using Bedrock, place down a custom block (in my case the Trade Shop), and try to break it (in survival/adventure mode). Notice that one error appears when starting to break the block, and another when finishing breaking it. Also notice that the block appears broken on the Bedrock client, but isn't.

Expected behaviour

It is expected for the block to break correctly with no issues or errors appearing in the logs, since Polymer is fully compatible with vanilla Java clients, it is expected to be fully compatible with vanilla Bedrock as well.

Screenshots / Videos

Screenshot_20240408_135241

Notice that along with block breaking being broken, the shop block has a weird appearance as well. Its UI however is fully functional.

Server Version and Plugins

[13:45:22] [main/INFO]: Loading Minecraft 1.20.4 with Fabric Loader 0.15.9
[13:45:22] [main/INFO]: Loading 93 mods:
        - fabric-api 0.96.11+1.20.4
           |-- fabric-api-base 0.4.36+78d798af4f
           |-- fabric-api-lookup-api-v1 1.6.49+82b1bb3e4f
           |-- fabric-biome-api-v1 13.0.16+78d798af4f
           |-- fabric-block-api-v1 1.0.16+3e2216cb4f
           |-- fabric-block-view-api-v2 1.0.4+78d798af4f
           |-- fabric-blockrenderlayer-v1 1.1.46+78d798af4f
           |-- fabric-client-tags-api-v1 1.1.7+78d798af4f
           |-- fabric-command-api-v1 1.2.41+f71b366f4f
           |-- fabric-command-api-v2 2.2.20+78d798af4f
           |-- fabric-commands-v0 0.2.58+df3654b34f
           |-- fabric-containers-v0 0.1.86+df3654b34f
           |-- fabric-content-registries-v0 5.0.15+78d798af4f
           |-- fabric-convention-tags-v1 1.5.10+78d798af4f
           |-- fabric-crash-report-info-v1 0.2.23+78d798af4f
           |-- fabric-data-attachment-api-v1 1.1.4+b90db5744f
           |-- fabric-data-generation-api-v1 13.2.4+5c0133444f
           |-- fabric-dimensions-v1 2.1.61+78d798af4f
           |-- fabric-entity-events-v1 1.6.1+09fc25014f
           |-- fabric-events-interaction-v0 0.7.1+389931eb4f
           |-- fabric-events-lifecycle-v0 0.2.74+df3654b34f
           |-- fabric-game-rule-api-v1 1.0.46+78d798af4f
           |-- fabric-item-api-v1 2.2.0+d6f2b0844f
           |-- fabric-item-group-api-v1 4.0.26+58f8c0124f
           |-- fabric-key-binding-api-v1 1.0.41+78d798af4f
           |-- fabric-keybindings-v0 0.2.39+df3654b34f
           |-- fabric-lifecycle-events-v1 2.3.0+a67ffb5d4f
           |-- fabric-loot-api-v2 2.1.9+78d798af4f
           |-- fabric-message-api-v1 6.0.5+78d798af4f
           |-- fabric-mining-level-api-v1 2.1.65+78d798af4f
           |-- fabric-model-loading-api-v1 1.0.8+78d798af4f
           |-- fabric-models-v0 0.4.7+9386d8a74f
           |-- fabric-networking-api-v1 3.1.7+2e5ac5484f
           |-- fabric-object-builder-api-v1 13.0.14+080016e44f
           |-- fabric-particles-v1 1.1.7+78d798af4f
           |-- fabric-recipe-api-v1 2.0.20+78d798af4f
           |-- fabric-registry-sync-v0 4.0.19+58f8c0124f
           |-- fabric-renderer-api-v1 3.2.4+78d798af4f
           |-- fabric-renderer-indigo 1.5.4+78d798af4f
           |-- fabric-renderer-registries-v1 3.2.53+df3654b34f
           |-- fabric-rendering-data-attachment-v1 0.3.42+73761d2e4f
           |-- fabric-rendering-fluids-v1 3.1.1+e761c6694f
           |-- fabric-rendering-v0 1.1.56+df3654b34f
           |-- fabric-rendering-v1 3.2.0+6fd945a04f
           |-- fabric-resource-conditions-api-v1 2.3.14+78d798af4f
           |-- fabric-resource-loader-v0 0.11.20+df798a894f
           |-- fabric-screen-api-v1 2.0.17+78d798af4f
           |-- fabric-screen-handler-api-v1 1.3.55+78d798af4f
           |-- fabric-sound-api-v1 1.0.17+78d798af4f
           |-- fabric-transfer-api-v1 4.0.11+eb30349a4f
           \-- fabric-transitive-access-wideners-v1 5.0.14+78d798af4f
        - fabricloader 0.15.9
           \-- mixinextras 0.3.5
        - floodgate 2.2.0-SNAPSHOT
           \-- cloud 1.8.4
                |-- cloud_commandframework_cloud-brigadier_ 1.8.4
                |-- cloud_commandframework_cloud-core_ 1.8.4
                |-- cloud_commandframework_cloud-services_ 1.8.4
                |-- fabric-permissions-api-v0 0.2-SNAPSHOT
                \-- io_leangen_geantyref_geantyref 1.3.13
        - geyser-fabric 2.2.3-SNAPSHOT
           |-- com_fasterxml_jackson_core_jackson-annotations 2.17.0
           |-- com_fasterxml_jackson_core_jackson-core 2.17.0
           |-- com_fasterxml_jackson_core_jackson-databind 2.17.0
           |-- com_fasterxml_jackson_dataformat_jackson-dataformat-yaml 2.17.0
           |-- com_github_steveice10_opennbt 1.6
           |-- com_nukkitx_natives 1.0.3
           |-- fabric-permissions-api-v0 0.2-SNAPSHOT
           |-- io_airlift_aircompressor 0.25
           |-- net_bytebuddy_byte-buddy 1.14.9
           |-- net_jodah_expiringmap 0.5.10
           |-- net_kyori_adventure-api 4.15.0
           |-- net_kyori_adventure-key 4.15.0
           |-- net_kyori_adventure-nbt 4.15.0
           |-- net_kyori_adventure-text-serializer-gson 4.15.0
           |-- net_kyori_adventure-text-serializer-json 4.15.0
           |-- net_kyori_adventure-text-serializer-json-legacy-impl 4.15.0
           |-- net_kyori_adventure-text-serializer-legacy 4.15.0
           |-- net_kyori_adventure-text-serializer-plain 4.15.0
           |-- net_kyori_examination-api 1.3.0
           |-- net_kyori_examination-string 1.3.0
           |-- net_kyori_option 1.0.0
           |-- org_bitbucket_b_c_jose4j 0.9.3
           |-- org_cloudburstmc_block-state-updater 1.20.70-20240303.125052-2
           |-- org_cloudburstmc_math_api 2.0
           |-- org_cloudburstmc_math_immutable 2.0
           |-- org_geysermc_api_base-api 1.0.0-SNAPSHOT
           |-- org_geysermc_cumulus_cumulus 1.1.2
           |-- org_geysermc_event_events 1.1-SNAPSHOT
           |-- org_java-websocket_java-websocket 1.5.1
           |-- org_lanternpowered_lmbda 2.0.0
           \-- org_yaml_snakeyaml 2.2
        - java 17
        - minecraft 1.20.4
        - universal_shops 1.5.0+1.20.3
           |-- common-economy-api 1.1.1
           |-- common-protection-api 1.0.0
           |-- fabric-permissions-api-v0 0.2-SNAPSHOT
           |-- placeholder-api 2.3.0+1.20.3
           |-- polymer-core 0.7.0+1.20.3-rc1
           |    |-- polymer-networking 0.7.0+1.20.3-rc1
           |    |    \-- polymer-common 0.7.0+1.20.3-rc1
           |    |         \-- packet_tweaker 0.5.0+1.20.2-rc1
           |    \-- polymer-registry-sync-manipulator 0.7.0+1.20.3-rc1
           |-- polymer-resource-pack 0.7.0+1.20.3-rc1
           |    \-- polymer-common 0.7.0+1.20.3-rc1
           |         \-- packet_tweaker 0.5.0+1.20.2-rc1
           |-- polymer-virtual-entity 0.7.0+1.20.3-rc1
           |    \-- polymer-common 0.7.0+1.20.3-rc1
           |         \-- packet_tweaker 0.5.0+1.20.2-rc1
           |-- server_translations_api 2.2.0+1.20.3-rc1
           |    \-- packet_tweaker 0.5.0+1.20.2-rc1
           \-- sgui 1.3.0+1.20.2

Geyser Dump

https://dump.geysermc.org/1eVduK3F21L60G9TYAbv10D4dOZWyBgZ

Geyser Version

2.2.3-SNAPSHOT (git-master-fa2e4e5)

Minecraft: Bedrock Edition Device/Version

1.20.73, MCPE (ran on Linux using mcpelauncher)

Additional Context

No response

eclipseisoffline commented 7 months ago

Adding default fallbacks when retrieving blocks (replacing BlockRegistries.JAVA_BLOCKS.get calls with BlockRegistries.JAVA_BLOCKS.getOrDefault) in BedrockActionTranslator and JavaBlockDestructionTranslator seems to mostly fix the issue. When adding the profile texture values used by the custom head blocks to custom-skulls.yml these blocks have a better appearance, though they still appear attached to a wall, which can cause collision desyncs.

I created a commit solving the issue. Should I pull request, or is there a better fix available?

rtm516 commented 7 months ago

Happy to accept the PR, will need some testing though