#Filtering by entity NBT?

7 messages · Page 1 of 1 (latest)

spiral gull
#

Added "Addon Related" since it's possible this might be easier with LootJS, but basically I'm trying to target an entity based on its NBT data (and have the script apply to it) to mainly modify drops and maybe other functionality on related events.

My guess is that in base KubeJS I'd be looking to perform a check or some sort of predicate using EntityEvents but that's undocumented on the wiki at the moment, so not sure there. Figured I'd ask here before diving into the repo to see if I can piece something together.

For the LootJS approach I'm assuming I might be able to use LootContext's getEntity and then use some property on that which will allow me to check the NBT, but their wiki doesn't provide a return type, nor would I really know where to look to reference the "Entity" return type which I assume it returns, so I'm not sure what kind of properties even exist on it (or the syntax I'd use to get the NBT data from it, if that's possible).

Programmer, but not familiar with MC's codebase or either modloader, so if I'm missing something obvious there my bad. I assume even if it's a "base MC type" there's still some discrepancy in the syntax/naming conventions from Java to KubeJS but idk.

reef sailBOT
#

Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!

rose spear
#

I don't have a clue how Predicates work in LootJS, but I can give you an example on how to achieve this with .matchEntityCustom():

LootJS.modifiers(event => {
    event.addEntityModifier("minecraft:cow").matchEntityCustom(entity => {
        return entity.nbt.CustomName == '"Stone"' //double quotes because nbt is weird, just console.log your value.
    }).addLoot("minecraft:stone")
})

For CustomName specifically you could also use the built-in entity.customName shorthand, i just wanted to provide an example on how you can get any nbt key.
Also in case you aren't already, i'd highly advise you to use VSC with the ProbeJS mod (and extension).

spiral gull
rose spear
#

For most things, yes, but it sadly won't for nbt since that's a data structure similar to json with uncertain properties. You can always log entity.nbt or Object.keys(entity.nbt) though.

spiral gull
#

Oh, so does .nbt just allow me to use the string properties that would exist on the actual data structure? that works then, I thought it might only work on vanilla NBT tags or something "predefined" like that.

#

In other words, I already know what NBT data I'm looking for (via /data in-game) but I wasn't sure how to actually get that using .nbt but that's convenient if it kinda "just works" as a property on entity.nbt