your current location:首页 > news>Kubejs6 about a solution for Curios to quickly determine whether it is equipped with a jewelry [KJS] Kubejs Minecraft Ga

Kubejs6 about a solution for Curios to quickly determine whether it is equipped with a jewelry [KJS] Kubejs Minecraft Ga

2024-12-05 23:05:24|Myriagame |source:minecraft skins

This tutorial is set by the author to use the CC by-NC protocol.

Foreword

After looking for a day, I didn't find a reliable method of locking the player whether the player was equipped with a designated jewelry. In the end, he could only solve the problem by yourself.如果想写kubeJS非常推荐安装KubeJS Offline Documentation,这个mod可以用指令导出一个离线文档,包含了所有的MC及其mod的java类信息,注意是java的类信息,而且只导出部分名称信息,包括类Names, constant names, method names and parameter names, etc., without class attributes (can be seen on several attribute names on some constructed methods), no specific implementation of the class and methods and no comments, and the search function is slightly apparent.Disabled, but only the name guessing method is enough to write JS.If you are really curious, prepare a MOD environment, Decode a jar package to see the specific implementation.

If the parameters of the event recovery of an event recovery include the parameters of the parameters, you do not understand, and the official wiki of Kubejs is not explained, it is recommended to use consle.info (event)/) Or Player.tell (EVENT) print what the Event is Java class, and then go to the offline document to check the constructive method of the constructor, you can understand which parameters of Event are composed of.

For example, EEVENT printed by ENTITYEVENTS.HURT (event => {}) The recovery showed that this type of dev.latvian.mods.kubejs.entity.entityHurteventjs can be searched in the offline document that its structure method is as follows. TityHurteventjs (Livingntity Entity, DamageSourceSource, Float amount), which means that Event consists of three parameters: entity, source of damage, and damage value.

Because my computer is not too lazy to install, only IDEA, so I use a notebook to write JS. Of course, I still recommend Probejs. If you have a VS environment.

text

The MC version and MOD version number used in the following examples are,

Mc1.19.2

Forge 43.4.4

Kubejs-FORGE-1902.6.2-build.73.jar

Curios-FORGE-1.19.2-5.1.6.3.jar

Spore_1.19.2_2.1.1.jar

Provide a way to quickly search for a jewelry, CurioShelper.Findfirmcurio (Entity, Item ID), the return value is java.util.Optional The fixed object will returnAn empty Optional container can determine whether it is empty by calling the iSpresent () method of the Optional class. If you are equipped, you will return a container with a SlotResult object. Use Tostring to see the fields where the equipment is located, player information, player coordinates, player coordinate coordinates, Item ID ...... and other information.If you don't understand what is slotResult, then the offline documentation is useful. Search for Top.Theillusivec4.curios.api.slotresult in the offline document. See what it can do.

The following is an example of a fungal infection: the anti -toxic mask of the spores (FUNGAL Infection: SPORE), and the jewelry bar HEAD tags are added, and an example of the effect of immunobius infection in the jewelry bar.

 const Curioshelper = java.loadClass ("Top.Theillusivec4.curios.api.curiosapi"). Getcurioshelper ()

// Entity is equipped with jewelry with jewelry ID

// Return Boolean

Function ISEQUIPEDCURIO (Entity, Curioid) {

Return CurioShelper.fINDFIRSTCURIO (Entity, Curioid.

}

ServerEvents.tags ("item", event => {

Event.add ("Curios: Head", "SPORE: Gas_mask")

})

ENTITYEVENTS.HURT (Event => {{

Let {Entity, Source, amount} = EVENT

// Return when not for players

If (! Entity.class.tostring (). Contains ("serverplayer") {) {

Return

}

// Cancel the damage judgment when wearing a mask for acetic infection

Ifquippedcurio (Entity, "SPORE: GAS_MASK")) {{

If (source.tostring (). Contains ("Mycelium.overtake") {{) {{) {{

Event.cancel ()

}

}

})

Playrevents.Tick (event => {{

Let Player = Event.player

// When wearing a mask and acetic infection effect, remove the mycelium infection

ISEQUIPDCURIO (Player, "SPORE: GAS_MASK") {{) {

If (Player.haseffect ("Spore: Mycelium_ef") {{) {{

Player.removeeffect ("Spore: Mycelium_ef")

}

}

})