#condition of holding item
1 messages · Page 1 of 1 (latest)
What?
.typeId == 'item you want to detect'
player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot).typeId == 'item'
const item = player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot) //this will return an itemStack
if (item.typeId == "minecraft:diamond") {
//...
}
[neko_set:${parseInt(player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot).typeId == 'item' ? consult.score(player, "neko_set") : '')}]
or this if you want it exactly like the code you sent first
There's no way I can make it work with the tag?
Ohh
oh so you want both tag and item detection ?
both conditions should be true for the code to work?
The player must be holding an item and have a tag
[neko_set:${parseInt(player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot).typeId == 'item' && player.hasTag(`nknk`) ? consult.score(player, "neko_set") : '')}]
Thanks for helping
That is made using the conditional AND operator what allows you to ''concatenate'' logical conditions
you're welcome
🙂
Another question
tell me
How do I import the TypeId?
huh wait, that will fire when you aren't holding any item, right?
I'll suppose that yes so use this
[neko_set:${parseInt(player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot).typeId ?? "minecraft:air" == 'item' && player.hasTag(`nknk`) ? consult.score(player, "neko_set") : '')}]
mojang removed the minecraft:air item some time ago, so if you don't have any item in hand it will return undefined and will cause that error, by using nullish coalesing operator I avoid the error by converting the value to minecraft:air when the typeId marks undefined
I put this and
Got a bigger bug
tell me
hmm
I don't think it is a bug caused by the code I did, let me check
send me the full scope
Ok
import * as mc from '@minecraft/server';
import * as consult from './template';
export function repeat(player) {
player.onScreenDisplay.setTitle(
`[ep:${parseInt(consult.score(player, "ep") / consult.score(player, "ep_eval") * 99)}]
[hp:${Math.round(player.getComponent("health").current * 100 / player.getComponent("health").value)}]
[neko_set:${parseInt(player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot).typeId ?? "minecraft:air" == 'ssak:neko' && player.hasTag(`nknk`) ? consult.score(player, "neko_set") : '')}]`
);
player.runCommandAsync(`scoreboard players set @s[scores={ep=${consult.score(player, "ep_eval")}..}] ep ${consult.score(player, "ep_eval")}`)
}
Line 7 is your code
[neko_set:${parseInt(player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot)?.typeId == 'item' && player.hasTag(`nknk`) ? consult.score(player, "neko_set") : '')}]
I'll try
It worked 😁😁😁