your current location:首页 > news>Kubejs implements TACZ melee weapon shooting key melee attack [KJS] Kubejs Minecraft Game

Kubejs implements TACZ melee weapon shooting key melee attack [KJS] Kubejs Minecraft Game

2024-12-10 17:56:04|Myriagame |source:minecraft skins

The key registration part refers to this tutorial, and thanks to the big guys of the Kubejs Demon Reform Communication Group.

Some TACZ guns contain a complete melee weapon (such as the wrench and atomic decomposition machines in the motor military division), which is limited by the current TACZ. These two weapons can only be triggered by melee key to trigger an attack without using a conventional mouse.The left button attack, which makes people feel awkward, so I thought of trying to use Kubejs to mappore a key position.

Registered key

With reference to the above tutorial, we register a left mouse button in Startup_scripts, and put the binding of this button into the classification of TACZ

 const $ keymapping = java.loadclass ("net.minecraft.client.keymapping")

const $ IKEYCONFLICICONTEXT = Java.loadClass ("Net.MineCraftforge.Client.Settings.ikeyConflictContext");

const $ KECONFLICTCONTEXT = Java.loadClass ("Net.mineCraftforge.client.Settings.KeyConFLICTEXT");

const $ keymodifier = java.loadclass ("net.mineCraftforge.client.Settings.Keymodifier");

const $ inputConstantStype = java.loadclass ("com.mojang.blaze3d.platform.inputConstants $ Type");

const $ KeyMappingRegistry = Java.loadClass (

"Dev.architectable.regization.client.Keymappings.Keymappingregization" "

);

global.meleespeckey = new $ keymapping (

"Key.tacz.melee_spec.desc",

$ KeconflictContext.in_game,

$ Keymodifier.none,

$ InputConstantStype.mouse,

0,

"Key.category.tacz",

);

Clientevents.init (() => {

$ KeymappingRegistry.register (Global.Meleespeckey);

});

The reason why the key to register in the key is mainly because the mouse buttons need to be registered -simply use the GLFW key position to register the keyboard button.

The following is the result of the registration:

Button event

After the key is registered, the key event is processed, and the following is written in the following_scripts:

<<<<<<<<] = "assh: none;">> cause

Const speckey = global.meleespeckey;

Const {player} = event; if (spieckey.consumeClick ()) {) {

Let item = player.getmainhanditem ();

Ifm.nbt.getString ("Gunid") == "Create_armorr: SPECIAL_MELEEE_WRENCH") {

Player.melee ();

}

}

})

"IF (SpecKey.ConsuMeClick ())" is used to detect whether the button is pressed

If we were pressed, we immediately tested whether the player's hands were the two melee weapons. Because TACZ's firearms were distinguished by the Gunid NBT tag, the judgment was well written.

Taking that mechanical power wrench as an example: "IF (ITEM.NBT.GETSTRING (" Gunid ") ==" Create_armorr: Special_melee_wrench ")") ")") ")") ")") ")

Next is the most troublesome place in the entire script: find the melee attack function of TACZ.After half an hour of JAR, I finally understood that in fact, the melee attack function is actually in the LocalPlayer class. TACZ has been injected with Mixin, which means that as long as "player.melee ()" calls 2333 (the corresponding other corresponding othersFunctions such as shooting and aiming can actually be called on the client like this)

OK, this is the entire key mapping process.The disadvantage of the United States is that because the shooting event is not canceled, the newly -handed wrench will consume the ammunition first, and then the left button will be a melee attack, but the program can run.