Add PlayerEvent.ATTACK_ENTITY (#380)

[ci skip]

* Add PlayerEvent.ATTACK_ENTITY
* Fired from Forge's AttackEntityEvent and Fabric's AttackEntityCallback
* When player is about to attack any entity (not just living) with left-click
* javadoc parameter alignment
* import cleanup
This commit is contained in:
desht
2023-02-06 16:53:43 +00:00
committed by GitHub
parent d022087cd5
commit 1524550146
3 changed files with 33 additions and 0 deletions

View File

@@ -431,6 +431,14 @@ public class EventHandlerImplCommon {
LootEvent.MODIFY_LOOT_TABLE.invoker().modifyLootTable(event.getLootTableManager(), event.getName(), new LootTableModificationContextImpl(event.getTable()), true);
}
@SubscribeEvent(priority = EventPriority.HIGH)
public static void event(AttackEntityEvent event) {
EventResult result = PlayerEvent.ATTACK_ENTITY.invoker().attack(event.getPlayer(), event.getPlayer().level, event.getTarget(), event.getPlayer().getUsedItemHand(), null);
if (result.isFalse()) {
event.setCanceled(true);
}
}
public interface WorldEventAttachment {
LevelAccessor architectury$getAttachedLevel();