Migrating to KubeJS 6
This page is still being worked on, so if some info is missing, please check back later!
What's changed in new KubeJS 6 (1.19.2+)?
onEvent()
onEvent('string.event.id', event => {})
syntax has been replaced bySomeEventGroup.someEventName(event => {})
.
// Before
onEvent('block.right_click', event => {
if(event.block.id === 'minecraft:dirt') {
console.info('Hi!')
}
})
// After
BlockEvents.rightClicked(event => {
if(event.block.id === 'minecraft:dirt') {
console.info('Hi!')
}
})
Not only that, but new events also support extra parameter for IDs and other things! You can now chose to make each id have it's own event handler:
// Before
onEvent('block.right_click', event => {
if(event.block.id === 'minecraft:dirt') {
console.info('Hi!')
} else if(event.block.id === 'minecraft:stone') {
console.info('Bye!')
}
})
// After
BlockEvents.rightClicked('minecraft:dirt', event => {
console.info('Hi!')
})
BlockEvents.rightClicked('minecraft:stone', event => {
console.info('Bye!')
})
Some events require ID, such as registry and tag evevnts:
// Before
onEvent('item.registry', event => {
})
// After
StartupEvents.register('item', event => {
})
// Before
onEvent('tags.items', event => {
})
// After
ServerEvents.tags('item', event => {
})
You can find full list of new events here.
onForgeEvent()
onForgeEvent('package.ClassName', event => {})
has been replaced byForgeEvents.onEvent('package.ClassName', event => {})
.
// Before
onForgeEvent('net.minecraftforge.event.level.BlockEvent$PortalSpawnEvent', event => {
})
// After
ForgeEvents.onEvent('net.minecraftforge.event.level.BlockEvent$PortalSpawnEvent', event => {
})
New! It now supports generic events:
ForgeEvents.onGenericEvent('net.minecraftforge.event.AttachCapabilitiesEvent', 'net.minecraft.world.entity.Entity', event => {
})
Server settings
settings.log...
properties have been removed from server scripts, and instead, moved to local/kubejsdev.properties
file. By default it won't be shipped with back, but you can change saveDevPropertiesInConfig
to true to instead save the file in kubejs/config/dev.properties
.
java()
java('package.ClassName')
has been replaced byJava.loadClass('package.ClassName')
.
// Before
const CactusBlock = java('net.minecraft.world.level.block.CactusBlock')
// After
const CactusBlock = Java.loadClass('net.minecraft.world.level.block.CactusBlock')
There might be some more reflective helper methods later in Java util class, such as listing all fields and methods in a class, etc.
Other questions
If you have any other questions, feel free to ask them on my discord.