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

For an EntityType<?> I can use getClass(), but the methods available are generic, since it's a wildcard. I would like the specific entity class in order to retrieve attributes and check a few other data. Since methods like getAttribute() aren't directly available, this can (probably?) be accomplished with:

if (MobEntity.class.isAssignableFrom(entityType.getClass())) {
   EntityType<? extends MobEntity> entityType1 = (EntityType<? extends MobEntity>) entityType;

   AttributeModifierMap.MutableAttribute attributeMap = null;
   Method[] methods = entityType1.getClass().getMethods();
   for (Method method : methods) {
      if (method.getReturnType() == AttributeModifierMap.MutableAttribute.class) {
         attributeMap = (AttributeModifierMap.MutableAttribute) method.getDefaultValue();
      }
   }
}

However this seems over-complicated. Alternatively I can cast ? to type T with a helper method, and then would somehow need to instantiate it:

T entity = new T(entityType1, world) {};

But obviously T can't be used in that manner. Am I overthinking this?

Edited by urbanxx001

Grab the data on first call instead of immediately. Then you'll have an instance of the entity to grab everything from. The entity type is used to create a singleton from the entity. If you needed a specific attribute map of a type, then you should grab that from GlobalEntityTypeAttributes and calculate there. What is the use-case for this?

  • Author

Thank you so much, I'll use GlobalEntityTypeAttributes then. The EntityType (a set of them actually) isn't being grabbed from an Entity in the world, but instead from the ForgeRegistry. It's being used for a database. I may still need the actual class, as I need to check if IAngerable is extended by it (to determine if mobs are Neutral or not; isPeacefulCreature only checks if the mob is peaceful or hostile). 

Edited by urbanxx001

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.