From 50745d792332b0afbe639efff4664ac4ec960b1d Mon Sep 17 00:00:00 2001 From: videogame hacker Date: Sun, 10 Apr 2022 17:33:35 +0100 Subject: [PATCH] Safe-cast to ServerPlayerEntity --- .../samo_lego/simpleauth/mixin/MixinSlot.java | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java index b781d5b..3ca726e 100644 --- a/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java +++ b/common/src/main/java/org/samo_lego/simpleauth/mixin/MixinSlot.java @@ -16,19 +16,20 @@ public abstract class MixinSlot { // Denying item moving etc. @Inject(method = "canTakeItems(Lnet/minecraft/entity/player/PlayerEntity;)Z", at = @At(value = "HEAD"), cancellable = true) private void canTakeItems(PlayerEntity playerEntity, CallbackInfoReturnable cir) { - ServerPlayerEntity player = (ServerPlayerEntity) playerEntity; - ActionResult result = AuthEventHandler.onTakeItem(player); + if (playerEntity instanceof ServerPlayerEntity player) { + ActionResult result = AuthEventHandler.onTakeItem(player); - if (result == ActionResult.FAIL) { - // Canceling the item taking - player.networkHandler.sendPacket( - new ScreenHandlerSlotUpdateS2CPacket( - -2, - 0, - player.getInventory().selectedSlot, - player.getInventory().getStack(player.getInventory().selectedSlot)) - ); - cir.setReturnValue(false); + if (result == ActionResult.FAIL) { + // Canceling the item taking + player.networkHandler.sendPacket( + new ScreenHandlerSlotUpdateS2CPacket( + -2, + 0, + player.getInventory().selectedSlot, + player.getInventory().getStack(player.getInventory().selectedSlot)) + ); + cir.setReturnValue(false); + } } } }