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.
| Event | Listener method | Description |
|---|---|---|
PLAYER_JOIN | join(ServerPlayer) | A player joined the server. |
PLAYER_QUIT | quit(ServerPlayer) | A player logged out. |
PLAYER_RESPAWN | respawn(ServerPlayer newPlayer, boolean conqueredEnd, Entity.RemovalReason) | A player respawned. |
PLAYER_CLONE | clone(ServerPlayer oldPlayer, ServerPlayer newPlayer, boolean wonGame) | A player respawned; lets you copy data from the old player to the new one. |
PLAYER_ADVANCEMENT | award(ServerPlayer, AdvancementHolder) | A player earned an advancement. |
CRAFT_ITEM | craft(Player, ItemStack constructed, Container inventory) | A player took a crafted item out of the result slot. |
SMELT_ITEM | smelt(Player, ItemStack smelted) | A player took a smelted item out of the output slot. |
PICKUP_ITEM_POST | pickup(Player, ItemEntity, ItemStack) | A player picked up an item. |
CHANGE_DIMENSION | change(ServerPlayer, ResourceKey<Level> oldLevel, ResourceKey<Level> newLevel) | A player changed dimension. |
OPEN_MENU | open(Player, AbstractContainerMenu) | A player opened a container menu. |
CLOSE_MENU | close(Player, AbstractContainerMenu) | A player closed a container menu. |
Cancellable events
These return an EventResult so you can cancel the action.
| Event | Listener method | Returns |
|---|---|---|
PICKUP_ITEM_PRE | canPickup(Player, ItemEntity, ItemStack) | EventResult - interrupt to prevent the pickup. |
DROP_ITEM | drop(Player, ItemEntity) | EventResult - interrupt to prevent the drop. |
ATTACK_ENTITY | attack(Player, Level, Entity target, InteractionHand, EntityHitResult) | EventResult - interrupt to cancel the attack. |
FILL_BUCKET | fill(Player, Level, ItemStack, HitResult) | EventResult - interrupt to handle/cancel it. |
BREAK_SPEED | breakSpeed(Player, BlockState, BlockPos pos, FloatValue speed) | EventResult - interrupt to stop the player breaking the block. |
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();
});