Skip to main content
Version: 26.2.x

Player Events

dev.architectury.event.events.common.PlayerEvent

Events about players: joining and leaving, crafting and smelting, picking up and dropping items, attacking, opening menus, block breaking speed, and more. Unless noted otherwise these fire on the server.

Notification events

These can't be cancelled - they tell you something happened.

EventListener methodDescription
PLAYER_JOINjoin(ServerPlayer)A player joined the server.
PLAYER_QUITquit(ServerPlayer)A player logged out.
PLAYER_RESPAWNrespawn(ServerPlayer newPlayer, boolean conqueredEnd, Entity.RemovalReason)A player respawned.
PLAYER_CLONEclone(ServerPlayer oldPlayer, ServerPlayer newPlayer, boolean wonGame)A player respawned; lets you copy data from the old player to the new one.
PLAYER_ADVANCEMENTaward(ServerPlayer, AdvancementHolder)A player earned an advancement.
CRAFT_ITEMcraft(Player, ItemStack constructed, Container inventory)A player took a crafted item out of the result slot.
SMELT_ITEMsmelt(Player, ItemStack smelted)A player took a smelted item out of the output slot.
PICKUP_ITEM_POSTpickup(Player, ItemEntity, ItemStack)A player picked up an item.
CHANGE_DIMENSIONchange(ServerPlayer, ResourceKey<Level> oldLevel, ResourceKey<Level> newLevel)A player changed dimension.
OPEN_MENUopen(Player, AbstractContainerMenu)A player opened a container menu.
CLOSE_MENUclose(Player, AbstractContainerMenu)A player closed a container menu.

Cancellable events

These return an EventResult so you can cancel the action.

EventListener methodReturns
PICKUP_ITEM_PREcanPickup(Player, ItemEntity, ItemStack)EventResult - interrupt to prevent the pickup.
DROP_ITEMdrop(Player, ItemEntity)EventResult - interrupt to prevent the drop.
ATTACK_ENTITYattack(Player, Level, Entity target, InteractionHand, EntityHitResult)EventResult - interrupt to cancel the attack.
FILL_BUCKETfill(Player, Level, ItemStack, HitResult)EventResult - interrupt to handle/cancel it.
BREAK_SPEEDbreakSpeed(Player, BlockState, BlockPos pos, FloatValue speed)EventResult - interrupt to stop the player breaking the block.
Added in 21.1

BREAK_SPEED was added in Architectury API 21.1.

Block breaking speed

BREAK_SPEED runs when a player's block breaking speed is calculated, from Player#getDestroySpeed(BlockState). The speed parameter is a FloatValue (a mutable float wrapper) pre-filled with the vanilla value; change it to make the player mine faster or slower. Interrupting with a false result stops the player from breaking the block at all.

The pos parameter is null when the caller did not supply one. Fabric never supplies one, as vanilla does not pass the position down to this calculation.

This mirrors NeoForge's PlayerEvent.BreakSpeed. Fabric has no equivalent, so Architectury supplies it with a mixin there.

PlayerEvent.BREAK_SPEED.register((player, state, pos, speed) -> {
if (player.getItemBySlot(EquipmentSlot.FEET).is(Items.DIAMOND_BOOTS)) {
speed.accept(speed.getAsFloat() * 2.0F); // mine twice as fast
}
return EventResult.pass();
});

Examples

PlayerEvent.PLAYER_JOIN.register(player -> {
player.sendSystemMessage(Component.literal("Welcome, " + player.getName().getString() + "!"));
});

Copy custom data across a respawn:

PlayerEvent.PLAYER_CLONE.register((oldPlayer, newPlayer, wonGame) -> {
// transfer your mod's per-player data from oldPlayer to newPlayer
});

Prevent players from attacking villagers:

PlayerEvent.ATTACK_ENTITY.register((player, level, target, hand, hitResult) -> {
if (target instanceof Villager) {
return EventResult.interruptFalse(); // cancel the attack
}
return EventResult.pass();
});