ProbeJS Legacy
是官方 ProbeJS 放弃维护的 KubeJS 版本的一个非官方延续项目。
使用方法
- 你当然需要安装 ProbeJS Legacy。
- 进入单人世界。使用
/probejs dump 导出由 ProbeJS Legacy 收集的数据。对于首次用户,在你加入世界时将自动完成此操作。
- 使用 VSCode 打开你的游戏实例文件夹。
- 尽情享受吧!
注意0:输入 @item 或 @block_tag 可查看生成的代码片段。
注意1:游戏实例文件夹是指你可以直接看到 kubejs 文件夹的位置。
注意2:其他支持 TypeScript 类型定义(.d.ts)的 IDE 也应该可以正常工作。
新功能
(与 ProbeJS 相比)
-
模拟 Internal
- ProbeJS Legacy 现在会生成一个
Internal 命名空间,允许用户轻松地从 ProbeJS 6 或 ProbeJS Legacy 3 迁移。
- 示例:
Internal.ItemStack 和 Internal.ItemStack_
-
更好的参数命名
- 与 TypeScript 冲突的参数名现在会以更好的方式进行重命名。
- 如果方法/构造函数中的参数名采用
arg123 格式,它们将被重命名为根据其类型生成的新名称。
示例:
"mayUseItemAt"(arg0: $BlockPos$$Type, arg1: $Direction$$Type, arg2: $ItemStack$$Type): boolean
将重命名为
"mayUseItemAt"(blockPos0: $BlockPos$$Type, direction1: $Direction$$Type, itemStack2: $ItemStack$$Type): boolean
-
改进的 $Class<T>
- ProbeJS 会将
$Class<T> 转换为 typeof T,但忽略了本不应这样做的许多情况。ProbeJS Legacy 使其更加正确。
- 一些基本类,例如
java.lang.String 和 java.lang.Character,现在可以被导出。
$Class<T> 中的 T 现在实际上可用于类型提示。
-
更好的 instanceof
- ProbeJS Legacy 现在可以正确支持
obj instanceof $SomeClass,其中 $SomeClass 是通过 java(...) 或 Java.loadClass(...) 加载的类。
示例:
const $BoatItem = java("some.path.to.BoatItem")
let item = Item.of("boat").item; // 这里 `item` 的类型是 `$Item`
if (item instanceof $BoatItem) {
// 这里 `item` 的类型可以推断为 `$BoatItem`
}
-
字段 Bean 化
- 某些字段将被转换为 getter+setter,以便为 TypeWrapper 提供更好的支持
- 考虑一个具有如下字段的
obj:block: $Block,而在 KubeJS 中 obj.block = "minecraft:stone" 是有效的语法。此前没有类型支持,但现在 ProbeJS Legacy 可以正确地支持它。
-
类型文件的共享
- 通过提取转储类中的公共部分,总类型文件的大小可以比之前小得多。
- 另一个好处是 TS 服务器现在可以在 3 种脚本类型之间重用公共类型定义,从而提升 IDE 性能。
-
更好的注释格式化
- 前后空白行现在将被忽略
- 如果只有一行有效内容,注释将格式化为单行
-
仅客户端/服务端方法(由 @OnlyIn 标记)将带有注释说明其为仅服务端或仅客户端。
-
包含过多模块的 xxx.d.ts 文件现在会自动拆分为较小的文件,以提供更好的 IDE 性能。
-
声明文件中的方法/字段现在按自然顺序排序。
-
global 解析:现在可以解析你放入 global 的值。通过 'global' Resolving Depth 配置项设置解析深度。
-
以及许多内部更改。如果我全部写下来,这个 Readme 肯定会太长。
收集数据
KubeJS 事件
对于 1.16.5,ProbeJS Legacy 会记录所有已发布的事件。如果你找不到某些常用事件,请在转储数据之前尝试触发它们。例如:block.place 事件是在放置方块时触发的。
对于 1.20.1,所有注册的 KJS 事件都会自动转储,无需手动触发。
Forge 事件
ProbeJS Legacy 会记录所有 Forge 事件,无论它们是否已被发布。此行为可以通过 Class Scanner(类扫描器)配置进行修改。
Java 类
ProbeJS Legacy 将使用多种方法来收集 Java 类。
这些类将被记录:
-
手动加载的类,即通过 java(...) 或 Java.loadClass(...) 加载的类。
-
JS 绑定引用的类,例如 AABB 和 Text。
-
已知类引用的类,例如 ItemStack.class 引用了 Item.class。
-
注册表对象,例如原版船只的 BoatItem。默认情况下会跳过非原版的对象,可以通过 Registry Object Filter(注册表对象过滤器)配置进行修改。
-
来自某些模组的类。参见 Mods with forced Full Scanning(强制全扫描模组)配置。
-
从缓存文件读取的类。该缓存文件保存至 <你的实例文件夹>/.probe/classes.txt。
-
通过类扫描器找到的类。详见 Class Scanner 配置。
为什么
起初,我只想找一份 KubeJS 脚本编写的文档或辅助工具,这样我在开发 Enlightend6Expert()时就不必再经历那种痛苦了。
但在研究之后,我意识到尽管 1.16.5 是最热门的模组版本之一,它甚至没有一个合适的 KubeJS 辅助模组。
于是就有了这个为 1.16.5 制作的 ProbeJS 分支。
这是我的第一个 Java 项目,也是我的第一个 Minecraft 模组项目。说实话,ProbeJS 对我来说这样的编程新手来说太难了。不过幸运的是,我成功了。
本项目采用与原始 ProbeJS 相同的 LGPLv3 许可证。
ProbeJS Legacy
is an unofficial continuation of ProbeJS for KubeJS versions abandoned by official ProbeJS.
Usage
- You need to install ProbeJS Legacy, obviously.
- Enter a singleplayer world. Use
/probejs dump to export datas gathered by ProbeJS Legacy. For first-time users, this will be done automatically when you join the world.
- Open your game instance folder using VSCode.
- Enjoy!
Note0: type @item or @block_tag to see snippets generated.
Note1: game instance folder is where you can see the kubejs folder directly.
Note2: Other IDEs with support for TypeScript typing (.d.ts) should also work.
New Features
(Compared to ProbeJS)
-
Simulated Internal
- ProbeJS Legacy will now generate a
Internal namespace, allowing users to migrate from ProbeJS 6 or ProbeJS Legacy 3 easily.
- Example:
Internal.ItemStack and Internal.ItemStack_
-
Better Param Naming
- Param names that conflict with TypeScript will now be renamed in a better way.
- Param names in Method/Constructor, if in
arg123 format, will be renamed to a new name generated from its type.
Example:
"mayUseItemAt"(arg0: $BlockPos$$Type, arg1: $Direction$$Type, arg2: $ItemStack$$Type): boolean
will be renamed to
"mayUseItemAt"(blockPos0: $BlockPos$$Type, direction1: $Direction$$Type, itemStack2: $ItemStack$$Type): boolean
-
Better $Class<T>
- ProbeJS will transform
$Class<T> into typeof T, but ignoring many conditions where this should not be done. ProbeJS Legacy makes it more correct.
- Some basic classes, for example
java.lang.String and java.lang.Character. can now be dumped.
- The
T in $Class<T> is now actually usable for type hint.
-
better instanceof
- ProbeJS Legacy can now properly support
obj instanceof $SomeClass, where $SomeClass is a class loaded via java(...) or Java.loadClass(...).
Example:
const $BoatItem = java("some.path.to.BoatItem")
let item = Item.of("boat").item; // here the type of `item` is `$Item`
if (item instanceof $BoatItem) {
// here the type of `item` can be inferred to `$BoatItem`
}
-
Field Beaning
- Some fields will be transformed into getter+setter, in order to provide better support for TypeWrapper
- Consider a
obj with a field like this: block: $Block, and obj.block = "minecraft:stone" is a valid syntax in KubeJS. This had no typing support before, but now ProbeJS Legacy can support it properly.
-
Typing files sharing
- By extracting common parts in dumped classes, the total typing files size can be much smaller than before.
- Another benefits is that TS server can now reuse common typings between 3 script types, improving IDE performance.
-
Better comment formatting
- blank lines at the front/back will now be ignored
- comments will be formatted as one line if there's only one valid line
-
Side only methods (marked by @OnlyIn) will have comments telling you that it's server-only or client-only.
-
xxx.d.ts file with too many modules in it will now be split into smaller files automatically, providing better IDE performance
-
Method/Field in declaration files are now naturally sorted.
-
gloabl resolving: values you put into global can be resolved now. Configure resolving depth via 'global' Resolving Depth config.
-
And many internal changes. This Readme will certainly be too long if I write them all down.
Collecting data
KubeJS Event
For 1.16.5, ProbeJS Legacy will record all posted event. If you're unable to find some common events, try triggering it before dumping data. Example: block.place event is triggered by placing a block.
For 1.20.1, all registered KJS events will be dumped automatically, no need for triggering.
Forge Event
ProbeJS Legacy will record all Forge events, regardless of whether they have been posted or not. This behaviour can be altered via Class Scanner config.
Java Classes
ProbeJS Legacy will use multiple approaches for collecting Java classes.
These classes will be recorded:
- Classes loaded manually, aka those loaded via
java(...) or Java.loadClass(...)
- Classes referenced by JS bindings, for example
AABB and Text.
- Classes references by known classes, for example
Item.class referenced by ItemStack.class.
- Registry objects, for example
BoatItem for vanilla boats. By default this will skip non-vanilla objects, and can be altered via Registry Object Filter config.
- Classes from certain mods. See
Mods with forced Full Scanning config.
- Classes read from cache file. The cache file is saved to
<your instance folder>/.probe/classes.txt.
- Classes found by class scanner. See
Class Scanner config.
Why
Initially, all I want to do is just find some sort of doc or helper for KubeJS script writing, so that I won't need to feel such pain in the arse when developing Enlightend6Expert() .
But after some research, I realized that 1.16.5, despite being one of the hottest modded versions, didn't even have a proper KubeJS helper mod.
So there it is, a ProbeJS fork for 1.16.5.
This is my first Java project and first Minecraft Mod project, and to be honest, ProbeJS is too tough for a coding noob like me. Thankfully I made it.
This project is licensed under LGPLv3, the same as the original ProbeJS.
评论 0
登录后参与评分
还没有评论,来抢沙发吧