Kubejs
Kubejs
This wiki is still very much work in progress! Feel free to suggest changes in the #off-topic Discord
channel.
Intro
Events
EventJS
CommandEventJS
TagEventJS
RecipeEventJS
WorldgenAddEventJS
WorldgenRemoveEventJS
ItemTooltipEventJS
Classes
Object
String
Primitive Types
Global
Examples
KubeJS UI
Custom Items
Custom Blocks
Item Modification
Block Modification
JEI Integration
REI Integration
Units
Chat Event
Network Packets
Starting Items
Clearlag 1.12
Custom Fluids
Intro
FAQ
What does this mod do?
This mod lets you create scripts in JavaScript language to manage your server, add new blocks
and items, change recipes, add custom handlers for quest mods and more!
Run the game with mod installed once. It should generate kubejs folder in your minecraft
There's examples and pre-made scripts here. And you can always ask in discord support channel
Yes, use /reload to reload server_scripts/ , F3 + T to reload client_scripts/ and
/kubejs reload startup_scripts to reload startup_scripts/ . If you don't care about reloading
recipes but are testing some world interaction event, you can run /kubejs reload server_scripts .
Note: Not everything is reloadable. Some things require you to restart game, some only world,
some work on fly. Reloading startup scripts is not recommended, but if you only have event
require addon mods, but in theory, still would work with datapack recipes. See Recipes section for
more info.
The feature list would go here if I actually wrote it. But basically, editing and creating recipes, tags,
items, blocks, fluids, worldgen. Listening to chat, block placement, etc. events. Just look at the
It uses a fork of Rhino, a JavaScript engine by Mozilla to convert JS code to Java classes at runtime.
KubeJS wraps minecraft classes and adds utilities to simplify that a lot and remove need for
mappings. Architectury lets nearly the same source code be compiled for both Forge and Fabric
If wiki didn't have the answer for what you were looking for, you can join the Discord server and
Website: https://kubejs.com/
Events
Events that get fired during game to control recipes, world, etc.
Events
updated regularly.
Click on event ID to open it's class and see information, fields and methods.
Type descriptions:
Server: Scripts go in kubejs/server_scripts folder. Will be reloaded when you run /reload
command.
Server Startup: Same as Server, and the event will be fired at least once when server loads.
Client: Scripts go in kubejs/client_scripts folder. Currently only reloaded if you have KubeJS
Client Startup: Same as Client, and the event will be fired at least once when client loads.
ID Cancellable Type
init No Startup
postinit No Startup
loaded No Startup
command.registryNo Server
client.init No Client
client.debug_info.left
No Client
client.debug_info.right
No Client
ID Cancellable Type
client.logged_in No Client
client.logged_out No Client
client.tick No Client
server.load No Server
server.unload No Server
server.tick No Server
server.datapack.first
No Server
server.datapack.last
No Server
recipes No Server
world.load No Server
world.unload No Server
world.tick No Server
world.explosion.pre
Yes Server
world.explosion.post
No Server
player.logged_in No Server
player.logged_outNo Server
player.tick No Server
player.data_from_server.
Yes Client
player.data_from_client.
Yes Server
player.advancement
No Server
player.inventory.opened
No Server
ID Cancellable Type
player.inventory.closed
No Server
player.inventory.changed
No Server
player.chest.opened
No Server
player.chest.closed
No Server
entity.check_spawn
Yes Server
block.registry No Startup
block.missing_mappings
No Server
block.tags No Server
block.drops No Server
item.registry No Startup
item.missing_mappings
No Server
item.tags No Server
item.right_click_empty
No Server
ID Cancellable Type
item.left_click No Server
item.entity_interact
Yes Server
item.modificationNo Startup
item.tooltip No Client
item.crafted No Server
item.smelted No Server
fluid.registry No Startup
fluid.tags No Server
entity_type.tags No Server
worldgen.add No Startup
worldgen.removeNo Startup
Events
EventJS
This event is the most basic event class, parent of all other events.
Parent class
Object
Can be cancelled
No
CommandEventJS
This event needs cleanup! Using it is not recommended.
Information
Parent class
EventJS
Can be cancelled
Yes
ParseResults
parseResults Command params
<CommandSource>
TagEventJS
This event is fired when a tag collection is loaded, to modify it with script. You can add and
Parent class
EventJS
Can be cancelled
No
removeAllTagsFrom(String[]
void Removes all tags from object
ids)
TagWrapper class
remove(String TagWrapper
Removes an object from tag, works the same as add().
[]/Regex ids) (itself)
TagWrapper
removeAll() Removes all entries from tag.
(itself)
Examples
// Listen to item tag event
onEvent('tags.items', 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')
event.removeAll('forge:ingots/copper')
'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')
event.removeAllTagsFrom('minecraft:stick')})
Recipes use item tags, not block or fluid tags, even if items representing those are blocks.
Like minecraft:cobblestone even if it's a block, it will still be an item tag for recipes.
tags.blocks is for adding tags to block types, it works the same way. You can find existing
block tags if you look at a block with F3 mode enabled, on side. These are mostly only used
for technical reasons, and like mentioned above, if its for recipes/inventory, you will want to
RecipeEventJS
Examples
event.shaped('3x minecraft:stone', [
'SAS',
'S S',
'SAS'
], {
S: 'minecraft:sponge',
A: 'minecraft:apple'
})})
event.remove({output: 'minecraft:stick'})})
// Supports /reload
// Remove broken recipes from vanilla and other mods // This is on by default, so you
//event.removeBrokenRecipes = true
input is Redstone Dust tag event.remove({mod: 'quartzchests'}) // Remove all recipes from
// You can use 'mod:id' syntax for 1 sized items. For 2+ you need to use '2x mod:id' or
// Add shaped recipe for 3 Stone from 8 Sponge in chest shape // (Shortcut for
minecraft:stone', [
'SAS',
'S S',
'SAS'
], {
S: 'minecraft:sponge',
A: 'minecraft:apple'
})
// Add shapeless recipe for 4 Cobblestone from 1 Stone and 1 Glowstone // (Shortcut for
Carrots
'minecraft:golden_apple') // Similar recipe to above but this time it has a custom, static
ID - normally IDs are auto-generated and will change. Useful for Patchouli
event.smelting('minecraft:golden_apple', 'minecraft:carrot').id('mymodpack:my_recipe_id')
// Add similar recipes for Blast Furnace, Smoker and Campfire event.blasting('3x
'minecraft:golden_apple') // You can also add .xp(1.0) at end of any smelting recipe to
change given XP
// Add a smithing recipe that combines 2 items into one (in this case apple and gold
'minecraft:gold_ingot')
// Create a function and use that to make things shorter. You can combine multiple actions
input)
if (includeBlasting) {
event.blasting(output, input)
// If you use custom({json}) it will be using vanilla Json/datapack syntax. Must include
"type": "mod:recipe_id"! // You can add recipe to any recipe handler that uses vanilla
recipe system or isn't supported by KubeJS // You can copy-paste the json directly, but you
can also make more javascript-y by removing quotation marks from keys // You can replace
{item: 'x', count: 4} in result fields with Item.of('x', 4).toResultJson() // You can
// Important! Create has integration already, so you don't need to use this. This is just
event.custom({
type: 'create:crushing',
ingredients: [
Ingredient.of('minecraft:oak_sapling').toJson()
],
results: [
Item.of('minecraft:apple').toResultJson(),
Item.of('minecraft:carrot').withChance(0.5).toResultJson()
],
processingTime: 100
})
event.shaped('minecraft:book', [
'CCC',
'WGL',
'CCC'
], {
Item.of('minecraft:enchanted_book').enchant('minecraft:respiration', 2), G:
'#forge:glass'
})
// In all shapeless crafting recipes, replace any planks with Gold Nugget in input items
'minecraft:gold_nugget')
// In all recipes, replace Stick with Oak Sapling in output items event.replaceOutput({},
'minecraft:stick', 'minecraft:oak_sapling')})
Possible settings you can change for recipes. It's recommended that you put this in it's own server
// priority: 5
As mentioned before, you can add any recipe from any mod with JSON syntax (see
event.custom({}) ) but these mods are supported as addons with special syntax:
KubeJS Mekanism
KubeJS Thermal
KubeJS Create
Poorly documented things below!
You can transform ingredients in shaped and shapeless recipes by adding these functions at end
of it:
.damageIngredient(IngredientFilter filter, int damage?) // Will damage item when you craft
with it
(like bucket)
Object with item and/or index ( {item: 'something', index: 0}, etc)
Examples:
ignores damage
// Craft example block from 2 diamond swords and 2 dirt. After crafting first diamond
event.shaped('kubejs:example_block', [
'SD ',
'D S'
], {
S: Item.of('minecraft:diamond_sword').ignoreNBT(),
D: 'minecraft:dirt'
}).damageIngredient(0).keepIngredient('minecraft:diamond_sword')
// Craft example block from 2 diamond swords and 2 stones. After crafting, diamond sword
event.shapeless('kubejs:example_block', [
Item.of('minecraft:diamond_sword').ignoreNBT(),
'minecraft:stone',
Item.of('minecraft:diamond_sword').ignoreNBT(),
'minecraft:stone'
]).replaceIngredient('minecraft:diamond_sword', 'minecraft:stone_sword')
// Craft clay from sand, bone meal, dirt and water bottle. After crafting, glass bottle
event.shapeless('minecraft:clay', [
'minecraft:sand',
'minecraft:bone_meal',
'minecraft:dirt',
WorldgenAddEventJS
This event isn't complete yet and can only do basic things. Adding dimension-specific
})
properties)
List of valid block IDs or tags that the ore can spawn in
below
chunk
and Z between 0 and 16. Recommended to be true // ore.chance = 4 // Spawns the ore every
~4 chunks. You usually combine this with clusterCount = 1 for rare ores
})
event.addSpawn(spawn => { // Create new entity spawn spawn.category = 'creature' //
'water_ambient'
spawn.weight = 10 // Weight
group
})})
All values are optional. All feature types have biomes field like addOre example
taiga
extreme_hills
jungle
mesa
plains
savanna
icy
the_end
beach
forest
ocean
desert
river
swamp
mushroom
nether
You can also use ('$type' (case doesn't matter)) on Forge's BiomeDictionary:
hot
cold
wet
dry
sparse
dense
spooky
dead
lush
1. raw_generation
2. lakes
3. local_modifications
4. underground_structures
5. surface_structures
6. strongholds
7. underground_ores
8. underground_decoration
9. vegetal_decoration
10. top_layer_modification
It's possible you may not be able to generate some things in their layer, like ores in dirt,
because dirt hasn't spawned yet. So you may have to change the layer by calling
WorldgenRemoveEventJS
For more information on biomes field, see worldgen.add event page.
})
event.removeSpawnsByID(spawns => {
spawns.entities.values = [
'minecraft:cow',
'minecraft:chicken',
'minecraft:pig',
'minecraft:zombie'
})
event.removeSpawnsByCategory(spawns => {
spawns.biomes.values = [
'minecraft:plains'
spawns.categories.values = [
'monster'
})})
If something isn't removing, you may try to remove it "manually" by first printing all features (this
will spam your console a lot, I suggest reading logs/kubejs/startup.txt) and then removing them by
ID where possible.
event.printFeatures('underground_ores')})
'mekanism:ore_copper')})
Events
ItemTooltipEventJS
onEvent('item.tooltip', tooltip => {
// You can also use any ingredient except #tag tooltip.add(/refinedstorage:red_/, 'Can be
any color') // Multiple lines with an array []. You can also escape ' by using other type of
Text.of('Hello')) // Adds text in first line, replacing title. If you want 2nd line, the
index must be 1
})})
Classes
Available fields and methods and examples on how to use them
Classes
Object
Parent class of all Java objects.
Parent
equals(Object
boolean Checks equality with another object.
other)
String
Class of string objects, such as "abc" (and in JS 'abc' works as well)
Parent
Object
Primitive Types
Information
Primitive types are objects that don't have a real class and don't inherit methods from Object.
KubeJS UI
You can also always look at existing modpack using KubeJS UI to see how they do it
event.replace(ui => {
//ui.background('kubejsui:textures/example_background.png')
ui.tilingBackground('kubejsui:textures/example_background.png', 256)
ui.minecraftLogo(30)
ui.button(b => {
b.name = 'Test'
b.x = 10
b.y = 10
b.action = 'minecraft:singleplayer'
})
ui.button(b => {
b.action = 'https://feed-the-beast.com/'
})
ui.label(l => {
l.x = 2
l.y = ui.height - 12
l.action = 'https://feed-the-beast.com/'
})
ui.image(i => {
i.width = 40
i.height = 30
i.action = 'https://feed-the-beast.com/'
})
ui.label(l => {
l.x = 100
l.y = ui.height - 20
l.height = 15
l.shadow = true
})
})})
Examples
Custom Items
This is a startup_scripts/ event
event.create('test_item')
event.create('test_item_2').maxStackSize(16).glow(true)
// You can specify item type as 2nd argument in create(), some types have different
'sword').tier('diamond').attackDamageBaseline(10.0)})
basic (default)
sword
pickaxe
axe
shovel
hoe
helmet
chestplate
leggings
boots
Other methods item builder supports: [you can chain these methods after create()]
maxStackSize(size)
unstackable()
maxDamage(damage)
burnTime(ticks)
containerItem(item_id)
rarity('rarity')
tool(type, level)
glow(true/false)
tooltip(text...)
group('group_id')
color(index, colorHex)
texture(customTexturePath)
parentModel(customParentModel)
Methods available if you use 'sword', 'pickaxe', 'axe', 'shovel' or 'hoe' type:
tier('toolTier')
modifyTier(tier => ...) // Same syntax as custom tool tier, see below
attackDamageBaseline(damage) // You only want to modify this if you are creating a custom
attackDamageBonus(damage)
types
speed(speed)
wood
stone
iron
gold
diamond
netherite
Methods available if you use 'helmet', 'chestplate', 'leggings' or 'boots' type:
tier('armorTier')
modifyTier(tier => ...) // Same syntax as custom armor tier, see below
leather
chainmail
iron
gold
diamond
turtle
netherite
search
buildingBlocks
decorations
redstone
transportation
misc
food
tools
combat
brewing
All values are optional and by default are based on iron tier
tier.uses = 250
tier.speed = 6.0
tier.attackDamageBonus = 2.0
tier.level = 2
tier.enchantmentValue = 14
tier.repairIngredient = '#forge:ingots/iron'
})})
HEAD]
tier.slotProtections = [2, 5, 6, 2]
tier.enchantmentValue = 9
'#forge:ingots/iron'
tier.knockbackResistance = 0.0
})})
Examples
Custom Blocks
This is a startup script.
event.create('test_block')
.material('glass')
.hardness(0.5)
// Block with custom type (see below for list of types) event.create('test_block_slab',
'slab').material('glass').hardness(0.5)})
If you want a custom block model, you can create one in Blockbench and put it in
kubejs/assets/kubejs/models/block/test_block.json .
List of available materials - to change break/walk sounds and to change some properties (tool used
to mine, etc):
Material
air
wood
rock
iron
organic
Material
earth
water
lava
leaves
plants
sponge
wool
sand
glass
tnt
coral
ice
snow
clay
groud
dragon_egg
portal
cake
web
slime
honey
berry_bush
Material
lantern
Other methods block builder supports: [you can chain these methods]
material('material')
unbreakable()
harvestTool('tool', level) // Available tools: pickaxe, axe, hoe, shovel, level >= 0
opaque(boolean)
fullBlock(boolean)
requiresTool(boolean)
renderType('type') // solid, cutout, translucent, cutout required for blocks with texture like
color(tintindex, color)
texture('texturepath')
texture('side', 'texturepath')
model('modelpath')
noItem()
box(x0, y0, z0, x1, y1, z1, true) // 0.0 - 16.0, default is (0,0,0,16,16,16, true)
box(x0, y0, z0, x1, y1, z1, false) // Same as above, but in 0.0 - 1.0 scale, default is
(0,0,0,1,1,1, false)
noCollision()
notSolid()
waterlogged()
noDrops()
slipperiness(float) //
speedFactor(float)
jumpFactor(float)
setLootTableJson(json)
setBlockstateJson(json)
setModelJson(json)
noValidSpawns(boolean)
suffocating(boolean)
viewBlocking(boolean)
redstoneConductor(boolean)
transparent(boolean)
Event callbacks:
RandomTickEvent:
BlockContainerJS block
Random random
Types
basic
slab
stairs
fence
fence_gate
wall
wooden_pressure_plate
stone_pressure_plate
wooden_button
stone_button
Examples
'minecraft:red_sand')})
table.addPool(pool => {
uniform
pool.survivesExplosion()
weight pool.addItem('minecraft:dirt', 40, [4, 8]) // [4-8] = count modifier, uses same
syntax as rolls
})
})})
Example from Factorial: (adds 1-3 leaves dropped from all Leaves blocks, 4-8 logs from all log and
wood blocks and 4-8 stone from Stone, Cobblestone, Andesite, Diorite and Granite)
table.addPool(pool => {
pool.survivesExplosion()
})
})
event.addBlock(/minecraft:.*_(log|wood)/, table => {
table.addPool(pool => {
pool.survivesExplosion()
})
})
event.addBlock([
'minecraft:stone',
'minecraft:cobblestone',
'minecraft:andesite',
'minecraft:diorite',
'minecraft:granite'
], table => {
table.addPool(pool => {
pool.survivesExplosion()
pool.addItem('factorial:stone', 1)
})
})})
You can also modify existing loot tables to add items to them:
onEvent('block.loot_tables', event => { // all dirt blocks have a 50% chance to drop an
table.addPool(pool => {
pool.addItem('minecraft:diamond_sword').randomChance(0.5).enchantWithLevels(1,
true).name(Text.of('Test').blue())
})
})})
onEvent('entity.loot_tables', event => { // Override zombie loot table that will drop 5 of
=> {
table.addPool(pool => {
pool.rolls = 5
pool.addItem('minecraft:carrot', 1)
pool.addItem('minecraft:apple', 3)
})
})
table.addPool(pool => { // Modify pig loot table to *also* drop dirt on top of its
regular drops
pool.addItem('minecraft:dirt')
})
})})
Override method
Event ID Modify method name
name
Examples
Item Modification
item.modification event is a startup script event that allows you to change properties of existing
items
item.maxStackSize = 64
item.fireResistant = true
})})
int maxStackSize
int maxDamage
int burnTime
String craftingReminder
boolean fireResistant
Rarity rarity
int uses
float speed
float attackDamageBonus
int level
int enchantmentValue
Ingredient repairIngredient
hunger(int)
saturation(float)
meat(boolean)
alwaysEdible(boolean)
fastToEat(boolean)
removeEffect(String effectId)
}
Examples
Block Modification
block.modification event is a startup script event that allows you to change properties of existing
blocks
block.destroySpeed = 0.1
block.hasCollision = false
})})
String material
boolean hasCollision
float destroySpeed
float explosionResistance
boolean randomlyTicking
String soundType
float friction
float speedFactor
float jumpFactor
int lightEmission
boolean requiredTool
Examples
JEI Integration
Sub-types
event.useNBT('example:item')
event.userNBTKey('example:item', 'type')})
event.hide('example:ingredient')
})
event.hide('example:fluid')})
})
event.add('example:fluid')})
Add Information
REI Integration
Note: REI integration only works on Fabric in 1.16. In 1.18+, it works on both Forge and
Fabric!
Hide Items
event.hide('example:ingredient')})
Add Items
event.add(item.of('example:item').nbt({test: 123}))})
Add Information
'Line 2'])})
Examples
log.info('Custom task!')
event.checkTimer = 20
task.progress++
})
log.info('Custom reward!')
event.player.tell('Hello!')
})
if (event.player) { event.notifiedPlayers.tell(Text.of(`${event.player.name}
completed... something!`).green())
})
// generic 'quest' object completion. Note: There isnt actually a way to get reliable title
quest!`).blue())
})
event.onlineMembers.playSound('entity.experience_orb.pickup')
})
if(event.server
&& event.source.actual
&& event.source.actual.player && event.source.actual.mainHandItem.id ===
'minecraft:wooden_sword'
event.source.actual.data.ftbquests.addProgress('12345678', 1)
}})
Examples
have integration.
// side: client// This is a startup script. This script changes a java variable in ProjectE
PECore.DEV_ENVIRONMENT = false})
Examples
Painter API
About
Painter API allows you to draw things on the screen, both from server and directly from client. This
can allow you to create widgets from server side or effects on screen or in world from client side.
Currently it doesn't support any input, but in future, in-game menus or even GUIs similar to Source
Paintable objects are created from NBT/Json objects and all have an id. If id isn't provided, a
random one will be generated. Objects x and z are absolute positions based on screen, but you
can align elements in one of the corners of screen. You can bulk add multiple objects in one json
object. All properties are optional, but obviously some you should almost always override like size
paint({...}) is based on upsert principle - if object doesn't exist it will create it (if the object also
rectangle is created
You can remove object with remove: true, bulk remove multiple objects or remove all objects:
If the object is re-occuring, it's recommended to create objects at login with all of its static
properties and visible: false , then update it later to unhide it. Painter objects will be cleared
when players leave world/server, if its persistent, then it must be re-added at login every time.
Root
Boolean visible
Screen Object
Unit x
Unit y
Unit z
Unit w
Unit h
Unit moveX
Unit moveY
Unit expandW
Unit expandH
rectangle
Color color
String texture
Float u0
Float v0
Float u1
Float v1
gradient
Color color
Color colorT
Color colorB
Color colorL
Color colorR
Color colorTL
Color colorTR
Color colorBL
Color colorBR
String texture
Float u0
Float v0
Float u1
Float v1
text
Text text
Boolean shadow
Float scale
Color color
Boolean centered
World Object (not implemented!)
Unit x
Unit y
Unit z
Unit w
Unit h
Unit d
Properties
Color can be either 0xRRGGBB , '#RRGGBB' , '#AARRGGBB', e.g. '#58AD5B' or chat colors 'red' ,
'dark_aqua' , etc.
Examples
event.player.paint({
example_rectangle: {
type: 'rectangle',
x: 10,
y: 10,
w: 50,
h: 20,
color: '#00FF00',
draw: 'always'
},
last_message: {
type: 'text',
scale: 1.5,
x: -4,
y: -4,
alignX: 'right',
alignY: 'bottom',
draw: 'always'
})
})
'(sin((time() * 1.1)) * (($screenW - 32) / 2))', w: 32, h: 32, alignX: 'center', texture:
message: ${event.message}`}}) // Bulk update, this is the same code as 2 lines above, you can
Units
This page describes all functions and operations available for units
Usage
Most basic unit is plain number, such as '1' or '4.5' . You can use variables with $ like
'$example' . Each operation requires parenthesis around it, e.g '(10 + $example)' . each function
requires name parenthesis and comma separated arguments e.g. 'min(PI, $example)' . You can
Constants
PI == 3.141592653589793
E == 2.718281828459045
true == 1.0
false == 0.0
Operations
-a
(a + b)
(a - b)
(a * b)
(a / b)
(a % b)
(a & b)
(a | b)
(a ^ b)
!a
(a << b)
(a >> b)
(a == b)
(a != b)
(a > b)
(a < b)
(a >= b)
(a <= b)
Functions
random()
time()
min(a, b)
max(a, b)
pow(a, b)
abs(a)
sin(a)
cos(a)
tan(a)
atan(a)
atan2(y, x)
deg(a)
rad(a)
log(a)
log10(a)
log1p(a)
sqrt(a)
sq(a)
floor(a)
ceil(a)
Chat Event
This script is peak of human evolution. Whenever someone says "Creeper" in chat, it replies with
"Aw man".
callback.data.tell(Text.green('Aw man'))
})
}})
Another example, cancelling the chat event. No need to schedule anything now, because player's
(event.message.startsWith('!some_command')) {
event.player.tell('Hi!')
event.cancel()
}})
Examples
Network Packets
This script shows how to use network packets:
// Listen to a player event, in this case item right-click// This goes in either server or
client script, depending on which side you want to send the data packet to
server side
be any string, but it's recommended to keep it to snake_case [a-z_0-9]. // Receiving side
test: 123 })
} else {
// It's not required to use a different channel ID, but it's recommended. // Receiving
})
// Listen to event that gets fired when network packet is received from server.// This goes
in a client script
Prints 123
})
// Listen to event that gets fired when network packet is received from client.// This goes
in a server script
Prints 456})
Examples
Starting Items
This server script adds items on first time player joins, checking stages. GameStages mod is not
required
stage yet
if (!event.player.stages.has('starting_items')) {
event.player.stages.add('starting_items')
event.player.give('minecraft:stone_sword')
event.player.give('30x minecraft:apple')
}})
Examples
every second
event.player.data.ftbutilities.rank
ftbutilities.getRank(rank.getPermission('promotion.next'))
newRank.getPermissionValue('promotion.timer').getInt()
newRank.getPermission('promotion.name') + '!')
ftbutilities.saveRanks()
})
// When player gets promoted to 'trusted' rank, give them gold ingot (uncomment the line)
event.data.player.give('minecraft:gold_ingot')})
power: 1
default_player_rank: true
promotion.name: Player
promotion.next: newcomer
promotion.timer: 5
command.ftbutilities.rtp: false
command.ftbutilities.home: false
[newcomer]
power: 5
promotion.name: Newcomer
promotion.next: regular
command.ftbutilities.rtp: true
[regular]
power: 10
promotion.name: Regular
promotion.next: trusted
command.ftbutilities.home: true
After 15 seconds (or 10 since previous role) they will be promoted to regular.
After 30 seconds (or 15 since previous role) they will be promoted to trusted, etc.
Examples
Clearlag 1.12
This script removes all items from world every 30 minutes. Only works in 1.12.
// Create item whitelist filter that won't be deleted with clearlagvar whitelist =
Ingredient.matchAny([
whitelist
'minecraft:emerald'
])
Utils.newCountingMap()
var clearLag = server => { // Get a list of all entities on server with filter that only
returns items
counters
lastClearLagResult.clear()
counters
itemList.forEach(entity => {
if (!whitelist.test(entity.item)) {
lastResult.add(key, 1)
entity.item.count)
entity.kill()
}
})
lastClearLagResult.addAll(lastResult.entries)
lastClearLagResult.sort(null)
server.tell([
Text.lightPurple('[ClearLag]'),
lastTotalClearLagResult.totalCount,
Text.yellow('Click here').click('command:/clearlagresults'),
])
callback => {
clearLag(callback2.data)
})
callback.reschedule()
})
})
// Register commands
event
.create('clearlag')
.op()
})
.add()
// Register new non-OP command /clearlagresults, that displays stats of all removed items
event
.create('clearlagresults')
clearlag results:' ])
lastTotalClearLagResult.get(entry.key)
Text.red(entry.value) ])
})
})
.add()})
Examples
The example script restarts server after 2 hours but notifies players 5 minutes before that.
function (callback) {
})
callback.data.runCommand('/stop')
})})
Examples
The image has to be saved as 32-bit PNG, not Auto-detect/24-bit, otherwise you will get a
JVM crash!
Example result:
Currently incompatible with Fancy Menu!
Examples
Custom Fluids
Fabric not supported yet!
// Basic "thick" (looks like lava) fluid with red tint event.create('thick_fluid', fluid
=> {
fluid.textureThick(0xFF0000)
fluid.bucketColor(0xFF0000)
fluid.displayName('Thick Fluid')
})
// Basic "thin" (looks like water) fluid with cyan tint event.create('thick_fluid', fluid
=> {
fluid.textureThin(0xFF0000)
fluid.bucketColor(0x00FFFF)
fluid.displayName('Thin Fluid')
})
fluid.displayName('Strawberry Cream')
fluid.textureStill('kubejs:block/strawberry_still')
fluid.textureFlowing('kubejs:block/strawberry_flow')
fluid.bucketColor(0xFF33FF)
})
// as always, for KubeJS 3 / Minecraft 1.16, these calls need to be chained instead, so
for example
event.create('thick_fluid')
.textureThick(0xFF0000)
.bucketColor(0xFF0000)
.displayName('Thick Fluid')})