Jump to content

Recommended Posts

Posted

Forge Version: 1.19.3 - 44.0.37

Hey, I've made a small mod with a nexus(just a blockentity) that spawns (monster)entitys. They should walk towards the nexus in order to destroy it.

Because there could be multiple nexuses, every spawned monster would need to know which nexus it was spawned by. In order to do that I thought I could just give every monster the nexus's BlockPos in nbt data.

The way I'm trying to do this is:

ModEntityTypes.NEXUS_ZOMBIE.get().spawn(level, (CompoundTag) new CompoundTag().put("NexusPos", NbtUtils.writeBlockPos(getBlockPos())), (Consumer<T>)null, spawnPosition, MobSpawnType.EVENT, false, false);

And then I get the nbt data of the spawned entity by using the command 

/data get entity [ e.g. fef9ec95-4e46-4063-9221-6ff624c9e603]

ingame.

 

But the tag NexusPos is not present there:

Spoiler

entity.variantinvasion.nexus_zombie has the following entity data: {Brain: {memories: {}}, HurtByTimestamp: 0, Attributes: [{Base: 0.1599999964237213d, Name: "minecraft:generic.movement_speed"}, {Base: 0.08d, Name: "forge:entity_gravity"}, {Base: 0.0d, Name: "forge:step_height_addition"}, {Base: 16.0d, Modifiers: [{Amount: -0.001095823442367118d, Operation: 1, UUID: [I; 1904190608, -23050025, -1224481018, -888990816], Name: "Random spawn bonus"}], Name: "minecraft:generic.follow_range"}], Invulnerable: 0b, FallFlying: 0b, PortalCooldown: 0, AbsorptionAmount: 0.0f, FallDistance: 0.0f, CanUpdate: 1b, DeathTime: 0s, HandDropChances: [0.085f, 0.085f], PersistenceRequired: 0b, UUID: [I; -17175403, 1313226851, -1843302410, 617211395], Motion: [0.0d, -0.0784000015258789d, 0.0d], Health: 20.0f, LeftHanded: 0b, Air: 300s, OnGround: 1b, Rotation: [45.0f, 0.0f], HandItems: [{}, {}], ArmorDropChances: [0.085f, 0.085f, 0.085f, 0.085f], Pos: [-575.2077941739268d, 125.0d, -522.7922058260732d], Fire: -1s, ArmorItems: [{}, {}, {}, {}], CanPickUpLoot: 0b, HurtTime: 0s}

I've dug a little into the spawn method which just forwards to EntityType.create. The create method only uses the compound tag to call Mob.finalizeSpawn, which does not use the compound tag.

I have a couple Questions

  • Is using nbt data for what I am trying to accomplish the right tool?
  • Is the compound tag argument ment to give the spawned entity it's nbt data? If not, how would I set the nbt data after or while spawning?
  • Is the way I am reading nbt via the command the correct way?
  • Do I have to manually sync changes to the nbt between the client and server?

If any more code is required to answer the question, just tell me :)

Thanks!

 

Posted

I can't really speak to that CompoundTag. I didn't know it existed until this question. 🙂

From what I can see it is used to pass additional ItemStack NBT for the SpawnEggItem and ArmorStands?

It will be up to the particular Entity implementation how it uses it in its finalizeSpawn() method. Also see the spawn() method that takes an ItemStack.

Nothing in vanilla uses the spawn() method you are using directly.

 

But, it looks like that same method you are using has a Consumer<T> that let's you modify the Entity before it is spawned.

Quote

ModEntityTypes.NEXUS_ZOMBIE.get().spawn(level, (CompoundTag) new CompoundTag().put("NexusPos", NbtUtils.writeBlockPos(getBlockPos())), (Consumer<T>)null, spawnPosition, MobSpawnType.EVENT, false, false);

e.g. something like:

ModEntityTypes.NEXUS_ZOMBIE.get().spawn(level, null, zombie -> zombie.setNexusTarget(getBlockPos()), spawnPosition, MobSpawnType.EVENT, false, false);

 

  • Thanks 1

Boilerplate:

If you don't post your logs/debug.log we can't help you. For curseforge you need to enable the forge debug.log in its minecraft settings. You should also post your crash report if you have one.

If there is no error in the log file and you don't have a crash report then post the launcher_log.txt from the minecraft folder. Again for curseforge this will be in your curseforge/minecraft/Install

Large files should be posted to a file sharing site like https://gist.github.com  You should also read the support forum sticky post.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.