Skip to main content

Migrating to KubeJS 6

WIP!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()

ThingsonEvent('string.event.id', event => {}) syntax has been replaced with
SomeEventGroup.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 document: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!')
})

onEventSome 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 => {
})

onForgeEvent()

onForgeEventonForgeEvent('package.ClassName', event => {}) has been replaced with
ForgeEvents.onEvent('package.ClassName', event => {}).

settings

// Before

onForgeEvent('net.minecraftforge.event.level.BlockEvent$PortalSpawnEvent', event => {
})

// devAfter

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.