Change skin-caching feature to be fail-safe (fixes #561)

This commit is contained in:
Jonas Herzig
2021-08-15 13:53:31 +02:00
parent 463c51be85
commit 27f365a60a

View File

@@ -2,6 +2,7 @@ package com.replaymod.replay.mixin;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.AbstractClientPlayerEntity; import net.minecraft.client.network.AbstractClientPlayerEntity;
import net.minecraft.client.network.OtherClientPlayerEntity;
import net.minecraft.client.network.PlayerListEntry; import net.minecraft.client.network.PlayerListEntry;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; 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 // 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, // 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). // 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(); this.getPlayerListEntry();
} catch (Exception e) {
e.printStackTrace();
} }
} }
} }