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

Ok, so, I understand that new entities have their attributes set by subscribing to EntityAttributeCreationEvent and all, including custom ones. I got that to work no problems.
However, say I have a new Attribute:

public static final DeferredRegister<Attribute> REGISTRY = DeferredRegister.create(ForgeRegistries.Keys.ATTRIBUTES, MhbMod.MODID);
public static final RegistryObject<Attribute> DEFENSE = registerAttr("defense", () -> new RangedAttribute("attribute.mhb.defense", 0, 0, 1024));
private static <T extends Attribute> RegistryObject<T> registerAttr(final String name, final Supplier<T> sup) { 
  	return REGISTRY.register(name, sup); 
}

And I want to add it to an existing entity type, like EntityType.PLAYER. This is what I had in mind:

@SubscribeEvent
public static void createAttributes(EntityAttributeCreationEvent event){
	event.put(EntityType.PLAYER, 
		AttributeSupplier.builder().add(DEFENSE.get(), 3).build()
	);
}

It seemed really clever, but EntityAttributeCreationEvent itself will thrown an error if any individual entity type has more than one AttributeSupplier.Builder mapped. I also considered accessing the Map inside EntityAttributeCreationEvent and replacing the existing player mapping with my own, but not only is that destructive, but the variable is private anyway so that's dead.

Clearly, this is not the right approach. What else could I do then? Should I add the Attribute later on on events like "entity joining the world / spawning" or "entity tick" so that any player entity can be selected?

Edited by NatePlays95
grammar

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.

  • Author

Yep, that's what I'm looking for, thanks a bunch!
I'm a bit worried it didn't work on an already existing world, but for new worlds it works perfectly fine.

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.