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 <-> FREE(处于激活状态时)
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
你是这个资源的作者?登录后可认领此资源。
相似资源
缓冲的原始输入和线程化的事件轮询
可定制的鞘翅模组,支持装饰纹饰、旗帜图案等更多功能!
一个用于收集生物掉落物的多区块模组。
显示你正在注视的方块的信息。(适用于 Minecraft 1.16+ 的 Hwyla/Waila 分支)
原版世界生成优化模组
使用 JavaScript 编辑配方、添加自定义物品、编写世界事件!
评论 0
登录后参与评分
还没有评论,来抢沙发吧