(vanilla fix) resolve NPE in NetHandlerPlayClient#handleSpawnPlayer

This commit is contained in:
kirillsaint 2024-01-16 18:26:16 +06:00
parent 54e4e25401
commit 882d89d0e6

View File

@ -4,7 +4,9 @@ import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.client.multiplayer.WorldClient; import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.client.network.NetHandlerPlayClient; import net.minecraft.client.network.NetHandlerPlayClient;
import net.minecraft.client.network.NetworkPlayerInfo;
import net.minecraft.network.play.server.S01PacketJoinGame; import net.minecraft.network.play.server.S01PacketJoinGame;
import net.minecraft.network.play.server.S0CPacketSpawnPlayer;
import net.minecraft.network.play.server.S19PacketEntityStatus; import net.minecraft.network.play.server.S19PacketEntityStatus;
import net.minecraft.network.play.server.S48PacketResourcePackSend; import net.minecraft.network.play.server.S48PacketResourcePackSend;
import net.minecraft.util.IChatComponent; import net.minecraft.util.IChatComponent;
@ -16,9 +18,28 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.*; import org.spongepowered.asm.mixin.injection.*;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.UUID;
@Mixin(NetHandlerPlayClient.class) @Mixin(NetHandlerPlayClient.class)
public class NetHandlerPlayClientMixin { public abstract class NetHandlerPlayClientMixin {
@Shadow private WorldClient clientWorldController; @Shadow private WorldClient clientWorldController;
@Shadow
public abstract NetworkPlayerInfo getPlayerInfo(UUID p_175102_1_);
@Inject(
method = "handleSpawnPlayer",
cancellable = true,
at =
@At(
value = "INVOKE",
target = "Lnet/minecraft/network/PacketThreadUtil;checkThreadAndEnqueue(Lnet/minecraft/network/Packet;Lnet/minecraft/network/INetHandler;Lnet/minecraft/util/IThreadListener;)V",
shift = At.Shift.AFTER
))
private void patcher$fixHandleSpawnPlayerNPE(S0CPacketSpawnPlayer packetIn, CallbackInfo ci) {
if (this.getPlayerInfo(packetIn.getPlayer()) == null) {
ci.cancel();
}
}
@Inject(method = "handleEntityStatus", at = @At("RETURN")) @Inject(method = "handleEntityStatus", at = @At("RETURN"))
public void callEntityDamageEvent(S19PacketEntityStatus packetIn, CallbackInfo ci) { public void callEntityDamageEvent(S19PacketEntityStatus packetIn, CallbackInfo ci) {