#custom keybind error

4 messages · Page 1 of 1 (latest)

patent echo
#

so when i run this code

const $KeyMappingRegistry = Java.loadClass('dev.architectury.registry.client.keymappings.KeyMappingRegistry')
const $KeyMapping = Java.loadClass('net.minecraft.client.KeyMapping')
const $GLFWKey = Java.loadClass('org.lwjgl.glfw.GLFW')

ClientEvents.init(event => {
    global.HKEY = new $KeyMapping('key.kubejs.hkey', $GLFWKey.GLFW_KEY_H, 'key.categories.kubejs')
    $KeyMappingRegistry.register(global.HKEY)
})

ClientEvents.tick(event => {
    if (Client.currentScreen == null) {
        if (global.HKEY.consumeClick()) {
            console.log('Key pressed')
        }
    }
})

i get this error
keybind_use.js#3: Error in 'ClientEvents.tick': TypeError: Cannot call method "consumeClick" of undefined

cobalt atlasBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

north bolt
#

one problem i noticed is that you're putting ClientEvents.init in client scripts
i know it's weird, but for some reason that event only works in startup
i'd recommend moving everything above the ClientEvents.tick handler into startup scripts and move all of the java classes into the ClientEvents.init

patent echo
#

ok yeah that works thanks