#Edit entity Nbt

49 messages · Page 1 of 1 (latest)

rose dove
#

Ive been trying to edit the Nbt of an entity and I tried searching on here and couldnt get any of the methods to work. This is my script as of right now.

ForgeEvents.onEvent("net.minecraftforge.event.entity.living.BabyEntitySpawnEvent", event =>{
    try {
        let mob_whitelist = [
            "aether:sheepuff",
            "deep_aether:quail",
            "aether:phyg",
            "aether:moa",
            "aether_redux:shimmercow",
            "aether:flying_cow",
            "aether:aerbunny",
        ] 

        event.parentA.mergeNbt("{Age:24000}")
        event.parentB.mergeNbt("{Age:24000}")
        

        // this part isnt important to the support ticket, and probably isnt staying anyways.
        if (mob_whitelist.indexOf(event.child.type) > -1){

            if (JavaMath.random() > 0.10){

                console.log("A " + event.child.type + " was removed")  
                event.setCanceled(true)
                return
            } 
        }
    } catch(e) {
        console.log(e)
    }
})
latent pagodaBOT
#

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

rose dove
#

Part of my Log aswell

[16:05:19] [INFO] Loaded script startup_scripts:aether_mob_breeding.js in 0.02 s
[16:05:19] [INFO] Loaded 10/10 KubeJS startup scripts in 0.773 s with 0 errors and 0 warnings
[16:12:11] [INFO] aether_mob_breeding.js#29: TypeError: Cannot call method "mergeNbt" of null [dev.latvian.mods.rhino.NativeError]
remote cipher
#

parentA and parentB are private fields

#

getParentA() and getParentB()

#

getChild()

rose dove
#

Ill try that

remote cipher
#

and mergeNbt isn’t a thing

rose dove
#

How else can I edit the nbt?

remote cipher
#

not exactly sure. i’m not a mod/java dev, and i honestly don’t see an obvious way how unless i’m blind

#

it looks to be this, then again i may be wrong

to get nbt (CompoundTag)

let nbt = entity.serializeNBT();
nbt.putInt("Age", 24000)
// to set / merge
entity.read(nbt)
rose dove
#

[16:37:27] [INFO] aether_mob_breeding.js#32: TypeError: Cannot find function read in object Sheepuff['Sheepuff'/450, l='ServerLevel[Aether Gen]', x=3581.65, y=98.00, z=-1948.58]. [dev.latvian.mods.rhino.NativeError]

remote cipher
#

hmm close

#

instead of read, try deserializeNBT

rose dove
#

Doesnt seem to work, no errors.

#

[17:02:52] [INFO] aether_mob_breeding.js#32: InternalError: Can't find method net.minecraftforge.common.extensions.IForgeEntity.deserializeNBT(). (startup_scripts:aether_mob_breeding.js#16) [dev.latvian.mods.rhino.NativeError]
Nevermind there is one

remote cipher
#

that does exist.. what

rose dove
#

I made a mistake there

remote cipher
#

forgot to pass nbt?

rose dove
#

Didnt reload the script after some tinkering

#
ForgeEvents.onEvent("net.minecraftforge.event.entity.living.BabyEntitySpawnEvent", event =>{

    try {

        let mob_whitelist = [
            "aether:sheepuff",
            "deep_aether:quail",
            "aether:phyg",
            "aether:moa",
            "aether_redux:shimmercow",
            "aether:flying_cow",
            "aether:aerbunny",
        ] 

        let nbt = event.getParentA().serializeNBT();
        nbt.putInt("Age", 24000)
        // to set / merge
        event.getParentA().deserializeNBT(nbt)

        if (mob_whitelist.indexOf(event.child.type) > -1){

            if (JavaMath.random() > 0.10){

                console.log("A " + event.child.type + " was removed")  
                event.setCanceled(true)
                return
            } 
        }

    } catch(e) {
        console.log(e)
    }

})```
remote cipher
#

yea idk cause

#

i don’t get why it can’t find that method

#

oooh

#

fabric

#

no you’re on forge

#

but picked fabric tag 🤔

rose dove
remote cipher
#

ok so does that work or?

rose dove
#

No

remote cipher
#

so no errors and not working BigEyes

#

my help is limited right now

rose dove
#

Ill try it on a cow just in case its the aether?

remote cipher
#

and test that nbt just to be sure it’s what we’re looking for console.log(nbt.toString());

rose dove
#

[17:22:46] [INFO] aether_mob_breeding.js#22: {AbsorptionAmount:0.0f,Age:24000,Air:300s,ArmorDropChances:[0.085f,0.085f,0.085f,0.085f],ArmorItems:[{},{},{},{}],Attributes:[{Base:16.0d,Modifiers:[{Amount:0.030584668801492045d,Name:"Random spawn bonus",Operation:1,UUID:[I;1586198164,-1859237441,-2105477128,1630461851]}],Name:"minecraft:generic.follow_range"},{Base:0.0d,Name:"forge:step_height_addition"},{Base:0.20000000298023224d,Name:"minecraft:generic.movement_speed"},{Base:0.08d,Name:"forge:entity_gravity"}],Brain:{memories:{}},CanPickUpLoot:0b,CanUpdate:1b,DeathTime:0s,FallDistance:0.0f,FallFlying:0b,Fire:-1s,ForcedAge:0,ForgeCaps:{"aether:mob_accessory":{DropChances:{aether_gloves:0.085f,aether_pendant:0.085f,hands:0.085f,necklace:0.085f}},"aether_redux:vampire_amulet":{active:0b,has_curio:0b,timer:24000},"curios:inventory":{Curios:[]},"structure_gel:gel_entity":{portal:"structure_gel:empty"}},ForgeData:{},HandDropChances:[0.085f,0.085f],HandItems:[{},{}],Health:10.0f,HurtByTimestamp:0,HurtTime:0s,InLove:536,Invulnerable:0b,LeftHanded:0b,LoveCause:[I;-1294744097,-937014147,-1939919181,160266970],Motion:[0.0d,-0.0784000015258789d,0.0d],OnGround:1b,PersistenceRequired:0b,PortalCooldown:0,Pos:[88.50144967521138d,-60.0d,56.608698659583204d],Rotation:[312.49234f,0.0f],UUID:[I;959226755,1594838250,-1336291690,-1254376322],"forge:spawn_type":"SPAWN_EGG",id:"minecraft:cow"}

#

There is a "ForcedAge" variable

remote cipher
#

ok that’s the nbt, it’s just not being set correctly 🤔

#

i mean Age was set, but is it applying to the entity? maybe after applying, serialize the nbt again and check if it actually set?

#

if nbt doesnt change deserializeNBT isn’t what we’re looking for. but i don’t see any other way. you could also try ForcedAge too

rose dove
#

I set it with /data and I dont see anything happening

remote cipher
#

question, are you meant to set age of parents or child?

#

cause if only the child, you can simply do event.getChild().setAge(24000)

rose dove
#

parents

#

Afaik the child is born with -24000 age, and the parents are given I think 6000 and both count down/up to 0 which when its reached the child grows up and the parents to lose their breeding cooldown.

remote cipher
#

i see

rose dove
#

This was literally a shower thought, what if the value is being changed. But then is being set to the normal amount right after. Ill test it when I have time by changing a different value and see what happens.

#

If thats the case then I might have to use global variables to save the parents info and then have another event edit the parents nbt.