Matthiesen Core
Matthiesen Core 是一个为 NeoForge 和 Fabric 设计的库模组,旨在使开发者能够使用共享的通用代码库来创建模组。
它提供了一套核心功能和工具,可在多个模组间复用,从而简化开发和维护工作。
你无需为每个平台单独维护不同的实现,只需在通用代码中编写一次模组逻辑,然后让 Matthiesen Core
来处理特定平台的细节即可。
如果依赖该模组的模组仅用于服务端,则 Matthiesen Core 无需安装在客户端。然而,如果依赖 Matthiesen Core 的模组包含客户端组件,那么 Matthiesen Core 也必须安装在客户端上。
注意:对于普通用户而言,除了为其他模组设置核心功能外,这个库本身没有任何实际作用。
如果你不是模组开发者,只需将该模组与其他依赖它的模组一起放入你的 mods/ 文件夹中,即可正常使用。
Matthiesen Core 是 Matthiesen Lib 和 Matthiesen Lib Api 的继任者,
后者原本是两个独立的库,现已合并为一个统一的库模组,为模组开发者提供更精简、高效的体验。
特性
Matthiesen Core 提供了一个统一的 API,支持以下功能:
- 内容注册:以跨平台兼容的方式注册方块、物品、实体和其他游戏内容。
- 事件处理:监听和处理不同平台上的游戏事件。
- 网络通信:在客户端和服务器之间发送和接收网络数据包。
- 配置管理:以一致的方式管理模组配置和设置。
- 实用函数:访问各种常用任务的实用函数,例如日志记录、资源管理等。
- 客户端特性:包含客户端特定的功能,如 HUD 管理、按键绑定处理和屏幕管理。
- 权限管理:提供权限系统,用于管理对某些功能或命令的访问权限。
必要依赖
可选依赖
版本兼容性
| Minecraft 版本 |
Fabric 版本 |
NeoForge 版本 |
模组版本 |
| 1.21.1 |
0.17.2+ |
21.1.182+ |
1.x.x |
| 1.21.1 |
0.18.4+ |
21.1.234+ |
2.x.x |
开发者快速入门
Matthiesen Core 的开发版本和源代码可从 Matthiesen Dev Maven 获取。
Gradle
步骤 1:将 Maven 仓库添加到你的 build.gradle.kts 文件中
repositories {
maven("https://maven.matthiesen.dev/releases") {
name = "devMatthiesenMaven-releases"
}
// 如需快照版本,还需包含快照仓库
maven("https://maven.matthiesen.dev/snapshots") {
name = "devMatthiesenMaven-snapshots"
}
}
步骤 2:在你的 gradle.properties 文件中添加版本属性
matthiesen_core_version=2.x.x
注意:请将 2.x.x 替换为 Matthiesen Core 的最新版本。你可以在 Matthiesen Dev Maven 找到最新版本,也可以参考下表查看对应版本。
| 发布类型 |
版本徽章 |
| 最新正式版 |
 |
步骤 3:将依赖项添加到你的 build.gradle.kts 文件中
// 在 common/build.gradle.kts 中
dependencies {
modImplementation("dev.matthiesen:matthiesen-core-common:${property("matthiesen_core_version")}") {
isTransitive = false
}
}
// 在 fabric/build.gradle.kts 中
dependencies {
modImplementation("dev.matthiesen:matthiesen-core-fabric:${property("matthiesen_core_version")}") {
isTransitive = false
}
}
// 在 neoforge/build.gradle.kts 中
dependencies {
modImplementation("dev.matthiesen:matthiesen-core-neoforge:${property("matthiesen_core_version")}") {
isTransitive = false
}
}
步骤 4:加载器特定的依赖项设置
对于 Fabric 和 NeoForge,你需要在模组的元数据文件(例如 Fabric 的 fabric.mod.json 或 NeoForge 的 neoforge.mods.toml)中添加相应的加载器特定依赖项。这可以确保在与你的模组一起加载时,正确版本的 Matthiesen Core 被加载。
Fabric 示例 (fabric.mod.json):
{
"depends": {
"matthiesen_core": ">=2.x.x"
}
}
NeoForge 示例 (neoforge.mods.toml):
[[dependencies.yourmodid]]
modId = "matthiesen_core"
type = "required"
versionRange = "[2.x.x,)"
ordering = "AFTER"
side = "BOTH"
步骤 5:同步你的项目,并设置通用的模组代码库以使用 Matthiesen Core 的 API 进行内容注册、事件处理、网络通信及其他功能。
AbstractCommonMod:在你的公共模组代码库中扩展 AbstractCommonMod 类,以利用 Matthiesen Core 的核心功能。此类为你的模组提供了基础框架,使你能够专注于实现模组的独特功能,而 Matthiesen Core 则处理平台相关的细节。
package com.example.mymod;
import dev.matthiesen.matthiesen_core.common.AbstractCommonMod;
import dev.faststats.Token;
import org.jetbrains.annotations.Nullable;
public final class ExampleModCommon extends AbstractCommonMod {
public static final String MOD_ID = "examplemod";
public static final String MOD_NAME = "Example Mod";
public static final ExampleModCommon INSTANCE = new ExampleModCommon();
private ExampleModCommon() {
super(MOD_ID, MOD_NAME);
}
@Override
public @Nullable @Token String getMetricsToken() {
return null;
}
@Override
public void initialize() {
super.initialize();
createInfoLog("Initializing Example Mod Common...");
}
}
AbstractCommonClientMod:在你的客户端模组代码库中扩展 AbstractCommonClientMod 类,以利用 Matthiesen Core 的客户端特定功能。此类为你的客户端模组提供了基础框架,使你能够专注于实现模组的独特客户端功能,而 Matthiesen Core 则处理平台相关的细节。
package com.example.mymod.client;
import dev.matthiesen.matthiesen_core.common.AbstractCommonClientMod;
import com.example.mymod.ExampleModCommon;
public final class ExampleModCommonClient extends AbstractCommonClientMod {
public static final ExampleModCommonClient INSTANCE = new ExampleModCommonClient();
private ExampleModCommonClient() {
super(ExampleModCommon.INSTANCE);
}
@Override
public void initialize() {
createInfoLog("Initializing Example Mod Common Client logic...");
}
}
进一步阅读
本模组的文档可在 mods.matthiesen.dev 找到。
FastStats 指标
本模组使用 FastStats 来收集匿名使用统计数据。这有助于开发者了解该模组的使用情况并持续改进它。你可以通过访问 FastStats: Information 了解更多关于所收集数据及其用途的信息。
你也可以在 FastStats: Matthiesen Core 页面上查看本模组收集的数据。
若要退出此数据收集,请在 <game_directory>/config/faststats/config.properties 文件中将 enabled 属性设置为 false。
许可证
MIT - 请参阅 LICENSE。
Matthiesen Core
Matthiesen Core is a library mod for NeoForge and Fabric that enables developers to create mods with a shared common codebase.
It provides a set of core functionalities and utilities that can be used across multiple mods, allowing for easier development and maintenance.
Instead of maintaining separate implementations for each platform, you can write your mod logic once in common code and let Matthiesen core
handle the platform-specific details.
Matthiesen Core does not have to be installed on the client if the mod depending on it is server-side only. However, if the mod(s) that depend
on Matthiesen Core have client-side components, then Matthiesen Core must be installed on the client as well.
Note: For regular users, This library does nothing on its own aside from setting up the core functionality for other mods to utilize.
If you are not a mod developer, simply drop the mod in your mods/ folder alongside the other mods that depend on it, and you are good to go.
Matthiesen Core is the successor to Matthiesen Lib and Matthiesen Lib Api, which
were two separate libraries that have now been combined into a single unified library mod, that provides a more streamlined and efficient experience for mod developers.
Features
Matthiesen Core provides a unified API for:
- Content Registration: Register blocks, items, entities, and other game content in a platform-agnostic way.
- Event Handling: Listen to and handle game events across different platforms.
- Networking: Send and receive network packets between the client and server.
- Configuration Management: Manage mod configurations and settings in a consistent manner.
- Utility Functions: Access a variety of utility functions for common tasks, such as logging, resource management, and more.
- Client-Side Features: Includes client-specific features like HUD management, keybinding handling, and screen management.
- Permission Management: Provides a permission system for managing access to certain features or commands.
Required Dependencies
Optional Dependencies
Version Compatibility
| Minecraft Version |
Fabric Version |
NeoForge Version |
Mod Version |
| 1.21.1 |
0.17.2+ |
21.1.182+ |
1.x.x |
| 1.21.1 |
0.18.4+ |
21.1.234+ |
2.x.x |
Developer Quick Start
Matthiesen Core development versions and sources are available from Matthiesen Dev Maven.
Gradle
Step 1: Add the Maven repository to your build.gradle.kts file
repositories {
maven("https://maven.matthiesen.dev/releases") {
name = "devMatthiesenMaven-releases"
}
// For Snapshot versions, also include the snapshots repository
maven("https://maven.matthiesen.dev/snapshots") {
name = "devMatthiesenMaven-snapshots"
}
}
Step 2: Add the version property to your gradle.properties file
matthiesen_core_version=2.x.x
Note: Replace 2.x.x with the latest version of Matthiesen Core. You can find the latest version on Matthiesen Dev Maven or see the table below for the latest version.
| Release Type |
Version Badge |
| Latest Release |
 |
Step 3: Add the dependency to your build.gradle.kts file
// In common/build.gradle.kts
dependencies {
modImplementation("dev.matthiesen:matthiesen-core-common:${property("matthiesen_core_version")}") {
isTransitive = false
}
}
// In fabric/build.gradle.kts
dependencies {
modImplementation("dev.matthiesen:matthiesen-core-fabric:${property("matthiesen_core_version")}") {
isTransitive = false
}
}
// In neoforge/build.gradle.kts
dependencies {
modImplementation("dev.matthiesen:matthiesen-core-neoforge:${property("matthiesen_core_version")}") {
isTransitive = false
}
}
Step 4: Loader-specific Dependency Setup
For Fabric and NeoForge, you will need to add the appropriate loader-specific dependency to your mod metadata file (e.g., fabric.mod.json for Fabric or neoforge.mods.toml for NeoForge). This ensures that the correct version of Matthiesen Core is loaded alongside your mod.
Fabric Example (fabric.mod.json):
{
"depends": {
"matthiesen_core": ">=2.x.x"
}
}
NeoForge Example (neoforge.mods.toml):
[[dependencies.yourmodid]]
modId = "matthiesen_core"
type = "required"
versionRange = "[2.x.x,)"
ordering = "AFTER"
side = "BOTH"
Step 5: Sync your project and set up your common mod codebase to use Matthiesen Core's APIs for content registration, event handling, networking, and other features.
AbstractCommonMod: Extend the AbstractCommonMod class in your common mod codebase to leverage Matthiesen Core's core functionalities. This class provides a foundation for your mod, allowing you to focus on implementing your mod's unique features while Matthiesen Core handles the platform-specific details.
package com.example.mymod;
import dev.matthiesen.matthiesen_core.common.AbstractCommonMod;
import dev.faststats.Token;
import org.jetbrains.annotations.Nullable;
public final class ExampleModCommon extends AbstractCommonMod {
public static final String MOD_ID = "examplemod";
public static final String MOD_NAME = "Example Mod";
public static final ExampleModCommon INSTANCE = new ExampleModCommon();
private ExampleModCommon() {
super(MOD_ID, MOD_NAME);
}
@Override
public @Nullable @Token String getMetricsToken() {
return null;
}
@Override
public void initialize() {
super.initialize();
createInfoLog("Initializing Example Mod Common...");
}
}
AbstractCommonClientMod: Extend the AbstractCommonClientMod class in your client mod codebase to leverage Matthiesen Core's client-specific features. This class provides a foundation for your client-side mod, allowing you to focus on implementing your mod's unique client-side features while Matthiesen Core handles the platform-specific details.
package com.example.mymod.client;
import dev.matthiesen.matthiesen_core.common.AbstractCommonClientMod;
import com.example.mymod.ExampleModCommon;
public final class ExampleModCommonClient extends AbstractCommonClientMod {
public static final ExampleModCommonClient INSTANCE = new ExampleModCommonClient();
private ExampleModCommonClient() {
super(ExampleModCommon.INSTANCE);
}
@Override
public void initialize() {
createInfoLog("Initializing Example Mod Common Client logic...");
}
}
Further Reading
Documentation for this mod can be found at mods.matthiesen.dev
FastStats Metrics
This mod uses FastStats to collect anonymous usage statistics. This helps the developer understand
how this mod is being used and improve it over time. You can learn more about the data collected and how it is used by visiting
FastStats: Information.
You can also view the data collected by this mod on the FastStats: Matthiesen Core page.
To opt out of this data collection, set the enabled property to false in the <game_directory>/config/faststats/config.properties file.
License
MIT - see LICENSE.
评论 0
登录后参与评分
还没有评论,来抢沙发吧