# Events # List of Events This is a list of all events. It's possible that not all events are listed here, but this list will be updated regularly. Click on event ID to open its class and see information, fields, and methods. Type descriptions: - **Startup**: scripts go into the `/kubejs/startup_scripts/` folder. Startup scripts run once, at startup, on both the client and server. Most events that require registering or modifying something at game start (like custom blocks, items, and fluids) will be Startup events. - **Server**: scripts go into the `/kubejs/server_scripts/` folder. It will be reloaded when you run `/reload` command. Server events are always accessible, even in single-player worlds. Most events that make changes to the world while the game is running (such as breaking blocks, teleporting players, or adding recipes) will go here. - **Server Startup**: same as Server, and the event will be fired at least once when the server loads. - **Client**: scripts go into the `/kubejs/client_scripts/` folder. Will be reloaded when you press `F3+T`. Most changes that are per-client (such as resource packs, Painter, and JEI) are client events. - **Client Startup**: Same as Client, and the event will be fired at least once when the client loads. ### Base KubeJS Events
**Folder** | **Method** | **Cancellable** |
`/startup_scripts/` | `StartupEvents.init` (link) | ❌ |
`/startup_scripts/` | `StartupEvents.postInit` (link) | ❌ |
`/startup_scripts/` | `StartupEvents.registry` (fluid) `StartupEvents.registry` ([block](https://wiki.latvian.dev/books/kubejs/page/custom-blocks "Custom Blocks")) `StartupEvents.registry` ([item](https://mods.latvian.dev/books/kubejs/page/custom-items)) `StartupEvents.registry` (enchantment) `StartupEvents.registry` (mob effects) `StartupEvents.registry` (sound event) `StartupEvents.registry` (block entity type) `StartupEvents.registry` (potion) `StartupEvents.registry` (particle type) `StartupEvents.registry` (painting variant) `StartupEvents.registry` (custom stat) `StartupEvents.registry` (point of interest type) `StartupEvents.registry` (villager type) `StartupEvents.registry` (villager profession) | ❌ |
`/client_scripts/` | `ClientEvents.highPriorityAssets` (link) | ❌ |
`/client_scripts/` | `ClientEvents.init` (link) | ❌ |
`/client_scripts/` | `ClientEvents.loggedIn` (link) | ❌ |
`/client_scripts/` | `ClientEvents.loggedOut` (link) | ❌ |
`/client_scripts/` | `ClientEvents.tick` (link) | ❌ |
`/client_scripts/` | `ClientEvents.painterUpdated` (link) | ❌ |
`/client_scripts/` | `ClientEvents.leftDebugInfo` (link) | ❌ |
`/client_scripts/` | `ClientEvents.rightDebugInfo` (link) | ❌ |
`/client_scripts/` | `ClientEvents.paintScreen` (link) | ❌ |
`/server_scripts/` | `ServerEvents.lowPriorityData` (link) | ❌ |
`/server_scripts/` | `ServerEvents.highPriorityData` (link) | ❌ |
`/server_scripts/` | `ServerEvents.loaded` (link) | ❌ |
`/server_scripts/` | `ServerEvents.unloaded` (link) | ❌ |
`/server_scripts/` | `ServerEvents.tick` (link) | ❌ |
`/server_scripts/` | `ServerEvents.tags` ([link](https://mods.latvian.dev/books/kubejs/page/tags)) | ❌ |
`/server_scripts/` | `ServerEvents.commandRegistry` (link) | ❌ |
`/server_scripts/` | `ServerEvents.command` (link) | ✅ |
`/server_scripts/` | `ServerEvents.customCommand` (link) | ✅ |
`/server_scripts/` | `ServerEvents.recipes` (link) | ❌ |
`/server_scripts/` | `ServerEvents.afterRecipes` (link) | ❌ |
`/server_scripts/` | `ServerEvents.specialRecipeSerializers` (link) | ❌ |
`/server_scripts/` | `ServerEvents.compostableRecipes` (link) | ❌ |
`/server_scripts/` | `ServerEvents.recipeTypeRegistry` (link) | ❌ |
`/server_scripts/` | `ServerEvents.genericLootTables` (link) | ❌ |
`/server_scripts/` | `ServerEvents.blockLootTables` (link) | ❌ |
`/server_scripts/` | `ServerEvents.entityLootTables` (link) | ❌ |
`/server_scripts/` | `ServerEvents.giftLootTables` (link) | ❌ |
`/server_scripts/` | `ServerEvents.fishingLootTables` (link) | ❌ |
`/server_scripts/` | `ServerEvents.chestLootTables` (link) | ❌ |
`/server_scripts/` | `LevelEvents.loaded` (link) | ❌ |
`/server_scripts/` | `LevelEvents.unloaded` (link) | ❌ |
`/server_scripts/` | `LevelEvents.tick` (link) | ❌ |
`/server_scripts/` | `LevelEvents.beforeExplosion` (link) | ✅ |
`/server_scripts/` | `LevelEvents.afterExplosion` (link) | ❌ |
`/startup_scripts/` | `WorldgenEvents.add` (link) | ❌ |
`/startup_scripts/` | `WorldgenEvents.remove` (link) | ❌ |
`/client_scripts/` | `NetworkEvents.fromServer` (link) | ✅ |
`/server_scripts/` | `NetworkEvents.fromClient` (link) | ✅ |
`/startup_scripts/` | `ItemEvents.modification` (link) | ❌ |
`/startup_scripts/` | `ItemEvents.toolTierRegistry` ([link](https://wiki.latvian.dev/books/kubejs/page/custom-tiers#bkmrk-tool-tiers)) | ❌ |
`/startup_scripts/` | `ItemEvents.armorTierRegistry` ([link](https://wiki.latvian.dev/books/kubejs/page/custom-tiers#bkmrk-armour-tiers)) | ❌ |
`/server_scripts/` | `ItemEvents.rightClicked` (link) | ✅ |
`/server_scripts/` | `ItemEvents.canPickUp` (link) | ✅ |
`/server_scripts/` | `ItemEvents.pickedUp` (link) | ❌ |
`/server_scripts/` | `ItemEvents.dropped` (link) | ✅ |
`/server_scripts/` | `ItemEvents.entityInteracted` (link) | ✅ |
`/server_scripts/` | `ItemEvents.crafted` (link) | ❌ |
`/server_scripts/` | `ItemEvents.smelted` (link) | ❌ |
`/server_scripts/` | `ItemEvents.foodEaten` (link) | ✅ |
`/client_scripts/` | `ItemEvents.tooltip` (link) | ❌ |
`/startup_scripts/` | `ItemEvents.modelProperties` (link) | ❌ |
`/client_scripts/` | `ItemEvents.clientRightClicked` (link) | ❌ |
`/client_scripts/` | `ItemEvents.clientLeftClicked` (link) | ❌ |
`/server_scripts/` | `ItemEvents.firstRightClicked` (link) | ❌ |
`/server_scripts/` | `ItemEvents.firstLeftClicked` (link) | ❌ |
`/startup_scripts/` | `BlockEvents.modification` (link) | ❌ |
`/server_scripts/` | `BlockEvents.rightClicked` (link) | ✅ |
`/server_scripts/` | `BlockEvents.leftClicked` (link) | ✅ |
`/server_scripts/` | `BlockEvents.placed` (link) | ✅ |
`/server_scripts/` | `BlockEvents.broken` (link) | ✅ |
`/server_scripts/` | `BlockEvents.detectorChanged` (link) | ❌ |
`/server_scripts/` | `BlockEvents.detectorPowered` (link) | ❌ |
`/server_scripts/` | `BlockEvents.detectorUnpowered` (link) | ❌ |
`/server_scripts/` | `BlockEvents.farmlandTrampled` (link) | ❌ |
`/server_scripts/` | `EntityEvents.death` (link) | ✅ |
`/server_scripts/` | `EntityEvents.hurt` (link) | ✅ |
`/server_scripts/` | `EntityEvents.checkSpawn` (link) | ✅ |
`/server_scripts/` | `EntityEvents.spawned` (link) | ✅ |
`/server_scripts/` | `PlayerEvents.loggedIn` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.loggedOut` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.respawned` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.tick` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.chat` (link) | ✅ |
`/server_scripts/` | `PlayerEvents.decorateChat` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.advancement` (link) | ✅ |
`/server_scripts/` | `PlayerEvents.inventoryOpened` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.inventoryClosed` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.inventoryChanged` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.chestOpened` (link) | ❌ |
`/server_scripts/` | `PlayerEvents.chestClosed` (link) | ❌ |
These events are enabled when certain other mods are present.
##### **Just Enough Items (JEI)****Folder** | **Method** | **Cancellable** |
`/client_scripts/` | `JEIEvents.subtypes` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/JEISubtypesEventJS.java)) | ❌ |
`/client_scripts/` | `JEIEvents.hideItems` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/HideJEIEventJS.java)) | ❌ |
`/client_scripts/` | `JEIEvents.hideFluids` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/HideJEIEventJS.java)) | ❌ |
`/client_scripts/` | `JEIEvents.hideCustom` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/HideCustomJEIEventJS.java)) | ❌ |
`/client_scripts/` | `JEIEvents.removeCategories` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/RemoveJEICategoriesEvent.java)) | ❌ |
`/client_scripts/` | `JEIEvents.removeRecipes` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/RemoveJEIRecipesEvent.java)) | ❌ |
`/client_scripts/` | `JEIEvents.addItems` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/AddJEIEventJS.java)) | ❌ |
`/client_scripts/` | `JEIEvents.addFluids` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/AddJEIEventJS.java)) | ❌ |
`/client_scripts/` | `JEIEvents.information` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/jei/InformationJEIEventJS.java)) | ❌ |
**Folder** | **Method** | **Cancellable** |
`/client_scripts/` | `REIEvents.hide` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/common/src/main/java/dev/latvian/mods/kubejs/integration/rei/HideREIEventJS.java)) | ❌ |
`/client_scripts/` | `REIEvents.add` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/common/src/main/java/dev/latvian/mods/kubejs/integration/rei/AddREIEventJS.java)) | ❌ |
`/client_scripts/` | `REIEvents.information` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/common/src/main/java/dev/latvian/mods/kubejs/integration/rei/InformationREIEventJS.java)) | ❌ |
`/client_scripts/` | `REIEvents.removeCategories` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/common/src/main/java/dev/latvian/mods/kubejs/integration/rei/RemoveREICategoryEventJS.java)) | ❌ |
`/client_scripts/` | `REIEvents.groupEntries` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/common/src/main/java/dev/latvian/mods/kubejs/integration/rei/GroupREIEntriesEventJS.java)) | ❌ |
**Folder** | **Method** | **Cancellable** |
`/server_scripts/` | `GameStageEvents.stageAdded` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/gamestages/GameStageEventJS.java)) | ❌ |
`/server_scripts/` | `GameStageEvents.stageRemoved` ([source](https://github.com/KubeJS-Mods/KubeJS/blob/1.19/main/forge/src/main/java/dev/latvian/mods/kubejs/integration/forge/gamestages/GameStageEventJS.java)) | ❌ |
This page is still under development. It is not complete, and subject to change at any time.
The recipe event is a server event.
### Contents - [How Recipes & Callbacks Work](#bkmrk-recipes%2C-callbacks%2C-) - [Adding Recipes](#bkmrk-adding-recipes) - [Shaped](#bkmrk-shaped) - [Shapeless](#bkmrk-%C2%A0) - [Smithing](#bkmrk-smithing) - [Smelting & other Cooking](#bkmrk-smelting-%26-cooking) - [Stonecutting](#bkmrk-stonecutting) - [Custom (JSON)](#bkmrk-custom%2Fmodded-json-r) - [Removing Recipes](#bkmrk-removing-recipes) - [Modifying & Replacing Recipes](#bkmrk-modifying-%26-replacin) - [Helpers, Efficiency and Advanced Ingredients](#bkmrk-%C2%A0-0) (a.k.a. "how to avoid repeating yourself") ### Recipes, Callbacks, and You [↑](#bkmrk-contents) The recipe event can be used to add, remove, or replace recipes. Any script that modifies recipes should be placed in the `kubejs/server_scripts` folder, and can be reloaded at any time with `/reload`. Any modifications to the recipes should be done within the context of a `recipes` event. This means that we need to register an "event listener" for the `ServerEvents.recipes` event, and give it some code to execute whenever the game is ready to modify recipes. Here's how we tell KubeJS to execute some code whenever it's recipe time: ```javascript /* * ServerEvents.recipes() is a function that accepts another function, * called the "callback", as a parameter. The callback gets run when the * server is working on recipes, and then we can make our own changes. * When the callback runs, it is also known as the event "firing". */ ServerEvents.recipes(event => { //listen for the "recipes" server event. // You can replace `event` with any name you like, as // long as you change it inside the callback too! // This part, inside the curly braces, is the callback. // You can modify as many recipes as you like in here, // without needing to use ServerEvents.recipes() again. console.log('Hello! The recipe event has fired!') }) ``` In the next sections, you can see what to put inside your callback. ### Adding Recipes [↑](#bkmrk-contents) The following is all code that should be placed *inside* your recipe callback. ##### Shaped[↑](#bkmrk-contents) Shaped recipes are added with the `event.shaped()` method. Shaped recipes must have their ingredients in a specific order and shape in order to match the player's input. The arguments to `event.shaped()` are: 1. The output item, which can have a count of 1-64 2. An array (max length 3) of crafting table rows, represented as strings (max length 3). Spaces represent slots with no item, and letters represent items. The letters don't have to mean anything; you explain what they mean in the next argument. 3. An object mapping the letters to Items, like `{letter: item}`. Input items must have a count of 1. If you want to force strict positions on the crafting grid or disable mirroring, see Methods of Custom Recipes. ```javascript event.shaped('3x minecraft:stone', [// arg 1: output 'A B', ' C ', // arg 2: the shape (array of strings) 'B A' ], { A: 'minecraft:andesite', B: 'minecraft:diorite', //arg 3: the mapping object C: 'minecraft:granite' } ) ``` ##### Shapeless[↑](#bkmrk-contents) Shapeless recipes are added with the `event.shapeless()` method. Players can put ingredients of shapeless recipes anywhere on the grid and it will still craft. The arguments to `event.shapeless()` are: 1. The output item 2. An array of input items. The total input items' count must be 9 at most. ```javascript event.shapeless('3x minecraft:dandelion', [ // arg 1: output 'minecraft:bone_meal', 'minecraft:yellow_dye', //arg 2: the array of inputs '3x minecraft:ender_pearl' ]) ``` ##### Smithing[↑](#bkmrk-contents) Smithing recipes have 2 inputs and one output and are added with the `event.smithing()` method. Smithing recipes are crafted in the smithing table. ```javascript event.smithing( 'minecraft:netherite', // arg 1: output 'minecraft:iron_ingot', // arg 2: the item to be upgraded 'minecraft:black_dye' // arg 3: the upgrade item ) ``` ##### Smelting & Cooking[↑](#bkmrk-contents) Cooking recipes are all very similar, accepting one input (a single item) and giving one output (which can be up to 64 of the same item). The fuel cannot be changed in this recipe event and should be done with tags instead. - Smelting recipes are added with `event.smelting()`, and require the regular Furnace. - Blasting recipes are added with `event.blasting()`, and require the Blast Furnace. - Smoking recipes are added with `event.smoking()`, and require the Smoker. - Campfire cooking recipes are added with `event.campfireCooking()`, and require the Campfire. ```javascript // Cook 1 stone into 3 gravel in a Furnace: event.smelting('3x minecraft:gravel', 'minecraft:stone') // Blast 1 iron ingot into 10 nuggets in a Blast Furnace: event.blasting('10x minecraft:iron_nugget', 'minecraft:iron_ingot') // Smoke glass into tinted glass in the Smoker: event.smoking('minecraft:tinted_glass', 'minecraft:glass') // Burn sticks into torches on the Campfire: event.campfireCooking('minecraft:torch', 'minecraft:stick') ``` ##### Stonecutting[↑](#bkmrk-contents) Like the cooking recipes, stonecutting recipes are very simple, with one input (a single item) and one output (which can be up to 64 of the same item). They are added with the `event.stonecutting()` method. ```javascript //allow cutting 3 sticks from any plank on the stonecutter event.stonecutting('3x minecraft:stick', '#minecraft:planks') ``` ##### Custom/Modded JSON recipes[↑](#bkmrk-contents) If a mod supports Datapack recipes, you can add recipes for it without any addon mod support! Unfortunately, we can't give specific advice because every mod's layout is different, but if a mod has a GitHub (most do!) or other source code, you can find the relevant JSON files in `/src/generated/resources/data/The tag event is a server event.
Tags are per item/block/fluid/entity\_type and as such cannot be added based on things like NBT data!
The tags event takes an extra parameter that determines which registry it's adding tags to. You will generally only need item, block, and fluid tags. However, it does support adding tags to any registry, including other mods ones. For mod ones make sure to include the namespace! ```javascript // Listen to item tag event ServerEvents.tags('item', event => { // Get the #forge:cobblestone tag collection and add Diamond Ore to it event.add('forge:cobblestone', 'minecraft:diamond_ore') // Get the #forge:cobblestone tag collection and remove Mossy Cobblestone from it event.remove('forge:cobblestone', 'minecraft:mossy_cobblestone') // Get #forge:ingots/copper tag and remove all entries from it event.removeAll('forge:ingots/copper') // Required for FTB Quests to check item NBT event.add('itemfilters:check_nbt', 'some_item:that_has_nbt_types') // You can create new tags the same way you add to existing, just give it a name event.add('forge:completely_new_tag', 'minecraft:clay_ball') // It supports adding tags to tags as well. Just prefix the second tag with # event.add('c:stones', '#forge:stone') // Removes all tags from this entry event.removeAllTagsFrom('minecraft:stick') // Add all items from the forge:stone tag to the c:stone tag, unless the id contains diorite const stones = event.get('forge:stone').getObjectIds() const blacklist = Ingredient.of(/.*diorite.*/) stones.forEach(stone => { if (!blacklist.test(stone)) event.add('c:stone', stone) }) }) ```Recipes use item tags, not block or fluid tags. Even if items representing those are blocks, like `minecraft:cobblestone`, it still uses an item tag for recipes.
```javascript // Listen to the block tag event ServerEvents.tags('block', event => { // Add tall grass to the climbable tag. This does make it climbable! event.add('minecraft:climbable', 'minecraft:tall_grass') }) ``` # Custom ItemsThe custom item event is a startup event.
Custom items are created in a startup script. They cannot be reloaded without restarting the game. The event is not cancellable. ```javascript // Listen to item registry event StartupEvents.registry('item', e => { // The texture for this item has to be placed in kubejs/assets/kubejs/textures/item/test_item.png // If you want a custom item model, you can create one in Blockbench and put it in kubejs/assets/kubejs/models/item/test_item.json e.create('test_item') // If you want to specify a different texture location you can do that too, like this: e.create('test_item_1').texture('mobbo:item/lava') // This texture would be located at kubejs/assets/mobbo/textures/item/lava.png // You can chain builder methods as much as you like e.create('test_item_2').maxStackSize(16).glow(true) // You can specify item type as 2nd argument in create(), some types have different available methods e.create('custom_sword', 'sword').tier('diamond').attackDamageBaseline(10.0) }) ``` Valid item types:Item modification is a startup event.
`ItemEvents.modification` is a startup script event used to modify various properties of existing items. ```javascript ItemEvents.modification(event => { event.modify('minecraft:ender_pearl', item => { item.maxStackSize = 64 item.fireResistant = true item.rarity = "UNCOMMON" }) event.modify('minecraft:ancient_debris', item => { item.rarity = "RARE" item.burnTime = 16000 }) event.modify('minecraft:turtle_helmet', item => { item.rarity = "EPIC" item.maxDamage = 481 item.craftingRemainder = Item.of('minecraft:scute').item }) }) ``` Available properties:Property | Value Type | Description |
maxStackSize | int | Sets the maximum stack size for items. Default is 64 for most items. |
maxDamage | int | Sets the maximum damage an item can take before it is broken. |
craftingRemainder | Item | Sets the item left behind in the crafting grid when this item is used as a crafting ingredient (like milk buckets in the cake recipe). Most items do not have one. |
fireResistant | boolean | If this item burns in fire and lava. Most items are false by default, but Ancient Debris and Netherite things are not. |
rarity | Rarity | Sets the items rarity. This is mainly used for the name colour. COMMON by default. Nether Stars and Elytra are UNCOMMON, Golden Apples are RARE and Enchanted Golden Apples are EPIC. |
burnTime | int | Sets the burn time (in ticks) in a regular furnace for this item. Note that Smokers and Blast Furnaces burn fuel twice as fast. Coal is 1600. |
foodProperties | FoodProperties | Sets the items food properties to the provided properties. Can be `null` to remove food properties. |
foodProperties | Consumer<FoodBuilder> | Sets the properties according to the consumer. See [below for more info](https://wiki.latvian.dev/books/kubejs/page/item-modification#bkmrk-food). |
digSpeed | float | Sets the items digging speed to the number provided. See table below for defaults. |
tier | Consumer<MutableToolTier> | Currently BROKEN! Sets the tools tier according to the consumer. See [below for more info](https://wiki.latvian.dev/books/kubejs/page/item-modification#bkmrk-tier). |
attackDamage | double | Sets the attack damage of this item. |
attackSpeed | double | Sets the attack speed of this item |
armorProtection | double | Sets the armor protection for this item. 20 is a full armour bar. |
armorToughness | double | Adds an armor toughness bonus. |
armorKnockbackResistance | double | Add an armor knockback resistance bonus. Can be negative. 1 is full knockback resistance. |
Tier | level | maxDamage | digSpeed | attackDamage (this is a bonus modified by the tool type value, not the final value) | enchantmentValue |
Wood | 0 | 59 | 2 | 0 | 15 |
Stone | 1 | 131 | 4 | 1 | 5 |
Iron | 2 | 250 | 6 | 2 | 14 |
Diamond | 3 | 1561 | 8 | 3 | 10 |
Gold | 0 | 32 | 12 | 0 | 22 |
Netherite | 4 | 2031 | 9 | 4 | 15 |
Tier | maxDamage | armourProtection | armorToughness | armorKnockbackResistance |
Leather | \[65, 75, 80, 55\] | \[1, 2, 3, 1\] | 0 | 0 |
Chain | \[195, 225, 240, 165\] | [1, 4, 5, 2] | 0 | 0 |
Iron | \[195, 225, 240, 165\] | [2, 5, 6, 2] | 0 | 0 |
Gold | \[91 ,105, 112, 77\] | [1, 3, 5, 2] | 0 | 0 |
Diamond | \[429, 495, 528, 363\] | [3, 6, 8, 3] | 2 | 0 |
Turtle (only has helmet) | \[325, nil, nil. nil\] | [2, nil, nil, nil] | 0 | 0 |
Netherite | \[481, 555, 592, 407\] | [3, 6, 8, 3] | 3 | 0.1 |
Elytra (not actually armor) | \[nil, 432, nil, nil\] | 0 | 0 | 0 |
Broken at the moment! [https://github.com/KubeJS-Mods/KubeJS/issues/662](https://github.com/KubeJS-Mods/KubeJS/issues/662). Use the non tier methods instead.
##### Tools ```javascript ItemEvents.modification(event => { event.modify('golden_sword', item => { item.tier = tier => { tier.speed = 12 tier.attackDamageBonus = 10 tier.repairIngredient = '#forge:storage_blocks/gold' tier.level = 3 } }) event.modify('wooden_sword', item => { item.tier = tier => { tier.enchantmentValue = 30 } }) }) ```Property | Value Type | Description |
uses | int | The maximum damage before this tool breaks. Identical to maxDamage. |
speed | float | The digging speed of this tool. |
attackDamageBonus | float | The bonus attack damage of this tool. |
level | int | The mining level of this tool. |
enchantmentValue | int | The enchanting power of this tool. The higher this is, the better the enchantments at an Enchanting Table are. |
repairIngredient | Ingredient | The material used to repair this tool in an anvil. |
Method | Parameters | Description |
hunger | int h | Sets the hunger restored when this item is eaten |
saturation | float s | Sets the saturation mulitplier when this food is eaten. This is not the final value, it goes through some complicated maths first |
meat | boolean flag (optional, true by default) | Sets if this item is considered meat. Meat can be fed to wolves to heal them. |
alwaysEdible | boolean flag (optional, true by default) | If this item can be eaten even if your food bar is full. Chorus Fruit has this true by default. |
fastToEat | boolean flag (optional, true by default) | If this item is fast to eat, like Dried Kelp. |
effect | ResourceLocation mobEffectId, int duration, int amplifier, float probability | Adds an effect to the entity who eats this, like a Golden Apple |
removeEffect | MobEffect mobEffect | Removes the effect from the entity who eats this, like Honey Bottles (poison). |
eaten | Consumer<FoodEatenEventJS> e | BROKEN! Use ItemEvents.foodEaten in server scripts instead. |
This is a [startup script](https://wiki.latvian.dev/books/kubejs/page/list-of-events), meaning that you will need to *restart your game* each time you want to make changes to it.
You can register many types of custom blocks in KubeJS. Here's the simplest way: ```javascript StartupEvents.registry("block", (event) => { event.create("example_block") // Create a new block with ID "kubejs:example_block" }) ``` That's it! Launch the game, and assuming you've left KubeJS's auto-generated resources alone, there should be a fully-textured block in the Creative menu under KubeJS (purple dye). KubeJS will also generate the name "Example Block" for you. To make modifications to this block, we use the **block builder** returned by the `event.create()` call. The block builder allows us to chain together multiple modifications. Let's try making some of the more common modifications: ```javascript StartupEvents.registry("block", (event) => { event.create("example_block") // Create a new block .displayName("My Custom Block") // Set a custom name .material("wood") // Set a material (affects the sounds and some properties) .hardness(1.0) // Set hardness (affects mining time) .resistance(1.0) // Set resistance (to explosions, etc) .tagBlock("my_custom_tag") // Tag the block with `#minecraft:my_custom_tag` (can have multiple tags) .requiresTool(true) // Requires a tool or it won't drop (see tags below) .tagBlock("my_namespace:my_other_tag") // Tag the block with `#my_namespace:my_other_tag` .tagBlock("mineable/axe") //can be mined faster with an axe .tagBlock("mineable/pickaxe") // or a pickaxe .tagBlock('minecraft:needs_iron_tool') // the tool tier must be at least iron }) ``` ### All Block Builder Methods In case it wasn't covered above, here's list of each method you can use when building a block. - `displayName('name')` - Sets the item's display name. - `material('material')` (No longer supported in 1.20+, see `mapColor` and `soundType` below!) - Set the item's material to an available material from the Materials List:The block modification event is a startup event.
`BlockEvents.modification` event is a startup script event that allows you to change properties of existing blocks. ```JavaScript BlockEvents.modification(e => { e.modify('minecraft:stone', block => { block.destroySpeed = 0.1 block.hasCollision = false }) }) ``` All available properties: - `String material` - `boolean hasCollision` - `float destroySpeed` - `float explosionResistance` - `boolean randomlyTicking` - `String soundType` - `float friction` - `float speedFactor` - `float jumpFactor` - `int lightEmission` - `boolean requiresTool` # Custom TiersThe custom tier event is a startup event.
You can make custom tiers for armor and tools in a startup script. They are not reloadable without restarting the game. The events are not cancellable. ##### Tool tiers ```javascript ItemEvents.toolTierRegistry(event => { event.add('tier_id', tier => { tier.uses = 250 tier.speed = 6.0 tier.attackDamageBonus = 2.0 tier.level = 2 tier.enchantmentValue = 14 tier.repairIngredient = '#forge:ingots/iron' }) }) ``` ##### Armor tiers ```javascript ItemEvents.armorTierRegistry(event => { event.add('tier_id', tier => { tier.durabilityMultiplier = 15 // Each slot will be multiplied with [13, 15, 16, 11] tier.slotProtections = [2, 5, 6, 2] // Slot indicies are [FEET, LEGS, BODY, HEAD] tier.enchantmentValue = 9 tier.equipSound = 'minecraft:item.armor.equip_iron' tier.repairIngredient = '#forge:ingots/iron' tier.toughness = 0.0 // diamond has 2.0, netherite 3.0 tier.knockbackResistance = 0.0 }) }) ``` # Worldgen ## General Notes #### Biome Filters: Biome filters work similarly to *recipe filters* and can be used to create complex and exact filters to fine-tune where your features may and may not spawn in the world. They are used for the `biomes` field of a feature and may look something like this: ```JavaScript WorldgenEvents.add(event => { event.addOre(ore => { // let's look at all of the 'simple' filters first ore.biomes = 'minecraft:plains' // only spawn in exactly this biome ore.biomes = /^minecraft:.*/ // spawn in all biomes that match the given pattern ore.biomes = '#minecraft:is_forest' // spawn in all biomes tagged as 'minecraft:is_forest' // filters can be arbitrarily combined using AND, OR and NOT logic ore.biomes = {} // empty AND filter, always true ore.biomes = [] // empty OR filter, always true ore.biomes = { not: 'minecraft:ocean' } // spawn in all biomes that are NOT 'minecraft:ocean' // since AND filters are expressed as maps and expect string keys, // all of the 'primitive' filters can also be expressed as such ore.biomes = { // see above for an explanation of these filters id: 'minecraft:plains', id: /^minecraft:.*/, // regex (also technically an ID filter) tag: '#minecraft:is_forest', } // note all of the above syntax may be mixed and matched individually }) }) ``` #### Rule Tests and Targets: In 1.18, Minecraft WorldGen has changed to a "target-based" replacement system, meaning you can specify specific blocks to be replaced with specific other blocks within the same feature configuration. (For example, this is used to replace Stone with the normal ore and Deepslate with the Deepslate ore variant). Each target gets a "rule test" as input (something that checks if a given block state should be replaced or not) and produces a specific output block state. While scripting, both of these concepts are expressed as the same class: `BlockStatePredicate`. Syntax-wise, `BlockStatePredicate` is pretty similar to biome filters as they too can be combined using `AND` or `OR` filters (which is why we will not be repeating that step here), and can be used to match one of three different things fundamentally: 1. **Blocks:** these are simply parsed as strings, so for example `'minecraft:stone'` to match Stone 2. **Block States:** these are parsed as the block ID followed by an array of properties. You would use something like `'minecraft:furnace[lit=true]'` to match only Furnace blocks that are lit. You can use `F3` to figure out a block's properties, as well as possible values through using the debug stick. 3. **Block Tags**: these are parsed in the "familiar" tag syntax, so you could use `'#minecraft:base_stone_overworld'` to match all types of stone that can be found generating in the ground in the Overworld.Note that these are **block** tags, not **item** tags. They may (and probably will) be different! (F3 is your friend!)
You can also use regular expressions with block filters, so `/^mekanism:.+_ore$/` would match any block from Mekanism whose ID ends with `_ore`. Keep in mind this will *not* match block state properties!
When a `RuleTest` is required instead of a `BlockStatePredicate`, you can also supply that rule test directly in the form of a JavaScript object (it will then be parsed the same as vanilla would parse JSON or NBT objects). This can be useful if you want rule tests that have a random chance to match.
**More examples of how targets work can be found in the example script down below.** #### Height Providers: Another system that may appear a bit confusing at first is the system of "height providers", which are used to determine at what Y level a given ore should spawn and with what frequency. Used in tandem with this feature are the so-called "vertical anchors", which may be used to get the height of something relative to a specific anchor point (for example the top or bottom of the world). In KubeJS, this system has been simplified a bit to make it easier to use for script developers. There are two common types of ore placement: 1. **Uniform**: has the same chance to spawn anywhere in between the two anchors 2. **Triangle**: is more likely to spawn in the center of the two anchors than it is to spawn further outwards To use these two, you can use the methods `uniformHeight` and `traingleHeight` in `AddOreProperties`, respectively. Vertical anchors have also been simplified, as you can use the `aboveBottom` / `belowTop` helper methods in `AddOreProperties`. **Once again, see the example script for more information!** --- #### Example script ```JavaScript WorldgenEvents.add(event => { // use the anchors helper from the event const { anchors } = event event.addOre(ore => { ore.id = 'kubejs:glowstone_test_lmao' // (optional, but recommended) custom id for the feature ore.biomes = { not: 'minecraft:savanna' // biome filter, see above (technically also optional) } // examples on how to use targets ore.addTarget('#minecraft:stone_ore_replaceables', 'minecraft:glowstone') // replace anything in the vanilla stone_ore_replaceables tag with Glowstone ore.addTarget('minecraft:deepslate', 'minecraft:nether_wart_block') // replace Deepslate with Nether Wart Blocks ore.addTarget([ 'minecraft:gravel', // replace gravel... /minecraft:(.*)_dirt/ // or any kind of dirt (including coarse, rooted, etc.)... ], 'minecraft:tnt') // with TNT (trust me, it'll be funny) ore.count([15, 50]) // generate between 15 and 50 veins (chosen at random), you could use a single number here for a fixed amount of blocks .squared() // randomly spreads the ores out across the chunk, instead of generating them in a column .triangleHeight( // generate the ore with a triangular distribution, this means it will be more likely to be placed closer to the center of the anchors anchors.aboveBottom(32), // the lower bound should be 32 blocks above the bottom of the world, so in this case, Y = -32 since minY = -64 anchors.absolute(96) // the upper bound, meanwhile is set to be just exactly at Y = 96 ) // in total, the ore can be found between Y levels -32 and 96, and will be most likely at Y = (96 + -32) / 2 = 32 // more, optional parameters (default values are shown here) ore.size = 9 // max. vein size ore.noSurface = 0.5 // chance to discard if the ore would be exposed to air ore.worldgenLayer = 'underground_ores' // what generation step the ores should be generated in (see below) ore.chance = 0 // if != 0 and count is unset, the ore has a 1/n chance to generate per chunk }) // oh yeah, and did I mention lakes exist, too? // (for now at least, Vanilla is likely to remove them in the future) event.addLake(lake => { lake.id = 'kubejs:funny_lake' // BlockStatePredicate lake.chance = 4 lake.fluid = 'minecraft:lava' lake.barrier = 'minecraft:diamond_block' }) }) WorldgenEvents.remove(event => { // print all features for a given biome filter event.printFeatures('', 'minecraft:plains') event.removeOres(props => { // much like ADDING ores, this supports filtering by worldgen layer... props.worldgenLayer = 'underground_ores' // ...and by biome props.biomes = [ { category: 'icy' }, { category: 'savanna' }, { category: 'mesa' } ] // BlockStatePredicate to remove iron and copper ores from the given biomes // Note tags may NOT be used here, unfortunately... props.blocks = ['minecraft:iron_ore', 'minecraft:copper_ore'] }) // remove features by their id (first argument is a generation step) event.removeFeatureById('underground_ores', ['minecraft:ore_coal_upper', 'minecraft:ore_coal_lower']) }) ``` #### Generation Steps