#condition of holding item

1 messages · Page 1 of 1 (latest)

silver anchor
#
player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot)
#

that will return an ItemStack, just check the id

silver anchor
#

.typeId == 'item you want to detect'

#
player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot).typeId == 'item'
rustic radish
# wet sail What?
const item = player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot) //this will return an itemStack

if (item.typeId == "minecraft:diamond") {
    //...
}
silver anchor
#
      [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

wet sail
silver anchor
silver anchor
#

both conditions should be true for the code to work?

wet sail
#

The player must be holding an item and have a tag

silver anchor
#

ooh

#

well in that case give me a moment

silver anchor
#
      [neko_set:${parseInt(player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot).typeId == 'item' && player.hasTag(`nknk`) ? consult.score(player, "neko_set") : '')}]
wet sail
silver anchor
#

That is made using the conditional AND operator what allows you to ''concatenate'' logical conditions

silver anchor
wet sail
wet sail
silver anchor
#

tell me

wet sail
#

How do I import the TypeId?

silver anchor
#

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

wet sail
#

Got a bigger bug

silver anchor
#

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

wet sail
#

Ok

wet sail
# silver anchor send me the full scope
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

silver anchor
#
      [neko_set:${parseInt(player.getComponent('minecraft:inventory').container.getItem(player.selectedSlot)?.typeId == 'item' && player.hasTag(`nknk`) ? consult.score(player, "neko_set") : '')}]
wet sail
#

I'll try