From e08a378318289db49f152af162ca77b20dd03f7a Mon Sep 17 00:00:00 2001 From: Pug <81167232+MerchantPug@users.noreply.github.com> Date: Tue, 12 Mar 2024 15:24:38 +1100 Subject: [PATCH] Apoli: Fix EdwinMindcraft/origins-architectury#353. --- .../power/InteractionPowerConfiguration.java | 5 ++--- .../apoli/common/ApoliPowerEventHandler.java | 15 ++++++++++----- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/main/java/io/github/edwinmindcraft/apoli/api/power/configuration/power/InteractionPowerConfiguration.java b/src/main/java/io/github/edwinmindcraft/apoli/api/power/configuration/power/InteractionPowerConfiguration.java index a800cf12c..4b8c95d84 100644 --- a/src/main/java/io/github/edwinmindcraft/apoli/api/power/configuration/power/InteractionPowerConfiguration.java +++ b/src/main/java/io/github/edwinmindcraft/apoli/api/power/configuration/power/InteractionPowerConfiguration.java @@ -66,11 +66,10 @@ public void performActorItemStuff(LivingEntity actor, InteractionHand hand) { Mutable resultingStack = this.itemResult() == null ? heldStack : new MutableObject<>(this.itemResult().copy()); boolean modified = this.itemResult() != null; if (this.resultItemAction().isBound()) { - this.resultItemAction().value().execute(actor.level(), resultingStack); - modified = true; + ConfiguredItemAction.execute(this.resultItemAction(), actor.level(), resultingStack); } if (modified) { - if (heldStack.getValue().isEmpty()) + if (resultingStack.getValue().isEmpty()) actor.setItemInHand(hand, resultingStack.getValue()); else if (actor instanceof Player player) player.getInventory().placeItemBackInInventory(resultingStack.getValue()); diff --git a/src/main/java/io/github/edwinmindcraft/apoli/common/ApoliPowerEventHandler.java b/src/main/java/io/github/edwinmindcraft/apoli/common/ApoliPowerEventHandler.java index b3e7cf331..d122bbfb7 100644 --- a/src/main/java/io/github/edwinmindcraft/apoli/common/ApoliPowerEventHandler.java +++ b/src/main/java/io/github/edwinmindcraft/apoli/common/ApoliPowerEventHandler.java @@ -404,11 +404,16 @@ public static void preventEntityInteraction(PlayerInteractEvent.EntityInteract e Player player = event.getEntity(); if (player.isSpectator()) return; Entity target = event.getTarget(); - ActionOnEntityUsePower.tryPrevent(player, target, event.getHand()) - .or(() -> ActionOnBeingUsedPower.tryPrevent(target, player, event.getHand())).ifPresent(res -> { - event.setCancellationResult(res); - event.setCanceled(true); - }); + Optional result = ActionOnEntityUsePower.tryPrevent(player, target, event.getHand()); + if (result.isEmpty() || result.get() == InteractionResult.PASS) { + result = ActionOnBeingUsedPower.tryPrevent(target, player, event.getHand()); + } + result.ifPresent(res -> { + if (res != InteractionResult.PASS) { + event.setCancellationResult(res); + event.setCanceled(true); + } + }); } @SubscribeEvent(priority = EventPriority.HIGHEST)