Skip to main content

Using ProbeJS

ProbeJS is an add-on that is built exclusively to help you program.

What it does:

It generates documentation files from digging around in he game code itself. So you get all the methods, not only from KubeJS, but also from base Minecraft and ones added by your modloader and ones from all the other mods in you install. Not only can you view these docs, but they are also formatted in a way that an sufficiently advanced code editor, like VSCode, can understand. So you will now get more relevant code suggestions too.

Installation:

Find ProbeJS on the 3rd Party addons list and download the relevant version to you.
Once you've installed it and relaunched your game, run the command /probejs dump.
Now you will need to wait a little while, but after some time, you should see a message altering you that the dump is complete.

You are now done with ProbeJS and can uninstall it if you choose, or you could keep it around to use occasionally to update your docs. But try to remember to uninstall before release

What just happened?

You can now look and see that there is a new folder located at instance/kubejs/probe and inside of here there are a more folders and files. These are your docs.

Setting up VS Code

  1. In VS Code select file > open folder
  2. This opens up a file explore window, select the KubeJS folder (instance/kubejs) and choose select folder.

Your done!

Usage

Properties and Methods of a Class

To know the methods of a class just type in the class name, like Item or BlockProperties, then type a . now you will see a list of the public methods and properties.

ProbeJS will not display the beaned assessors and mutators methods. So if you see a .getFoo() remeber that you can use .foo and .setFoo(bar) then you can use .foo = bar.

Searching by Keyword

If you are in VS Code press the explorer button in the top-ish left to open up the explorer pane.

Now navigate to probe > generated > globals.d.ts.
Press Ctrl + F and a little search window should pop up in your editor.
Now type in you key word and look through all the matches.

Tips

If you append class  to the front and   to the end then you will look for classes so like Item has 8635 result for me, but if I type class Item then the one I want!

In the events.documented.d.ts file you will find most all the events with descriptions of what they do.

In events.d.ts you will find even more events but less information about them.

In constants.d.ts you can see different pieces that you can use where ever.

 

If you want to find the methods of an event, say item.pickup find it in one of the files (In this case events.documented.d.ts) and here is the line describing it:

declare function onEvent(name: "item.pickup", handler: (event: Internal.ItemPickupEventJS) => void);

Look closely and find Internal.ItemPickupEventJS. Since it says Internal, we will look in the the globals.d.ts file, but if it says Registry then we use registries.d.ts.

Now we will go to the generated file and search ItemPickupEventJS.
Then we find:

    /**
    * Fired when an item is about to be picked up by the player.
    * @javaClass dev.latvian.mods.kubejs.item.ItemPickupEventJS
    */
    class ItemPickupEventJS extends Internal.PlayerEventJS {
        getItem(): Internal.ItemStackJS;
        getEntity(): Internal.EntityJS;
        getItemEntity(): Internal.EntityJS;
        canCancel(): boolean;
        get item(): Internal.ItemStackJS;
        get itemEntity(): Internal.EntityJS;
        get entity(): Internal.EntityJS;
        /**
        * Internal constructor, this means that it's not valid unless you use `java()`.
        */
        constructor(player: Internal.Player, entity: Internal.ItemEntity, stack: Internal.ItemStack);
    }

This means that we can use the methods .getItem() .getEntity() .getItemEntity() .canCancel() .item .itemEntity and .entity.

 

But if we did potion.registry then we get Registry.Potion which brings us to:

    class Potion extends Internal.RegistryObjectBuilderTypes$RegistryEventJS<any> {
        create(id: string, type: "basic"): Internal.PotionBuilder;
        create(id: string): Internal.PotionBuilder;
    }

So we can use event.create("cactus_juice") but that does not do much so we need to follow one step further and go to the potion builder, which you see is Internal.PotionBuilder. Now we search PotionBuilder in globals.d.ts then we see:

    /**
    * @javaClass dev.latvian.mods.kubejs.misc.PotionBuilder
    */
    class PotionBuilder extends Internal.BuilderBase<Internal.Potion> {
        getRegistryType(): Internal.RegistryObjectBuilderTypes<Internal.Potion>;
        effect(effect: Internal.MobEffect_, duration: number, amplifier: number, ambient: boolean, visible: boolean): this;
        effect(effect: Internal.MobEffect_, duration: number, amplifier: number, ambient: boolean, visible: boolean, showIcon: boolean): this;
        effect(effect: Internal.MobEffect_, duration: number, amplifier: number, ambient: boolean, visible: boolean, showIcon: boolean, hiddenEffect: Internal.MobEffectInstance_): this;
        effect(effect: Internal.MobEffect_, duration: number): this;
        effect(effect: Internal.MobEffect_, duration: number, amplifier: number): this;
        effect(effect: Internal.MobEffect_): this;
        addEffect(effect: Internal.MobEffectInstance_): this;
        createObject(): Internal.Potion;
        get registryType(): Internal.RegistryObjectBuilderTypes<Internal.Potion>;
        /**
        * Internal constructor, this means that it's not valid unless you use `java()`.
        */
        constructor(i: ResourceLocation);
    }

Now we see the methods that we can call after this.

So in our code we could write:

onEvent('potion.registry', event => {
  	event.create("cactus_juice").effect("speed",10,5)
})