This tutorial is set by the author to use the CC By-NC-SA protocol.
This article will implement the Kubejs registration button, the effect is as shown in the figure
Refer to Discord and Crispyloresis Integrated Package
Minecraft FORGEKEKUJSARCHITECTURYRHINOPROBEJS1.20.147.2.192001.6.4-Build.1149.1.122001.2- Build.185.7.0
Register
The registered button needs to be in startup_scripts.
const $ keymapping = java.loadclass ("net.minecraft.client.keymapping")const $ glfwkey = java.loadclass ("org.lwjgl.glfw.glfw");
const $ KeyMappingRegistry = Java.loadClass (
"Dev.architectable.regization.client.Keymappings.Keymappingregization" "
);
global.Testkey = New $ KeyMapping (
"Key.kubejs.test",
$ Glfwkey.glfw_key_k,
"Key.Keybinding.test"
);
Clientevents.init (() => {
$ KeymappingRegistry.register (global.testkey);
});
Let's analyze it one by one.
reflection
const $ keymapping = java.loadclass ("net.minecraft.client.keymapping")const $ glfwkey = java.loadclass ("org.lwjgl.glfw.glfw");
const $ KeyMappingRegistry = Java.loadClass (
"Dev.architectable.regization.client.Keymappings.Keymappingregization" "
);
The first class is the original button binding.
The LWJGL in the second category can be regarded as the MC game engine, where the key code is obtained here.For example, the value of the $ glfwkey.glfw_key_k below is only 75.It is also possible to search for the button code without using this class, but it is not recommended.
The third category provides a static method registration button, which will be mentioned below.
When you enter these code, you may not make up automatically because each class must be loaded at least once to be recognized by Probejs.You can restart the game and run the command, and the automatic completion will be obtained next.
/Probejs dump
Storage button object
global.testkey = new $ keymapping ("Key.kubejs.test",
$ Glfwkey.glfw_key_k,
"Key.Keybinding.test"
);
Create an object and store it in Global.
The 3 parameters correspond to the content in the button settings, as shown in the figure:
"Key.kubejs.test" is the key name. Use the translation key to create a language file and modify it by itself.
$ GLFWKEY.GLFW_KEY_K is the key code. If you fill in 75 directly, you can also indicate K, but it is not recommended to do this.
"Key.Keybinding.test" is a key category, and also uses the translation key.When registering multiple keys, you can reach the same category if the value is the same.
If you store it in Global, you can access the server_scripts and client_scripts.
Next, you can restart the game and run the command to let Probejs add automatic completion to Global.
Register
<<<<<<<<] = "ass: none;">> client focuss.int ((para) => {
$ KeymappingRegistry.register (global.testkey);
});
Register the button when initialization of the client.
If there are multiple buttons, the same is the same:
<<<<<<<<] = "ass: none;">> client focuss.int ((para) => {
$ KeymappingRegistry.register (global.testkey);
$ KeymappingRegistry.register (Global.Reloadkey);
});
Use keys in the client
I have registered the keys now, and we must use the keys on the client next.The server can only use buttons indirectly.
In client_scripts:
<<<<<<<<<<<<<<<<<]
Const key = global.testkey; // access global
Const {player} = event;
If (key.ConsumeClick ()) {
Player.senddata ("Global.Testkey.ConsumeClick");
Player.playSound ("block.anvil.use");
Console.log ("