Mebahel 的 API
Mebahel 模组共用的系统与工具库。
Mebahel's API 是一个 Fabric 类库,为多个 Mebahel 项目提供通用的系统支持。它包含了可复用的代码,用于结构处理、自定义容器、多人游戏战利品处理、实体移动以及其他功能,否则这些功能需要在每个模组中单独实现。
该模组主要作为技术依赖项存在,本身并不添加独立的游戏内容。
依赖项
Forge / NeoForge
Fabric
给玩家和整合包用户
Mebahel's API 是那些使用其共用系统的模组的依赖项。在大多数情况下,玩家不会直接与其交互。
根据使用该 API 的模组不同,它可以提供诸如干燥结构生成、动画自定义箱子、个人战利品、同步容器行为、改进的自定义实体移动以及由 Mebahel 模组共享的配置界面等功能。
游戏内配置
当世界正在运行时,Minecraft 选项界面会包含一个按钮,用于打开兼容的 Mebahel 模组的配置菜单。每个支持的模组都会显示其名称、版本、作者、描述和图标。无需手动编辑配置文件即可更改其设置。
更改会通过 API 进行检查并发送到服务器,从而允许受支持的设置在多人游戏中保持同步。配置按钮仅在世界活跃时出现,因此 Minecraft 启动时主菜单保持不变。
Mebahel Mod Menu 选择 : 
Mebahel Mod Menu 配置 : 
结构去水
结构可以在生成后使用 API 移除水和被水浸湿的状态。这对于地牢、废墟以及其他可能与海洋、河流、洞穴或含水层相交的结构非常有用。
自定义箱子
使用箱子框架的模组可以提供具有以下功能的自定义容器:
- 开合动画
- 自定义音效和屏幕
- 以服务器为主的库存处理
- 多人游戏安全的同步机制
- 可选的每位玩家专属战利品
当启用个人战利品时,每位玩家会从配置的战利品表中获得自己生成的库存,而不是共享相同的箱子内容。
实体移动
自定义实体可以使用共用的移动工具进行战斗定位,包括横移、目标过近时后退、面向目标的旋转、跳跃辅助以及防卡住处理。
安装
当其他模组将其列为必需依赖项时,请安装 Mebahel's API。
它必须存在于依赖它的模组的相应环境中。如果在安装了依赖模组的情况下移除该 API,可能会导致这些模组无法加载或正常运行。
给模组开发者
Mebahel's API 为 Fabric 模组之间共享的系统提供了可复用的基础。目的是将通用行为保留在一个类库中,而不是在每个项目中维护单独的实装。
目前 API 暴露的主要系统包括:
- 结构去水
- 动画自定义箱子的基础实现
- 个人和共享箱子库存
- 自定义容器的屏幕和屏幕处理器支持
- 实体移动和战斗定位工具
- 游戏内配置屏幕的注册、验证和同步
配置框架
模组可以向 Mebahel's API 注册自己的配置屏幕。共享菜单会发现所有已注册的 Mebahel 模组,并为玩家提供一个一致的地方来管理支持中的设置,而无需在游戏过程中频繁切换。
该框架处理客户端屏幕、服务器通信、验证结果以及提交更改后显示的反馈。各个模组仍负责定义其设置并决定哪些值是有效的。
开发者安装
将 API 仓库和依赖项添加到你的 Fabric 项目中。
Maven 仓库
repositories {
maven {
name = "GitLab-Mebahel"
url = uri("https://gitlab.com/api/v4/projects/77311613/packages/maven")
}
}
依赖项
dependencies {
modImplementation "net.mebahelsapi:mebahels-api:<version>"
}
fabric.mod.json
{
"depends": {
"mebahels-api": "*"
}
}
结构去水处理程序
去水处理程序旨在确保结构在生成后保持干燥。
它可以:
- 移除生成块的水浸湿状态
- 清除处理区域内结构内部的水
- 与基于模板的结构生成配合工作
- 在放置后执行清理工作,无需在每个结构中编写自定义逻辑
用法
将处理程序添加到相关的结构处理器配置中:
"processors": "mebahelsapi:water_removal_processor"
清理工作在结构放置后自动处理,并在服务器端运行。
自定义箱子框架
箱子框架为需要动画、同步、自定义音效或多人游戏特定库存行为的自定义容器提供了基础实现。
它包括对以下内容的支持:
- GeckoLib 的打开、关闭和生成动画
- 自定义的开箱与合箱音效
- 自定义屏幕(Screen)和屏幕处理器(Screen Handler)
- 以服务器为权威的容器逻辑
- 多人游戏同步
- 为每位玩家单独生成的个人战利品
- 不使用个人战利品时的标准共享库存
个人战利品
当配置了战利品表时,箱子可以为每位玩家生成独立的库存。战利品仅针对该玩家生成一次,并与其他玩家看到的库存独立存储。
这适用于地牢奖励、Boss宝箱或多玩家结构,其中每个玩家都应能领取属于自己的战利品。
共享库存
当未使用个人战利品表时,箱子作为共享容器运行,所有玩家访问同一个库存。
方块实体示例
public class DwemerChestBlockEntity extends BaseChestBlockEntity {
public DwemerChestBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.DWEMER_CHEST_ENTITY, pos, state, 36);
}
@Override
protected Text getChestTitle() {
return Text.translatable("block.mebahelcreaturesdwarven.dwemer_chest");
}
@Override
protected String getLogPrefix() {
return "[DwemerChest]";
}
@Override
@Environment(EnvType.CLIENT)
public void playOpenSound() {
playChestSound(ModSounds.DWARVEN_CHEST_OPEN);
}
@Override
@Environment(EnvType.CLIENT)
public void playCloseSound() {
playChestSound(ModSounds.DWARVEN_CHEST_CLOSE);
}
@Override
protected boolean isMultiplayerEnabled() {
return ModMultiplayerChest.turnOnMultiplayerDraugrChest;
}
}
方块示例
public class DwemerChestBlock extends BaseChestBlock {
public DwemerChestBlock(AbstractBlock.Settings settings) {
super(
settings,
() -> ModBlockEntities.DWEMER_CHEST_ENTITY,
DwemerChestBlockEntity::new
);
}
@Override
protected boolean isMultiplayerEnabled() {
return ModMultiplayerChest.turnOnMultiplayerDraugrChest;
}
}
MovementUtil
MovementUtil 包含用于自定义实体移动和战斗定位的可复用辅助工具。它主要面向远程生物、Boss、构造体以及其他需要比基础导航目标更多控制权的实体。
典型用途包括:
- 保持实体朝向其目标
- 检测并恢复因卡住导致的移动停滞
- 维持战斗距离
- 围绕目标横向移动
- 当目标靠得太近时撤退
- 辅助跨越小型障碍物
移动和攻击时机可以分开处理,从而使动画和攻击与定位逻辑保持独立。
射击目标示例
public class DraugrArcherShootingGoal extends Goal {
private final DraugrArcherEntity actor;
private final MovementUtil movementUtil;
private final double STRAFE_DISTANCE = 8;
public DraugrArcherShootingGoal(DraugrArcherEntity actor) {
this.actor = actor;
this.movementUtil = new MovementUtil(this.actor);
}
@Override
public void tick() {
if (actor.isUsingPotion() || actor.getHealTicks() > 0) {
actor.setShooting(false);
actor.getNavigation().stop();
return;
}
LivingEntity target = this.actor.getTarget();
if (target == null || !target.isAlive()) {
this.stop();
return;
}
double distanceToTarget = this.actor.distanceTo(target);
movementUtil.lookAtTarget(target, actor);
movementUtil.checkIfStuck(target, actor);
if (distanceToTarget <= STRAFE_DISTANCE) {
movementUtil.moveBackward(target, actor);
} else {
movementUtil.strafeAroundTarget(target, actor);
}
// 射击逻辑单独处理
}
}
一个典型的目标可以验证目标、更新旋转角度、执行防卡住处理、根据距离选择移动方式,然后单独处理攻击时机。
被以下项目使用
Mebahel's API 作为共享库,被依赖这些系统的 Mebahel 模组所使用。
将这些功能保留在公共依赖项中,使得可以在多个项目中复用修复和改进,而无需维护重复的实现。
当前状态
Mebahel's API 与其依赖的模组一起积极维护。当额外的共享系统在超过一个项目中具有实用性时,可能会将其移入 API。
加入社区并在 Discord 上关注开发动态:
Mebahel's API
Shared systems and utilities used by Mebahel mods.
Mebahel's API is a Fabric library that provides common systems used across several Mebahel projects. It contains reusable code for structure processing, custom containers, multiplayer loot handling, entity movement, and other features that would otherwise need to be implemented separately in each mod.
The mod is primarily a technical dependency and does not add standalone gameplay content by itself.
Dependencies
Forge / NeoForge
Fabric
For Players and Modpack Users
Mebahel's API is installed as a dependency for mods that use its shared systems. In most cases, players do not interact with it directly.
Depending on the mod using the API, it can provide features such as dry structure generation, animated custom chests, personal loot, synchronized container behavior, improved movement for custom entities, and configuration screens shared by Mebahel mods.
In Game Configuration
When a world is running, the Minecraft options screen includes a button that opens the configuration menu for compatible Mebahel mods. Each supported mod appears with its name, version, author, description, and icon. Its settings can be changed without editing configuration files by hand.
Changes are checked and sent to the server through the API, allowing supported settings to stay synchronized in multiplayer. The configuration button only appears while a world is active, so the main menu remains unchanged when Minecraft starts.
Mebahel Mod Menu selection : 
Mebahel Mod Menu configuration : 
Structure Water Removal
Structures can use the API to remove water and waterlogged states after generation. This is useful for dungeons, ruins, and other structures that may intersect oceans, rivers, caves, or aquifers.
Custom Chests
Mods using the chest framework can provide custom containers with features such as:
- Animated opening and closing
- Custom sounds and screens
- Server-authoritative inventory handling
- Multiplayer-safe synchronization
- Optional personal loot for each player
When personal loot is enabled, each player receives their own generated inventory from the configured loot table instead of sharing the same chest contents.
Entity Movement
Custom entities can use shared movement utilities for combat positioning, including strafing, retreating when a target is too close, target-facing rotation, jump assistance, and anti-stuck handling.
Installation
Install Mebahel's API when another mod lists it as a required dependency.
It must be present in the appropriate environment for the mod that depends on it. Removing the API while dependent mods are installed can prevent them from loading or functioning correctly.
For Mod Developers
Mebahel's API provides reusable foundations for systems shared between Fabric mods. The goal is to keep common behavior in one library instead of maintaining separate implementations in every project.
The main systems currently exposed by the API include:
- Structure water removal
- Animated custom chest foundations
- Personal and shared chest inventories
- Screen and screen handler support for custom containers
- Entity movement and combat positioning utilities
- Registration, validation, and synchronization for in game configuration screens
Configuration Framework
Mods can register their own configuration screen with Mebahel's API. The shared menu discovers every registered Mebahel mod and gives players one consistent place to manage supported settings while they are playing.
The framework handles the client screen, server communication, validation results, and feedback shown after a change is submitted. Individual mods remain responsible for defining their settings and deciding which values are valid.
Developer Installation
Add the API repository and dependency to your Fabric project.
Maven Repository
repositories {
maven {
name = "GitLab-Mebahel"
url = uri("https://gitlab.com/api/v4/projects/77311613/packages/maven")
}
}
Dependency
dependencies {
modImplementation "net.mebahelsapi:mebahels-api:<version>"
}
fabric.mod.json
{
"depends": {
"mebahels-api": "*"
}
}
Structure Water Removal Processor
The water removal processor is intended for structures that should remain dry after generation.
It can:
- Remove waterlogged states from generated blocks
- Clear water inside the processed structure area
- Work with template-based structure generation
- Perform cleanup after placement without requiring custom logic in every structure
Usage
Add the processor to the relevant structure processor configuration:
"processors": "mebahelsapi:water_removal_processor"
The cleanup is handled automatically after structure placement and runs on the server side.
Custom Chest Framework
The chest framework provides a base implementation for custom containers that need animation, synchronization, custom sounds, or multiplayer-specific inventory behavior.
It includes support for:
- GeckoLib open, close, and spawn animations
- Custom opening and closing sounds
- Custom screens and screen handlers
- Server-authoritative container logic
- Multiplayer synchronization
- Personal loot generated separately for each player
- Standard shared inventories when personal loot is not used
Personal Loot
When a loot table is configured, the chest can generate a separate inventory for each player. Loot is generated once for that player and stored independently from the inventories seen by other players.
This is useful for dungeon rewards, boss chests, or multiplayer structures where every player should be able to claim their own loot.
Shared Inventory
When no personal loot table is used, the chest behaves as a shared container and all players access the same inventory.
Example Block Entity
public class DwemerChestBlockEntity extends BaseChestBlockEntity {
public DwemerChestBlockEntity(BlockPos pos, BlockState state) {
super(ModBlockEntities.DWEMER_CHEST_ENTITY, pos, state, 36);
}
@Override
protected Text getChestTitle() {
return Text.translatable("block.mebahelcreaturesdwarven.dwemer_chest");
}
@Override
protected String getLogPrefix() {
return "[DwemerChest]";
}
@Override
@Environment(EnvType.CLIENT)
public void playOpenSound() {
playChestSound(ModSounds.DWARVEN_CHEST_OPEN);
}
@Override
@Environment(EnvType.CLIENT)
public void playCloseSound() {
playChestSound(ModSounds.DWARVEN_CHEST_CLOSE);
}
@Override
protected boolean isMultiplayerEnabled() {
return ModMultiplayerChest.turnOnMultiplayerDraugrChest;
}
}
Example Block
public class DwemerChestBlock extends BaseChestBlock {
public DwemerChestBlock(AbstractBlock.Settings settings) {
super(
settings,
() -> ModBlockEntities.DWEMER_CHEST_ENTITY,
DwemerChestBlockEntity::new
);
}
@Override
protected boolean isMultiplayerEnabled() {
return ModMultiplayerChest.turnOnMultiplayerDraugrChest;
}
}
MovementUtil
MovementUtil contains reusable helpers for custom entity movement and combat positioning. It is mainly intended for ranged mobs, bosses, constructs, and other entities that need more control than a basic navigation goal provides.
Typical uses include:
- Keeping an entity facing its target
- Detecting and recovering from movement stalls
- Maintaining combat distance
- Strafing around a target
- Retreating when a target gets too close
- Assisting movement over small obstacles
Movement and attack timing can be handled separately so animations and attacks remain independent from positioning logic.
Example Shooting Goal
public class DraugrArcherShootingGoal extends Goal {
private final DraugrArcherEntity actor;
private final MovementUtil movementUtil;
private final double STRAFE_DISTANCE = 8;
public DraugrArcherShootingGoal(DraugrArcherEntity actor) {
this.actor = actor;
this.movementUtil = new MovementUtil(this.actor);
}
@Override
public void tick() {
if (actor.isUsingPotion() || actor.getHealTicks() > 0) {
actor.setShooting(false);
actor.getNavigation().stop();
return;
}
LivingEntity target = this.actor.getTarget();
if (target == null || !target.isAlive()) {
this.stop();
return;
}
double distanceToTarget = this.actor.distanceTo(target);
movementUtil.lookAtTarget(target, actor);
movementUtil.checkIfStuck(target, actor);
if (distanceToTarget <= STRAFE_DISTANCE) {
movementUtil.moveBackward(target, actor);
} else {
movementUtil.strafeAroundTarget(target, actor);
}
// Shooting logic handled separately
}
}
A typical goal can validate the target, update rotation, run anti-stuck handling, choose movement based on distance, and then handle attack timing separately.
Used By
Mebahel's API is used as the shared library for Mebahel mods that rely on these systems.
Keeping this functionality in a common dependency makes it possible to reuse fixes and improvements across multiple projects without maintaining duplicate implementations.
Current Status
Mebahel's API is actively maintained alongside the mods that depend on it. Additional shared systems may be moved into the API when they are useful across more than one project.
Join the community and follow development on Discord:
评论 0
登录后参与评分
还没有评论,来抢沙发吧