Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

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?

  • Author

getEntityAttribute has nothing to do with NBT.

 

I need both, and both are my problem, that's why I said Attribute/NBT

I'll try it now

 

Do not create new Random instances all the time.

What can I do then?

Edited by NoobMaster4000

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...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.