Conversation
0xMashiro
marked this pull request as ready for review
August 21, 2026 02:42
Author
|
已经将编译后的 hotfix 版本在自己的服务器上线,运行24小时无问题。 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
变更原因
生产环境中出现了一次由 TaCZ 子弹实体生成数据编码触发的服务端主线程崩溃。
现场环境:
事故发生在玩家移动后重新建立实体追踪关系时。服务端尝试向客户端发送一枚
EntityKineticBullet的生成数据包,其中gunId为null,最终在资源 ID 序列化阶段抛出NullPointerException:该异常由服务端主线程向上抛出并导致实例停止。现场没有 OOM 证据;玩家移动只触发了实体追踪更新,并不是空字段的创建来源。
进一步检查发现,
EntityKineticBullet(EntityType, Level)会由实体类型工厂调用。该构造路径为ammoId设置了字段默认值,但gunId和gunDisplayId保持 Java 默认值null。如果附属 Mod 或其他运行时代码通过实体工厂创建子弹并绕过正常开枪构造器,该实体在进入追踪范围后即可触发上述崩溃。同一代码路径在 1.1.8-hotfix 中仍然存在。
修改内容
gunId和gunDisplayId增加与项目现有ammoId相同风格的字段默认值。writeSpawnData中增加最终空值保护,覆盖字段被第三方 Mixin、反射或异常路径重新写为null的情况。ammoId、gunId和gunDisplayId三个生成数据包中的ResourceLocation字段。使用的回退值均来自现有
DefaultAssets:兼容性
复现建议
由于
tacz:bullet注册为noSummon(),不能通过普通/summon命令可靠复现。可在开发测试代码中调用:随后让玩家进入该实体的追踪范围。修改前会在
writeSpawnData中对空gunId编码并导致 NPE;修改后会使用安全哨兵 ID 完成编码。验证状态
git diff --check:通过。DefaultAssets、Objects.requireNonNullElse用法一致。风险评估
本修改只影响异常空值路径。对于正常子弹实体,序列化结果与修改前完全一致;对于数据不完整的实体,行为从“服务端主线程崩溃”降级为“使用 TaCZ 已定义的空/默认资源 ID 完成同步”。