From 27f365a60a709f4d241ec0dbf3f2bafb2383107b Mon Sep 17 00:00:00 2001 From: Jonas Herzig Date: Sun, 15 Aug 2021 13:53:31 +0200 Subject: [PATCH] Change skin-caching feature to be fail-safe (fixes #561) --- .../replay/mixin/Mixin_FixNPCSkinCaching.java | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/replaymod/replay/mixin/Mixin_FixNPCSkinCaching.java b/src/main/java/com/replaymod/replay/mixin/Mixin_FixNPCSkinCaching.java index 925c2b0e..11d31423 100644 --- a/src/main/java/com/replaymod/replay/mixin/Mixin_FixNPCSkinCaching.java +++ b/src/main/java/com/replaymod/replay/mixin/Mixin_FixNPCSkinCaching.java @@ -2,6 +2,7 @@ package com.replaymod.replay.mixin; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.AbstractClientPlayerEntity; +import net.minecraft.client.network.OtherClientPlayerEntity; import net.minecraft.client.network.PlayerListEntry; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; @@ -24,8 +25,19 @@ public abstract class Mixin_FixNPCSkinCaching { // intended ones. To fix that, we make this caching-glitch which servers have come to rely on an actual feature // by just fetching the cache in the constructor which arguably is what MC should have done to begin with, // especially because the spawn packet handling code already requires the entry to be present). - if (MinecraftClient.getInstance().getNetworkHandler() != null) { // will be null if this is the client player + + // To reduce the chance of incompatibility with custom player entities, we only do this for the vanilla MP one. + //noinspection ConstantConditions + if (!(((Object) this) instanceof OtherClientPlayerEntity)) return; + + // To get the player list entry, we need to be connected (we usually are, but better be safe than sorry) + if (MinecraftClient.getInstance().getNetworkHandler() == null) return; + + // And we catch any exceptions, so if there is still something, it's hopefully not fatal + try { this.getPlayerListEntry(); + } catch (Exception e) { + e.printStackTrace(); } } }