KubeJS Basics - trulyno/GregTech-Modern GitHub Wiki

KubeJS uses JavaScript in order to modify the game in a (relatively)easy way. Before starting to add content with KubeJS, we'll do a couple of things first:

  1. Chose a set of compatible mods and add KubeJS and ProbeJS as well. ProbeJS will ease the development process.
  2. Launch the game and create a world.
  3. Execute the command /probejs dump. This will collect a lot of data on items and fluids from the game, as well as functions from KubeJS integrations of mods that have it.
  4. Go to the folder of your modpack and open that folder using Visual Studio Code. Also install the ProbeJS extension for VSCode Enter the kubejs folder. You will modify files in the server_scripts, startup_scripts and assets KubeJS is divided into server events and startup events.

Server Events

The server events refer to actions like creation, modification or deletion of recipes. There are other capabilities, but for this guide will focus only on recipes. In the server_scripts folder you will find a file ending in .js. You can open and edit that, or create your own file with the same extension. You can have as many .js files as you want. It is a good practice to organize your scripts in folders. Open a script file and write the following:

ServerEvents.recipes(event => {

});

ServerEvents is the collections of events(or actions) that can happen while a player is in a world(also known as the server). One of the possible events is recipes. Inside the parentheses, event => (){ } is what is called a lambda function(a function without a name). This allows us to access events and modify them. We will modify them in the curly brackets. You can also replace event with e or any other word or letter. For this guide we will use event.

Crafting table recipes

Let's now make a crafting table recipe. There are two types: shaped and shapeless. Let's first look at an example of a shaped recipe:

event.shaped(Item.of('functionalstorage:storage_controller'), [
        'SSS',
        'GCG',
        'SSS'
    ], {
        S: 'minecraft:stone',
        G: '#forge:glass',
        C: '#forge:circuits/lv'
    });

Let's break it down. event.shaped() tells kubejs that the content of the parentheses is a shaped recipe. This will take in 3 arguments separated by commas:

  1. A string or an Item.of() call
  2. An array
  3. An object The string refers to the id of an item. You can get the id by turning on advanced tooltips with the F3 + H shortcut in-game. ProbeJS will help you with autocompletions of ids. The array has 2 or 3 strings incased in brackets, separated by commas.