Posted November 9, 20177 yr 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).
November 11, 20177 yr 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.
November 11, 20177 yr 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.
November 11, 20177 yr Author How should I do that? Do I have to create a specific UUID, or is putting anything fine?
November 12, 20177 yr 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 November 12, 20177 yr by MythicalChromosome
November 12, 20177 yr 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.
November 12, 20177 yr 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.