Jump to content

1.12.x Help setting entity attribute/NBT


NoobMaster4000

Recommended Posts

Hello, I have a little API mod (Or a library, core or how you want to call it) that has methods used to spawn items/mobs/etc but I have problems setting attributes/NBT to an entity.

This is how I spawn an entity without armor

public static void SpawnEntityNoArmor(World worldIn, int x, int y, int z, Class<? extends Entity> entity,
			int amount, Boolean hasCustomName, @Nullable String name, Boolean hasMessage, @Nullable EntityPlayer player,
			@Nullable String message, Boolean hasCustomHealth, @Nullable Integer health) {
		for (int b = 0; b < amount; b++) {
			Entity en = EntityList.newEntity(entity, worldIn);
			en.setPositionAndUpdate(x, y, z);
			if (hasCustomName) {
				en.setCustomNameTag(Messages.color(name));
			}
			if (hasCustomHealth) {
			}
			worldIn.spawnEntity(en);
		}
		if (hasMessage) {
			Messages.sendMessage(player, message);
		}
	}

I use

Entity en = EntityList.newEntity(entity, worldIn);

because is the only method I've found on the internet that let me spawn an entity using EntityName.class

I don't know how to add to this entity an attribute/NBT because en.getEntityAttribute doesn't exists

Calling the method with:

EntityHelper.SpawnEntityNoArmor(worldIn, x + new Random().nextInt(12) - 6, y,
						z + new Random().nextInt(12) - 6, EntitySheep.class, new Random().nextInt(8) + 1, true, "jeb_",
						true, player, "I'm a sheep");

If you want to know what "EntityHelper" class contain is just this method above (the first one) plus some other useless methods for this question

 

How can I set an entity Attribute using my entity spawn method or using a different method that let me dynamically choose an entity?

Link to comment
Share on other sites

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.