EntityEvent.java 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*
  2. * This file is part of architectury.
  3. * Copyright (C) 2020, 2021 shedaniel
  4. *
  5. * This program is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 3 of the License, or (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public License
  16. * along with this program; if not, write to the Free Software Foundation,
  17. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  18. */
  19. package me.shedaniel.architectury.event.events;
  20. import me.shedaniel.architectury.event.Event;
  21. import me.shedaniel.architectury.event.EventFactory;
  22. import net.minecraft.core.BlockPos;
  23. import net.minecraft.world.InteractionResult;
  24. import net.minecraft.world.damagesource.DamageSource;
  25. import net.minecraft.world.entity.Entity;
  26. import net.minecraft.world.entity.LivingEntity;
  27. import net.minecraft.world.level.Level;
  28. import net.minecraft.world.level.block.state.BlockState;
  29. import org.jetbrains.annotations.Nullable;
  30. public interface EntityEvent {
  31. /**
  32. * Invoked before LivingEntity#die, equivalent to forge's {@code LivingDeathEvent}.
  33. */
  34. Event<LivingDeath> LIVING_DEATH = EventFactory.createInteractionResult();
  35. /**
  36. * Invoked before LivingEntity#hurt, equivalent to forge's {@code LivingAttackEvent}.
  37. */
  38. Event<LivingAttack> LIVING_ATTACK = EventFactory.createInteractionResult();
  39. /**
  40. * Invoked before entity is added to a world, equivalent to forge's {@code EntityJoinWorldEvent}.
  41. */
  42. Event<Add> ADD = EventFactory.createInteractionResult();
  43. Event<PlaceBlock> PLACE_BLOCK = EventFactory.createInteractionResult();
  44. interface LivingDeath {
  45. InteractionResult die(LivingEntity entity, DamageSource source);
  46. }
  47. interface LivingAttack {
  48. InteractionResult attack(LivingEntity entity, DamageSource source, float amount);
  49. }
  50. interface Add {
  51. InteractionResult add(Entity entity, Level world);
  52. }
  53. interface PlaceBlock {
  54. InteractionResult placeBlock(Level world, BlockPos pos, BlockState state, @Nullable Entity placer);
  55. }
  56. }