PlayerEvent.java 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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 me.shedaniel.architectury.utils.IntValue;
  23. import net.minecraft.advancements.Advancement;
  24. import net.minecraft.core.BlockPos;
  25. import net.minecraft.resources.ResourceKey;
  26. import net.minecraft.server.level.ServerPlayer;
  27. import net.minecraft.world.Container;
  28. import net.minecraft.world.InteractionResult;
  29. import net.minecraft.world.entity.item.ItemEntity;
  30. import net.minecraft.world.entity.player.Player;
  31. import net.minecraft.world.inventory.AbstractContainerMenu;
  32. import net.minecraft.world.item.ItemStack;
  33. import net.minecraft.world.level.Level;
  34. import net.minecraft.world.level.block.state.BlockState;
  35. import org.jetbrains.annotations.ApiStatus;
  36. import org.jetbrains.annotations.Nullable;
  37. public interface PlayerEvent {
  38. Event<PlayerJoin> PLAYER_JOIN = EventFactory.createLoop();
  39. Event<PlayerQuit> PLAYER_QUIT = EventFactory.createLoop();
  40. Event<PlayerRespawn> PLAYER_RESPAWN = EventFactory.createLoop();
  41. Event<PlayerAdvancement> PLAYER_ADVANCEMENT = EventFactory.createLoop();
  42. Event<PlayerClone> PLAYER_CLONE = EventFactory.createLoop();
  43. Event<CraftItem> CRAFT_ITEM = EventFactory.createLoop();
  44. Event<SmeltItem> SMELT_ITEM = EventFactory.createLoop();
  45. Event<PickupItemPredicate> PICKUP_ITEM_PRE = EventFactory.createInteractionResult();
  46. Event<PickupItem> PICKUP_ITEM_POST = EventFactory.createLoop();
  47. Event<ChangeDimension> CHANGE_DIMENSION = EventFactory.createLoop();
  48. Event<DropItem> DROP_ITEM = EventFactory.createLoop();
  49. Event<OpenMenu> OPEN_MENU = EventFactory.createLoop();
  50. Event<CloseMenu> CLOSE_MENU = EventFactory.createLoop();
  51. /**
  52. * @deprecated use {@link BlockEvent#BREAK}
  53. */
  54. @Deprecated
  55. @ApiStatus.ScheduledForRemoval(inVersion = "2.0")
  56. Event<BreakBlock> BREAK_BLOCK = EventFactory.createInteractionResult();
  57. interface PlayerJoin {
  58. void join(ServerPlayer player);
  59. }
  60. interface PlayerQuit {
  61. void quit(ServerPlayer player);
  62. }
  63. interface PlayerRespawn {
  64. void respawn(ServerPlayer newPlayer, boolean conqueredEnd);
  65. }
  66. interface PlayerClone {
  67. void clone(ServerPlayer oldPlayer, ServerPlayer newPlayer, boolean wonGame);
  68. }
  69. interface PlayerAdvancement {
  70. void award(ServerPlayer player, Advancement advancement);
  71. }
  72. interface CraftItem {
  73. void craft(Player player, ItemStack constructed, Container inventory);
  74. }
  75. interface SmeltItem {
  76. void smelt(Player player, ItemStack smelted);
  77. }
  78. interface PickupItemPredicate {
  79. InteractionResult canPickup(Player player, ItemEntity entity, ItemStack stack);
  80. }
  81. interface PickupItem {
  82. void pickup(Player player, ItemEntity entity, ItemStack stack);
  83. }
  84. interface ChangeDimension {
  85. void change(ServerPlayer player, ResourceKey<Level> oldLevel, ResourceKey<Level> newLevel);
  86. }
  87. interface DropItem {
  88. InteractionResult drop(Player player, ItemEntity entity);
  89. }
  90. interface BreakBlock {
  91. InteractionResult breakBlock(Level world, BlockPos pos, BlockState state, ServerPlayer player, @Nullable IntValue xp);
  92. }
  93. interface OpenMenu {
  94. void open(Player player, AbstractContainerMenu menu);
  95. }
  96. interface CloseMenu {
  97. void close(Player player, AbstractContainerMenu menu);
  98. }
  99. }