Brief introduction
As we all know, Event.Player will select the specified player based on the previous event, event.player.mainhanditem will record the player's items based on this player.The required data required layer by layer, for example, all the final output as the (legal) incident (required) events can be added with the X coordinate of the block after the .x read the box, plus.BlockState reads the position of the block, so based on this principle, we can easily realize the NBT of the items that read any position.
A way to quickly obtain data in the game
First of all, when you need to directly obtain information data, you should use the event.server.runcommandsilent (`$ {}`) in the Itemvents.RightClicked event.Check whether it is available for variables), so that when you right -click when you hold a item, you will receive messages from the server on the left side of the screen.Then, we can enter the following code:
Itemevents.RightClicked (event => {{Event.server.runcommandsilent (`say $ {event.player.headarmoritem}`)
})
Test the type of decoration of the equipment on the player's body
Now, it is known that Event.Player.head/Chest/Legs/Feetarmoritem can obtain the items data of the four equipment columns on the player. When the player is equipped with a copper helmet and obtains HeadarMoritem with a script, you will receive this prompt:
Obviously, this is not detected by NBT, so what will happen to the. NBT suffixes after we add the .Player.Headarmoritem?
If the enchantment is added, this can only be longer, is there any way to cut the decoration part?The answer is, but it is not the interception string of the JavaScript itself, but the NBT screening provided by Kubejs.Let's add ["trim"] to. NBT, then we can get this output:
Middle parentheses can be continuously used. The effect of continuous use is to continue to intercept NBT under parentheses, such as
Event.player.Headarmoritem.nbt ["trim"] ["Pattern"]
Output
This kind of data is completely enough, but because any equipment bar is empty or any equipment without decoration will report an error, so you need to add a line.
if (event.player.headarmoritem! = NULL && Event.player.Headarmoritem.nbt ["trim"]! = Undefined)
Now, we only need to write down such a code to achieve a script based on the type of armor decoration type given to state effects:
<<<<<<<] = "assh: none;">> useRe archives.tith (access => {
If (event.player.headarmoritem! = Null && event.player.Headarmoritem.nbt ["trim"]! = Undefined)
{Var head = event.player.Headarmoritem.nbt ["trim"]
Else {head = null} if (event.player.chestarmoritem! = NULL && Event.player.Chestarmoritem.nbt ["trim"]! = Undefined)
Var Chest = Event.player.Chestarmoritem.nbt ["trim"]
If (event.player.legsarmoritem! = Null && Event.player.legsarmoritem.nbt ["trim"]! = Undefined)
Var legs = event.player.legsarmoritem.nbt ["trim"] ["Pattern"]
If (event.player.Feetarmoritem! = Null && Event.Player.Feetarmoritem.nbt ["trim"]! = Undefined) VAR Feet = EVENT.FEETARMORITEM.NBT ["TRI m "] [" Pattern "]
Ifad == Chest && Chest == legs && legs == Feet) {
// Coast Coast Dolphin
Ifad == "Minecraft: Coast"))
Event.entity.PotionEffects.add ("Minecraft: Dolphins_grace", 60, 0, TRUE, TRUE)
// Dune dune speed
Ifad == "Minecraft: Dune")
Event.entity.PotionEffects.add ("Minecraft: Speed", 60, 0, TRUE, TRUE)
})
Check whether there are specified items in the player's jewelry bar
Module: Curios API
Next, we can perform some higher -end operations.
You can get all the NBT tags of this player, but because the data is too large, the chat box cannot be put, so we can empty the item bar first, leave a block or item, and then use .tring (). Substring (0,20000)The suffix of the suffix is cut off the first 2000 characters of this string. It is not difficult to see it. It is not difficult to see that under the forgecaps is the player's jewelry bar data. After layer screening, we get such a string of code:
Event.player.nbt ["ForgetCaps"] ["Curios: Inventory"] ["curios"]. Tostring ()
Now we only need to find the items you need from these short line string. The example is displayed here:
<<<<<<<] = "assh: none;">> useRe archives.tith (access => {
// Indexof is the first time where these characters appear in the detection string. If it is not detected, it is -1
if (event.player.nbt["ForgeCaps"]["curios:inventory"]["Curios"].toString().indexOf("kubejs:atlas") == -1) {
// If the player has no map book, then:
Event.entity.PotionEffects.add ("XAEROWORLDMAP: No_world_map", 15, 0, TRUE, TRUE) //
Event.entity.PotionEffects.add ("XAEMINIMAP: No_minimap", 15, 0, TRUE, TRUE) // Disable small maps
// If you want to reverse this effect, change == to! =
}
})