Safe-cast to ServerPlayerEntity in MixinSlot #1

Merged
sorceress merged 2 commits from videogame-hacker/EasyAuth:architectury into architectury 2022-04-10 18:12:17 +00:00
1 changed files with 13 additions and 12 deletions
Showing only changes of commit 50745d7923 - Show all commits

View File

@ -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<Boolean> 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);
}
}
}
}