WTHIT Forge Edition

WTHIT Forge Edition

3M Downloads

Wither spawning can cause a crash

Fourmisain opened this issue ยท 0 comments

commented

I was playing on a multiplayer server and tried spawning a Wither.
Just after placing the last wither skull the game crashed with

java.lang.NullPointerException: Cannot invoke "net.minecraft.class_2631.method_11334()" because "skull" is null
at Not Enough Crashes deobfuscated stack trace.(1.16.5+build.6)
at mcp.mobius.waila.plugin.vanilla.PlayerHeadComponent.getDisplayItem(PlayerHeadComponent.java:26)
at mcp.mobius.waila.overlay.Raycast.getDisplayItem(Raycast.java:102)
at mcp.mobius.waila.overlay.Tooltip.hasItem(Tooltip.java:148)
at mcp.mobius.waila.overlay.Tooltip.render(Tooltip.java:197)
at net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback.lambda$static$0(HudRenderCallback.java:27)
at net.minecraft.client.gui.hud.InGameHud.handler$zff000$render(InGameHud:1841)
at net.minecraft.client.gui.hud.InGameHud.render(InGameHud:376)
...

I wasn't able to reproduce the issue in singleplayer and it might be caused by Accurate Block Placement which seems to have placed a 4th skull. Maybe there's some kind of timing issue where the block was (re?)placed locally but the block entity was deleted due to the wither spawning - or something like that.

Either way, the fix should be to add some null checks at these places:

SkullBlockEntity skull = (SkullBlockEntity) accessor.getBlockEntity();
if (skull.getOwner() != null) {

SkullBlockEntity skull = (SkullBlockEntity) accessor.getBlockEntity();
if (skull.getOwner() != null && !StringUtils.isBlank(skull.getOwner().getName()))

I looked through the code for other unchecked getBlockEntity() instances and found this one:

MobSpawnerBlockEntity spawner = (MobSpawnerBlockEntity) accessor.getBlockEntity();
((ITaggableList<Identifier, Text>) tooltip).setTag(OBJECT_NAME_TAG, new TranslatableText(accessor.getBlock().getTranslationKey())
.append(new LiteralText(" ("))
.append(spawner.getLogic().getRenderedEntity().getDisplayName())

It's unlikely that this could cause issues, except maybe then command blocks or creative players adding/removing spawners are involed, a null check wouldn't hurt tough.

P.S. I would have made this a PR, but it's been what feels like 30 mins and it is still downloading dependencies... ๐Ÿ˜