I was just struggling with this too. Posting my solution, if it helps anyone. Works for 1.20.1 // First make your custom stats register
public static final DeferredRegister<ResourceLocation> CUSTOM_STATS =
DeferredRegister.create(Registries.CUSTOM_STAT, MyMod.MODID);
// Then make your custom stat type and add it to your register
public static final RegistryObject<ResourceLocation> BLOCK_PLACED =
CUSTOM_STATS.register("block_placed", () -> ResourceLocation.fromNamespaceAndPath(MyMod.MODID, "block_placed"));
// Register your register :) Called from init method of your mod
public static void register(IEventBus eventBus) {
CUSTOM_STATS.register(eventBus);
}
// An example usage of my custom stat
@SubscribeEvent
public void onBlockPlace(BlockEvent.EntityPlaceEvent event) {
if (!(event.getEntity() instanceof ServerPlayer player)) return;
player.awardStat(Stats.CUSTOM.get(BLOCK_PLACED.get()));
}