[Scarpet] Added ability to cancel events (#1497)

* Added ability to cancel events

* Made more events cancellable

* Added event_priority to __config

* Check for string values for performance

* Made player_finishes_using_item cancellable

* Made player_chooses_recipe cancellable

* Made player_swaps_hands cancellable

* Made player_message cancellable

* Added __on_player_placing_block (#1498)

* Added event to docs, keywords, event_test

* Added docs for event cancellation
This commit is contained in:
replaceitem authored and GitHub committed 2022-10-15 13:30:53 +02:00
1 parent 4bb4b557e5
commit 24b9c386ec
14 files changed
+243 -99

No files matched your search

@@ -37,7 +37,7 @@ public abstract class LivingEntity_scarpetEventsMixin extends Entity implements
((EntityInterface)this).getEventContainer().onEvent(EntityEventsGroup.Event.ON_DEATH, damageSource_1.msgId);
}
@Inject(method = "actuallyHurt", locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
@Inject(method = "actuallyHurt", cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD, at = @At(
value = "INVOKE",
target = "Lnet/minecraft/world/entity/LivingEntity;getDamageAfterArmorAbsorb(Lnet/minecraft/world/damagesource/DamageSource;F)F",
shift = At.Shift.BEFORE
@@ -52,7 +52,9 @@ public abstract class LivingEntity_scarpetEventsMixin extends Entity implements
//}
if (source.getEntity() instanceof ServerPlayer && PLAYER_DEALS_DAMAGE.isNeeded())
{
PLAYER_DEALS_DAMAGE.onDamage(this, amount, source);
if(PLAYER_DEALS_DAMAGE.onDamage(this, amount, source)) {
ci.cancel();
}
}
}