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

I saw a post here detailing how to use getAttributeModifiers on a specific item to modify attack speed, which I found very useful. I just want to know if it's possible to modify it in a similar way without overriding the getAttributeModifiers method of a particular item. What I'm trying to achieve is changing attack speed without the need for a specific item (in my case, I'm trying to modify attack speed when holding no item).

  • Author

I looked at the class, and managed to figure out a lot of what I need. However, there's still one part that leaves me stumped:

AttributeModifier attributemodifier = iattributeinstance.getModifier();

Now getModifier takes a UUID, following the example of other code I've seen I could use the variable ATTACK_SPEED_MODIFIER in there, but trying to put it in there yields nothing. Either that is defined somewhere in the mod's code itself (and I'm just being an idiot) or I'm not referencing it properly. In other words, I'm not sure what UUID I should use in this case, or how to get it.

Create and use your own UUID.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Now I keep getting NullPointerExceptions, the error seems to indicate it has something to do with incorrectly creating the AttributeModifier but I'm not sure.

Here's the relevant code:

static UUID ATTACK_SPEED_MODIFIER = UUID.fromString("b6454cb6-2555-4952-91d4-f20f3ae94eb2");

@SubscribeEvent
	public static void activeHamonEvent(LivingUpdateEvent event){
		if (event.getEntity() instanceof EntityPlayer){
			
			EntityPlayer player = (EntityPlayer) event.getEntity();
			
			final IAttributeInstance iattributeinstance = player.getEntityAttribute(SharedMonsterAttributes.ATTACK_SPEED);

			if (iattributeinstance != null){
	                AttributeModifier attributemodifier = iattributeinstance.getModifier(ATTACK_SPEED_MODIFIER);
	                iattributeinstance.removeModifier(attributemodifier);
	                iattributeinstance.applyModifier(new AttributeModifier(attributemodifier.getID(), attributemodifier.getName(), attributemodifier.getAmount()*2, attributemodifier.getOperation()));
	            }
			else{
	                AttributeModifier attributemodifier = iattributeinstance.getModifier(ATTACK_SPEED_MODIFIER);
	                iattributeinstance.removeModifier(attributemodifier);
	                iattributeinstance.applyModifier(new AttributeModifier(attributemodifier.getID(), attributemodifier.getName(), 1, attributemodifier.getOperation()));
	            }
		}
	}

I'm sure it's something simple that I overlooked and that I'm going to kick myself for missing it, but I can't figure out what exactly it is I'm missing.

Edited by MythicalChromosome

2 hours ago, MythicalChromosome said:

if (iattributeinstance != null){
    //blah blah blah, not important
} else{
    AttributeModifier attributemodifier = iattributeinstance.getModifier(ATTACK_SPEED_MODIFIER);

 

If the iattributeinstance is null, then get the modifier from the iattributeinstance...

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

  • Author

Ah yeah, that statement was supposed to be nested inside another if-statement but it seems I screwed up the formatting there.

 

Still, the IAttributeInstance keeps crashing the game because it's null, and I can't figure out what to put in the else block to handle that...

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.