Getting Started
Instillation
Install the mod and its two dependencies Architectury and Rhino.
Make you use the most resent version of each mods for your version.
If you are using 1.16 fabric then use this instead.
When you first install KubeJS, you will need to launch Minecraft with the mods (and the game not crashing) to generate the some folders and files.
The kubejs folder
Finding it
Everything you do in KubeJS in located in the kubejs folder in your instance.
polymc > instances > instance name > minecraft > kubejs
In CurseForge launcher the file structure will look like curseforge > minecraft > instances > instance name > kubejs
In both of these cases the instance name is the name of the instance
From now on this will be referenced as the kubejs folder.
The contents of it
startup_scripts
/kubejs reload_startup_scripts
To reload all the code you must restart the game
client_scripts
/kubejs reload client_scripts
Can reload all the code in client_scripts with F3+T
server_scripts
/reload)
Used for modifying:
/kubejs reload server_scripts
Can be all the code in server_scripts with /reload
exported
config
assets
/kubejs reload lang
Read more about it here.
data
/reload
Read more about it here.
README.txt
You can find type-specific logs in logs/kubejs/ directory
Other Useful Tools
Code is just a language that computers can understand. However, the grammar of the language, called syntax for code, is very precise. When you code has a syntactical error, the computer does not know what to do and will probably do something that you do not desire.
With KubeJS we will be writing a lot of code, so it important to avoid these errors. Luckily, there are tools called code editors, that can help us write code correctly.
We recommend installing Visual Studio Code as it is light-ish and has great built in JS support. Now when you edit you java script files, it will not only warn you when you make most syntactical errors, but also help you make them in the first place.
Writing Your First Script
If you have launched the game at least once before you will find kubejs/server_scripts/example_server_script.js It looks like this:
// priority: 0
settings.logAddedRecipes = true
settings.logRemovedRecipes = true
settings.logSkippedRecipes = false
settings.logErroringRecipes = true
console.info('Hello, World! (You will see this line every time server resources reload)')
onEvent('recipes', event => {
// Change recipes here
})
onEvent('item.tags', event => {
// Get the #forge:cobblestone tag collection and add Diamond Ore to it
// event.get('forge:cobblestone').add('minecraft:diamond_ore')
// Get the #forge:cobblestone tag collection and remove Mossy Cobblestone from it
// event.get('forge:cobblestone').remove('minecraft:mossy_cobblestone')
})
Lets break it down:
settings.logRemovedRecipes = true
settings.logSkippedRecipes = false
settings.logErroringRecipes = true
recipes event, and will run the code inside when and only when the recipes event is triggered
This is triggered when server resources reload
/reload command is used
// Change recipes here
// will be considered a comment and will not be run
Used for taking notes as you write the code
})
onEvent('item.tags', event => {
// Get the #forge:cobblestone tag collection and add Diamond Ore to it
// event.get('forge:cobblestone').add('minecraft:diamond_ore')
// Get the #forge:cobblestone tag collection and remove Mossy Cobblestone from it
// event.get('forge:cobblestone').remove('minecraft:mossy_cobblestone')
})
item.tags event
You can find the list of all event here
Finally Writing Code For Real
Lets start off by adding a recipe to craft flint from three gravel.
To do so, insert this code right after the recipes event.
event.shapeless("flint", ["gravel", "gravel", "gravel"])
It should look like this:
// priority: 0
settings.logAddedRecipes = true
settings.logRemovedRecipes = true
settings.logSkippedRecipes = false
settings.logErroringRecipes = true
console.info('Hello, World! (You will see this line every time server resources reload)')
onEvent('recipes', event => {
// Change recipes here
event.shapeless("flint", ["gravel", "gravel", "gravel"])
})
onEvent('item.tags', event => {
// Get the #forge:cobblestone tag collection and add Diamond Ore to it
// event.get('forge:cobblestone').add('minecraft:diamond_ore')
// Get the #forge:cobblestone tag collection and remove Mossy Cobblestone from it
// event.get('forge:cobblestone').remove('minecraft:mossy_cobblestone')
})
Now lets test it!
Run the command /reload in game, then try crafting three gravel together in any order.
But how does it work?
onEvent('recipes', event => {...
create:flour , if it is from a different mod (flint is the same as minecraft:flint, and both are valid)"
There you go! You can make custom shapeless recipes!
If you want to make other types of recipes, learn about it here, and if you have an addon that adds more recipe types, loot at its mod page, or here.