
i113w's Camera Lib
提供一个提供RTS风格相机系统的库,该库由Better Mine Team使用。
i113w 的相机库
一个 NeoForge 1.21.1 客户端库,提供完整的 RTS 风格相机系统 —— 包括相机移动、实体框选、右键指令区域、射线检测和高亮渲染。
设计为通过轻量 API 层供其他模组使用(例如 Better Mine Team)。
要求
| 项目 | 版本 |
|---|---|
| Minecraft | 1.21.1 |
| NeoForge | 21.1.209+ |
| Java | 21 |
| 端 | 仅客户端 |
导入库
本地 JAR(将 JAR 放入你模组的 libs/ 目录):
dependencies {
implementation files('libs/i113w_camera_lib-0.0.1.jar')
}
在 META-INF/neoforge.mods.toml 中声明依赖:
[[dependencies."your_mod_id"]]
modId = "i113w_camera_lib"
type = "required"
versionRange = "[0.0.1,)"
ordering = "BEFORE"
side = "CLIENT"
关键接口与类
CameraLibAPI —— 单例入口点
CameraLibAPI api = CameraLibAPI.get();
// 注册你的委托
api.setInteractionDelegate(new MyDelegate());
// 将选中的实体 ID 同步到库(驱动轮廓渲染)
api.setSelectedEntities(Set<Integer> ids);
// 查询悬停的实体(没有则为 -1)
int id = api.getHoveredEntityId();
// 清除选择和悬停状态
api.clearSelection();
IRTSInteractionDelegate —— 注入业务逻辑
public interface IRTSInteractionDelegate {
boolean isSelectable(Entity entity);
ResourceLocation getCursorIcon(@Nullable Entity hoveredEntity, boolean isAttackDragging);
}
通过 CameraLibAPI.get().setInteractionDelegate(impl) 注册。
事件(在 NeoForge.EVENT_BUS 上触发)
RTSBoxSelectEvent —— 左键点击或拖拽框选完成
@SubscribeEvent
public static void onSelect(RTSBoxSelectEvent event) {
List<Entity> candidates = event.getCandidates(); // 已由 isSelectable() 预过滤
}
RTSRightClickEvent —— 右键点击或右键拖拽完成
@SubscribeEvent
public static void onRightClick(RTSRightClickEvent event) {
if (event.isDrag()) {
List<Entity> targets = event.getDragTargets();
} else {
HitResult hit = event.getSingleHitResult(); // BlockHitResult 或 EntityHitResult
}
}
RTSCameraController —— 相机状态
RTSCameraController cam = RTSCameraController.get();
cam.toggleRTSMode(); // 激活 / 停用
cam.toggleCameraStyle(); // 切换 RTS <-> 自由(激活状态下)
cam.isActive(); // 布尔值
cam.reset(); // 强制退出,在登出 / 关卡卸载时使用
相机模式
| 模式 | 视野(FOV) | 缩放 | 偏航旋转 |
|---|---|---|---|
| RTS | 25°(固定) | 滚轮 | 按住 Left Ctrl + 拖拽(按 rtsSnapAngle 吸附) |
| FREE | 标准 | 滚轮(向前移动) | 按住 Left Ctrl + 拖拽(连续) |
高亮渲染
相机激活时,库会自动绘制实体轮廓。消费模组无需编写任何渲染代码 —— 只需保持 CameraLibAPI.setSelectedEntities(...) 同步。
| 颜色 | 条件 |
|---|---|
| 白色 | 实体 ID 在选中集合中 |
| 黄色 | 悬停的实体(不在选中集合中) |
配置
玩家可在 .minecraft/config/i113w_camera_lib-client.toml 中调整的值:
| 键 | 默认值 | 描述 |
|---|---|---|
rtsPitchMin / Max |
35 / 45 | RTS 模式下的俯仰角限制范围 |
freePitchMin / Max |
10 / 90 | FREE 模式下的俯仰角限制范围 |
rtsZoomMin / Max |
10 / 80 | RTS 模式下的缩放距离限制 |
rtsZoomSpeedMultiplier |
3.5 | 滚轮缩放灵敏度 |
rtsSnapAngle |
90 | 每次偏航吸附的度数 |
freeRotationSpeed |
5.0 | FREE 模式下的鼠标偏航灵敏度 |
thresholdPx |
20 | 边缘平移触发距离(距屏幕边缘的像素数) |
baseSpeed |
1.0 | WASD 移动速度 |
sprintMultiplier |
2.0 | 按住疾跑键时的速度倍率 |
许可证
MIT —— 见 LICENSE
作者: i113w
正在加载版本记录…
正在加载评论…
评论在新手盒子客户端中发表,这里同步展示。