#How do I check for a spawned entities NBT containing a specific Key name and value?

1 messages · Page 1 of 1 (latest)

stiff pecan
#

trying to use check_spawn event and as one of the IF statements, it would need to have
{numMaxAbilities: 1} or higher basically numMaxAbilities >0

stuck gladeBOT
#

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

flat grove
#

you could try something like event.entity.fullNbt.numMaxAbilities > 0

stiff pecan
#

ooooh awesome ty

#

so would it look something like this

EntityEvents.checkSpawn(event => {
    if(event.type == "SPAWNER" && event.entity.fullNbt.numMaxAbilities > 0){
        let nbt = event.entity.getFullNBT()
        var map = Utils.newMap();
        map.put("EldritchSpawned", true);
        nbt.KubeJSPersistentData=map;
        event.entity.mergeFullNBT(nbt)
        console.log(event.entity.getFullNBT())
    }
})```
flat grove
#

um

#

this is how i would try it

#
EntityEvents.checkSpawn(e => {
  let nbt = e.entity.fullNBT
  if (e.type == 'SPAWNER' && nbt.numMaxAbilities > 0) {
    nbt.EldritchSpawned = true
    e.entity.mergeFullNBT(nbt)
    console.log(e.entity.fullNBT)
  }
})
stiff pecan
#

2 questions;;

  1. why drop var map = Utils.newMap(); and nbt.KubeJSPersistentData=map ? i'm asking purely for educational purposes

  2. can I write in event.cancel() at the end of the IF statement in this event?

flat grove
#
  1. just to not overcomplicate mostly, the merge can take a standard JS object
  2. if you cancel it, it will just yeet the mob from existence
#

as a continuation to 1: you already have an object in the form of the nbt, so you might as well just add to that
its a copy of the original, not a reference

stiff pecan
#

it will yeet it from existence for that spawn in that spawner at that moment right? the mob can still exist outside of spawners right?

flat grove
#

well depending on where your cancel is, if its outside the if, it will pretty much disable all mob spawns, globally

#

if its inside, it will stop the mobs that comes from spawners that have the max abilities thingie > 0

#

at which point, it doesnt matter what you put after the if, if youre gonna cancel it thinking_lex

stiff pecan
#

got it makes sense

#

so i added the last snippet, got them to spawn

#

looks like its not adding the nbt

#
{DeathTime: 0s, LeftHanded: 0b, OnGround: 1b, AbsorptionAmount: 0.0f, IsBaby: 0b, Attributes: [{Name: "minecraft:zombie.spawn_reinforcements", Base: 0.003635517221684154d}, {Name: "minecraft:generic.knockback_resistance", Modifiers: [{Amount: 0.008766412161895066d, UUID: [I; 1952162562, -1092858140, -1161584693, -1714563210], Name: "Random spawn bonus", Operation: 0}], Base: 0.0d}, {Name: "stepheightentityattribute:stepheight", Base: 0.0d}, {Name: "minecraft:generic.movement_speed", Base: 0.23000000417232513d}, {Name: "additionalentityattributes:water_speed", Base: 0.019999999552965164d}], Invulnerable: 0b, Brain: {memories: {}}, HandDropChances: [0.085f, 0.085f], ArmorDropChances: [0.085f, 0.085f, 0.085f, 0.085f], Rotation: [192.24573f, 0.0f], HurtByTimestamp: 0, arcanus: {IsDiscombobulated: 0b, DiscombobulatedTimer: 0}, CanBreakDoors: 0b, cpaCooldown: 0, CustomName: '{"text":"Eldritch Zombie"}', MineCellsFlags: 0, GoldenAirSupply: 0.0f, BalmData: {}, cardinal_components: {"hexcasting:brainswept": {brainswept: 0b}, "bewitchment:fake_mob": {TargetUUID: ""}, "spectrum:azure_dike": {max_protection: 0, protection: 0, recharge_delay_after_damage: 0, recharge_delay_default: 0, current_recharge_delay: 0}, "eldritch_mobs:eldritch_modifiers": {numMaxAbilities: 0, checkedIfSpawnedInSoothingLanternChunk: 1b, titleSet: 0b, healthIncreased: 0b, abilities: {}}, "bewitchment:minion": {MasterUUID: ""}, "bewitchment:blood": {Blood: 100}, "bewitchment:curses": {Curses: []}, "apoli:powers": {Powers: []}, "onsoulfire:on_soul_fire": {OnSoulFire: 0b}, "bewitchment:additional_water_data": {WetTimer: 0, Submerged: 0b}, "respawnablepets:respawnable": {Respawnable: 0b}, "bewitchment:familiar": {Familiar: 0b}}, InWaterTime: -1, ArmorItems: [{}, {}, {}, {}], BSMLastRevive: 1000, HandItems: [{}, {}], Air: 300s, UUID: [I; 218920973, -84917454, -1929458454, 1498652229], DrownedConversionTime: -1, PersistenceRequired: 0b, CanPickUpLoot: 0b, FallDistance: 0.0f, UsingSpectreBoundedSpyglass: 0b, Motion: [0.0d, -0.0784000015258789d, 0.0d], BSMSoulCache: 0, Fire: -1s, Pos: [-38.091923943146234d, 63.0d, 15.367753043859393d], Health: 20.0f, HurtTime: 0s, FallFlying: 0b, BannerStack: {id: "minecraft:air", Count: 1b}, PortalCooldown: 0, cpadidTP: 0b}
#

(not trying to do the cancel if i get this to work. its basically for some stuff i have setup with lootjs)

#

also put in cancel to see if it would even work and that doesnt as well

flat grove
#

ah

#

your nbt is wrong

#

if (e.type == 'SPAWNER' && nbt.numMaxAbilities > 0)
->
if (e.type == 'SPAWNER' && nbt["eldritch_mobs:eldritch_modifiers"].numMaxAbilities > 0)

#

its not on top level

stiff pecan
#

ooooo

#

that makes sense

#

okay ill make that switch ty!

flat grove
#

:3

stiff pecan
# flat grove :3

**[09:38:33] [Server thread/ERROR]: ! #23: Error occurred while handling event 'EntityEvents.checkSpawn': TypeError: Cannot read property "numMaxAbilities" from undefined (server_scripts:lootjs/eldritch.js#23)**

#

saying that again

flat grove
#

ah should do a check

#
if (e.type == 'SPAWNER' && nbt["eldritch_mobs:eldritch_modifiers"]?.numMaxAbilities > 0)
#

i think its like that

stiff pecan
#

alright trying now 😄 i did though have only eldritch mobs spawn if that makes a difference

#

it should have found it

flat grove
#

hmm

#

could it because of an underground spawner SChide2

stiff pecan
#

i am having them spawn from a vanilla spawner i placed and then gave the zombie egg to

#

i reloaded, error is now gone

#

ill check their nbt data to seee if it got added

#

oh wait im still using cancel. they are not cancelling spawn

flat grove
#

i hate nbt

stiff pecan
#

Same

#
    let nbt = e.entity.fullNBT
    if (e.type == 'SPAWNER' && nbt["eldritch_mobs:eldritch_modifiers"]?.numMaxAbilities > 0)
    //   nbt.EldritchSpawned = true
    //   e.entity.mergeFullNBT(nbt)
    //   console.log(e.entity.fullNBT)
    e.cancel()
    }
  })```
flat grove
#

can you post your current script here so i can edit that

#

oh thanks

#

XD

stiff pecan
#

😄

flat grove
#

theres an extra } detective_woof_lex

stiff pecan
#

Oooof

#

okay reloading lmfao

#

Okay a regular zombie spawned

#

damn

#

and ofc spoke too soon.

#

eldritch mob zombie spawned

flat grove
#

wait

stiff pecan
#

game crashed

flat grove
#

i just formatted the nbt

stiff pecan
#

most likely due to a LootJS script im using to try to prevent drops if killed via slaughter block. can disregard. ill report this to lootjs

flat grove
#

its one layer deeper

#

cardinal_components

stiff pecan
#

oO

#

I thought it was more of a search method

flat grove
#
if (e.type == 'SPAWNER' && nbt.cardinal_components?["eldritch_mobs:eldritch_modifiers"]?.numMaxAbilities > 0)
#

nah you have to type the whole path

stiff pecan
#

so [cardinal_components.eldritch_mobs:eldritch_modifiers]?.numMaxAbilities

flat grove
#

i hope that works actually, im a bit unsure about the first ?

stiff pecan
#

oh shit i didnt see you wrote that

#

i need more coffee

#

Okay! launching

flat grove
#

im too scared to see the result

stiff pecan
#

lmfaoo

#

fingers crossed its not cursed 😄

#

should i add { } after if and put the cancel in it

#

or is it still technically considered nested?

flat grove
#

ye thats what i did, but if you only have the cancel its fine without

stiff pecan
#

ah okay

#

man if this works........... ill be so happy lol. ive always wanted to add great loot to eldritch mobs but mob farms always prevented me

#

🤞

#

it still spawned 😦

#

woah

#

it did cancel another tho

flat grove
#

o.o

stiff pecan
#

one tried spawning and the poof happened

#

but it didnt come in

flat grove
#

what you could do...

stiff pecan
#

or i alt+Tabbed at the wrong time and the slaughter block killed it

flat grove
#

can you post your script again

#

so i can add something to it

stiff pecan
#

yeah i think thats what hpapened. another eldritch just spawned

#
EntityEvents.checkSpawn(e => {
    let nbt = e.entity.fullNBT
    if (e.type == 'SPAWNER' && nbt.cardinal_components?["eldritch_mobs:eldritch_modifiers"]?.numMaxAbilities > 0)
    //   nbt.EldritchSpawned = true
    //   e.entity.mergeFullNBT(nbt)
    //   console.log(e.entity.fullNBT)
    e.cancel()
    })
flat grove
#

we can check for sure

#

try this

#
EntityEvents.checkSpawn(e => {
  let nbt = e.entity.fullNBT
  if (e.type == 'SPAWNER' && nbt.cardinal_components?.["eldritch_mobs:eldritch_modifiers"]?.numMaxAbilities > 0) {
    //   nbt.EldritchSpawned = true
    //   e.entity.mergeFullNBT(nbt)
    //   console.log(e.entity.fullNBT)
    e.cancel()
    e.server.tell('a mob was yeeted')
  } else e.server.tell('a mob spawned')
})
stiff pecan
#

ooh nice addition

flat grove
#

i tested the JS online so that should work better

stiff pecan
#

okay lets see!

#

no message 😦

#

so its not even seeing the if statement?

flat grove
#

wait theres nothing?

#

im beyond confused

#

can you show me your server.txt please

stiff pecan
amber boughBOT
#

Paste version of message.txt from @stiff pecan

stiff pecan
#

oh

#

server.txt

#

one sec

flat grove
#

thats the latest.log, not server.txt blushcat_lex

stiff pecan
#

well

#

this is why 😄

#

! [10:10:18] [ERR] if (e.type == 'SPAWNER' && nbt.cardinal_components?.["eldritch_mobs:eldritch_modifiers"]?.numMaxAbilities > 0) {:23: Error loading KubeJS script: server_scripts:lootjs/eldritch.js': missing name after . operator (server_scripts:lootjs/eldritch.js#23)

amber boughBOT
#

Paste version of message.txt from @stiff pecan

flat grove
#

ah it doesnt see that format yet..

#

i was afraid that would be the case

#

outdated JS PepeHands

stiff pecan
#

is that because of the ?.

#

i was wondering what that was. is this es7?

flat grove
#

yeah its the ?.[]

stiff pecan
#

I see. gonna have to look that up later

flat grove
#

my online test worked with it, but rhino doesnt know about it

stiff pecan
#

we should be able to use the ES6 alternate of whatever that is right?

flat grove
#

im not sure, this is a bit of grey terriroty for me with rhino, but we can do it the good ol fashioned way

#
EntityEvents.checkSpawn(e => {
  let nbt = e.entity.fullNBT
  if (e.type == 'SPAWNER' && nbt.cardinal_components && nbt.cardinal_components['eldritch_mobs:eldritch_modifiers']?.numMaxAbilities > 0) {
    //   nbt.EldritchSpawned = true
    //   e.entity.mergeFullNBT(nbt)
    //   console.log(e.entity.fullNBT)
    e.cancel()
    e.server.tell('a mob was yeeted')
  } else e.server.tell('a mob spawned')
})
stiff pecan
#

cant go wrong with the ol fashioned way

flat grove
#

and if this doesnt work...

stiff pecan
#

its still there

flat grove
#

yeah that is fine

stiff pecan
#

ah okay

flat grove
#

what it didnt like was the [] following it

#

which i now removed

stiff pecan
#

Ooh

#

i see what its doing now

#

thats a cool feature

#

or what it was trying to do

flat grove
#

its called an optional chaining

#

meaning it goes "forward" with the checks only if the previous one is not null

stiff pecan
#

i wish Google tag manager used ES7. thats a cool feature.

#

could help me with work haha

#

okay

#

its working

#

in the sense of the tell

flat grove
#

oh

#

well fuck

stiff pecan
#

yay

#

YAY

flat grove
#

oh my fucking god

stiff pecan
#

gonna make sure regular zombies spawn

flat grove
#

yeah keep in mind in this case the "mob spawned" will show with any and every spawn, no matter where from

stiff pecan
#

gotcha

#

i had a feeling it was everything outside of the spawner

#

no zombies are spawning on this spawner: (

#

wait

#

HA

#

One did

flat grove
#

:D

stiff pecan
#

i think this is it!

flat grove
#

this was way too complicated than i had hoped for raha

stiff pecan
#

lmfao!! yes definitely for such a small script too haha

#

definitely helpful though! i think this will help a lot of people using eldritch mobs

#

since this is a major issue if you want to use loot and care about spawners

flat grove
#

:o

stiff pecan
#

gonna try the NBT thing now

flat grove
#

and here i thought the pain was over

stiff pecan
#

hahahaha

flat grove
stiff pecan
#

you know what.. nevermind lets end. this is more useful than having lootjs stop the drops

#

id rather the mob not spawn regardless

#

Final script!

EntityEvents.checkSpawn(e => {
    let nbt = e.entity.fullNBT
    if (e.type == 'SPAWNER' && nbt.cardinal_components && nbt.cardinal_components['eldritch_mobs:eldritch_modifiers']?.numMaxAbilities > 0) {
      e.cancel()
    }
  })
#

ty so much lexxie

flat grove
#

<3

#

while we're at it..

flat grove
#

?.[] doesnt work with the current rhino version

pale lance
#

youre definitely never getting that in rhino

#

I can add it in ichor tho

flat grove
#

Yay :3

pale lance
#

I feel like this already works tho

flat grove
#

Well we tried it and it didn't

#

You can see the error there

pale lance
#

I mean in ichor

flat grove
#

Ah

#

Well its not like we can try it

#

Heh

pale lance
flat grove
#

No

#

?.[]

pale lance
#

oh I see

#

you just have both there

#

mm

#

hold up is that even valid JS

flat grove
#

Yes

#

I tested it

pale lance
#

so a.b.c -> a['b'].c -> a.['b'].c still valid?

flat grove
#

I would assume so

#

I tried with the question mark

#

Not without it

#

But i dont see why that wouldn't

pale lance
#

hm

flat grove
#

If you give me 30 mins I'll be able to explain more

#

Going to work now

pale lance
#

nah I understand it

#

just didnt know a.[b] is valid

flat grove
#

We do a little learning

#

First time I use optional chaining like that too

#

But if you think about it, it's the only way to chain that

pale lance
#

yeah I always wondered if array OC is possible

flat grove
#

now im at work and i can type :d

pale lance
#

no you should be working

#

also this is #off-topic material, I hate leaving ichor things in random support threads

#

or #1056980648755208272

flat grove
#

i'll add it there then 😝

#

<#1070619542658756668 message>