#How do I check for a spawned entities NBT containing a specific Key name and value?
1 messages · Page 1 of 1 (latest)
Once your ticket has been resolved, please close it with </ticket close:1054771505520717835> command!
you could try something like event.entity.fullNbt.numMaxAbilities > 0
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())
}
})```
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)
}
})
2 questions;;
-
why drop
var map = Utils.newMap();andnbt.KubeJSPersistentData=map? i'm asking purely for educational purposes -
can I write in
event.cancel()at the end of the IF statement in this event?
- just to not overcomplicate mostly, the merge can take a standard JS object
- 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
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?
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 
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
any ideas?

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
: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
ah should do a check
if (e.type == 'SPAWNER' && nbt["eldritch_mobs:eldritch_modifiers"]?.numMaxAbilities > 0)
i think its like that
alright trying now 😄 i did though have only eldritch mobs spawn if that makes a difference
it should have found it
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
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()
}
})```
😄
theres an extra } 
Oooof
okay reloading lmfao
Okay a regular zombie spawned
damn
and ofc spoke too soon.
eldritch mob zombie spawned
wait
game crashed
i just formatted the nbt
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
if (e.type == 'SPAWNER' && nbt.cardinal_components?["eldritch_mobs:eldritch_modifiers"]?.numMaxAbilities > 0)
nah you have to type the whole path
so [cardinal_components.eldritch_mobs:eldritch_modifiers]?.numMaxAbilities

i hope that works actually, im a bit unsure about the first ?
lmfaoo
fingers crossed its not cursed 😄
should i add { } after if and put the cancel in it
or is it still technically considered nested?
ye thats what i did, but if you only have the cancel its fine without
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
o.o
what you could do...
or i alt+Tabbed at the wrong time and the slaughter block killed it
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()
})
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')
})
ooh nice addition
i tested the JS online so that should work better
Paste version of message.txt from @stiff pecan
thats the latest.log, not server.txt 
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)
Paste version of message.txt from @stiff pecan
yeah its the ?.[]
I see. gonna have to look that up later
my online test worked with it, but rhino doesnt know about it
we should be able to use the ES6 alternate of whatever that is right?
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')
})
cant go wrong with the ol fashioned way
yeah that is fine
ah okay
its called an optional chaining
meaning it goes "forward" with the checks only if the previous one is not null
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
oh my fucking god
gonna make sure regular zombies spawn
yeah keep in mind in this case the "mob spawned" will show with any and every spawn, no matter where from
gotcha
i had a feeling it was everything outside of the spawner
no zombies are spawning on this spawner: (
wait
HA
One did
:D
i think this is it!
this was way too complicated than i had hoped for 
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
:o
gonna try the NBT thing now
hahahaha

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
@pale lance can i pass a rhino/ichor request onto you 
?.[] doesnt work with the current rhino version

Yay :3
I feel like this already works tho
I mean in ichor
also you have that backwards, you mean []?. right?
so a.b.c -> a['b'].c -> a.['b'].c still valid?
I would assume so
I tried with the question mark
Not without it
But i dont see why that wouldn't
hm
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
yeah I always wondered if array OC is possible
now im at work and i can type :d





