Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
MerchantPug committed Mar 12, 2024
1 parent 277d30e commit e08a378
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,10 @@ public void performActorItemStuff(LivingEntity actor, InteractionHand hand) {
Mutable<ItemStack> 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());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<InteractionResult> 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)
Expand Down

0 comments on commit e08a378

Please sign in to comment.