Introduction 6.1 6.2 - Project-Vyre/another-create-wiki GitHub Wiki

Introduction to KubeJS 6.1-6.2 on Minecraft 1.19.2

Welcome to the another-create-wiki wiki!

This section contains essential information on how to get started with KubeJS on Minecraft 1.19.2.

First step is to install the following:

After KubeJS is installed, run the game once and make a world to generate the kubejs folder which is located in your Minecraft instance folder.

For context, your Minecraft Instance folder will contain the majority of the following folders:

  • config
  • defaultconfig
  • kubejs
  • mods
  • saves
  • screenshots
  • schematics

If you see most of these folders without opening any of them, you are in the right place.

It contains the following folders and a README.txt file.

  • assets
    • Here is where you put your custom item, armor, block and fluid textures.
      • Yes, you can use .json files for custom block models.
      • Yes, you can use .mcmeta files to change how your block is displayed in-game and make another color variant for deepslate for example.
  • client_scripts
    • This is where your scripts related to tooltips, JEI modification and other client side things will go.
  • config
    • This is where you can put defaultoptions.txt so you don't have to use DefaultOptions.
    • Setting the Window Title. That's the client name that shows up in the window on the top left corner if you don't know what that means.
    • Setting the client icon. Must be an .png file exported in 32-bit, otherwise it will cause a JVM crash.
  • data
    • Put the data folder contents of your datapacks in here. It will not work if you have it like: kubejs\data\bigcustomdatapack\
  • exported
    • You don't really need to worry about it. It's just where data dumps like texture atlases are well... dumped.
  • server_scripts
    • This is where the recipe magic happens! Remember to Ctrl + S to save your recipe once it is finished then type /reload.
    • You can also modify item tags, loot tables, and more in here.
  • startup_scripts
    • Scripts for your custom items, blocks, armor and fluids go in here.
    • This is where you can modify item and armor durability.

Also some important guidelines:

  • DO NOT use an existing modID in your recipeID unless if you are overriding it.
  • KubeJS uses slightly different syntax (way of typing "commands" in layman's terms) depending on which version of Minecraft you are using, specifically 1.19.2+ and 1.18.2. I will be skipping 1.16.5 syntax, go bother someone else.
  • For all intents and purposes, the main focus of this tutorial is for adding and removing your own recipes.

Tutorial

  1. Open up Visual Studio Code and click Open Folder and navigate to either your instance folder or just the kubejs folder if you are just going to edit KubeJS stuff after doing modpack configs in the config folder.
  2. Click it, then click the Select Folder button on the bottom right corner. If a prompt says "Do you want to trust the authors of these files?" click yes.
  3. In the server_scripts folder, there should already be a script.js file. Open that via the VSCode Explorer panel where you can see all the kubejs folders. Personally I would organize scripts by mod if you want to easily transfer your scripts without having to delete and remove certain lines of code.

Some More Important Things

Some things I know you will ask about when you are in the KubeJS support channel. If you are a visual learner, this wiki page should be most helpful.

What are events?

  • Here is something that you should know: The word event is simply something that happens. When it comes to being inside the main ServerEvent / onEvent class, the word event can be changed to e to keep it short. Just ensure that it matches so that your events can be fired and be registered in-game. In layman's terms: for example, when the recipes event is triggered in the mod loader, everything inside ServerEvents.recipes() will be read and loaded into the game.

What are strings?

  • Strings are either inside double "quotes" or single 'quotes'. In JavaScript, using single 'quotes' is standard unless if you have a string that contains 'that's' or something similar. In that case.

What are objects, properties, listeners, etc?

  • This is better explained in the code block below. Now, are you in the .js file inside server_scripts? Good. See the gigantic code block below? I'll explain everything through there.
// requires: kubejs_create

/*
This header above tells KubeJS that this script needs KubeJS Create to be installed to work.

If you have pasted this code into Visual Studio Code, then the word event should be in ORANGE 
if you are using the Github Default Dark Theme.

Also I would suggest renaming this file to recipes.js for the sake of identification.
Right-click the file on the left Explorer panel and rename it there for the easiest method.
*/

// Single line comments are indicated with two forward slashes.

/*
Multi line comments are indicated with...
*/

/**
 * Documentation is automatically generated by using two * after the first forward slash.
 * Press Enter to automatically make a new line unless if a function is written below
 * 
 * Functions will be explained later on.
 */

// Directly below is the Server Event listener for the recipes event.
// event => is what triggers everything that has the word "connected"
ServerEvents.recipes(event => {
    /* 
    Type your recipe scripts inside here. Don't forget to right click the background and 
    click Format Document to let Visual Studio Code format your code properly.

    Let's start with the basics with a few **shaped** recipe that you will recognize in-game.
    */
    event.shaped('minecraft:iron_sword', [
        'I',
        'I',
        'S'
    ], {
        I: 'minecraft:iron_ingot',
        S: 'minecraft:stick'
    }).id('minecraft:iron_sword')
    event.shaped('minecraft:bucket', [
        'I I',
        ' I '
    ], {
        I: 'minecraft:iron_ingot'
    }).id('minecraft:bucket')
    event.shaped('8x create:shaft', [
        'A',
        'A'
    ], {
        A: 'create:andesite_alloy'
    }).id('create:crafting/kinetics/shafts')
    event.shaped('minecraft:clock', [
        ' G ',
        'GRG',
        ' G '
    ], {
        G: 'minecraft:gold_ingot',
        R: 'minecraft:redstone'
    }).id('minecraft:clock')
    /*
    Now I know you might be thinking...

    What does this all mean?

    Results are always usually first, with ingredients following.
    Spaces in the single quotation mark grid [] equal empty space.
    The capital letters inside the array [] individually DEFINE where the ingredient is located on the crafting grid.
    The capital letters inside the object {} are what define the item used in that position.

    .id() is what gives your recipe a recipeID and the ability to override existing recipes from
    other mods. Also, as a general guideline you should put this at the very end of your recipe in
    case you have a recipe that keeps ingredients.

    You do not have to use the same letters as the ingredients, it can be anything from 
    A-Z, 0-9, #, etc though Visual Studio Code will show a syntax error.
    */
    event.shaped('create:shaft', [
        '#',
        '#'
    ], {
        '#': 'create:andesite_alloy'
    }).id('kubejs:a_duplicate_recipe_for_the_shaft')
    // above is an example of using non-letter characters as keys.

    // Let's move onto shapeless recipes.
    event.shapeless('create:cogwheel', [
        'create:shaft',
        '#minecraft:planks'
    ]).id('create:crafting/kinetics/cogwheel')
    event.shapeless('create:large_cogwheel', [
        'create:shaft',
        '2x #minecraft:planks'
    ]).id('create:crafting/kinetics/large_cogwheel')
    // unlike shaped recipes, there is nothing to define the location of.
    // simply list your ingredients inside the [array] that comes after the output item string.
    /*
    Let's get started with removing recipes... and your first if statement.
    */
    let remove_recipes = false
    // if this is set to false, the if statement below will be false and thus will not run unless set to true.
    if (remove_recipes) {
        event.remove([
            { output: 'minecraft:stick' }, // I remove all recipes that output sticks!
            {
                mod: 'create',
                input: 'create:andesite_alloy',
                output: 'create:cogwheel'
            } // I remove all recipes from the Create mod that use Andesite Alloy and output Cogwheels!
        ])
    }
})

Advanced Things

Tired of repeating the same things multiple times? Tired of having to edit your code every time a mod is not present yet? This section has that covered.

What are functions?