Posted August 14, 20178 yr I'm struggling on changing player speed, I've used attributes and capabilities, but neither work.
August 14, 20178 yr Author This is what I have @SubscribeEvent public void onPlayerTick(PlayerTickEvent event) { EntityPlayer p = event.player; if(p.getHeldItem(EnumHand.MAIN_HAND).equals(ModItems.DransFeather)); { //p.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(5.0); p.capabilities.setPlayerWalkSpeed(2); } } The other methods in my events class work, just not this one, I've also tried this without the if statement. Edit: The "p.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(5.0);" is the other thing I tried Edited August 14, 20178 yr by Plgue
August 14, 20178 yr Author 5 minutes ago, diesieben07 said: getHeldItem returns an ItemStack, which will never be equal to an Item. Using the movement speed modifier should work. I'll try, I will update on progress also I posted my outdated code, this is my newer code @SubscribeEvent public void onPlayerTick(PlayerTickEvent event) { EntityPlayer p = event.player; if(p.getHeldItem(EnumHand.MAIN_HAND).equals(new ItemStack(ModItems.DransFeather))); { p.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(5.0); //p.capabilities.setPlayerWalkSpeed(2); } } Edited August 14, 20178 yr by Plgue
August 14, 20178 yr Author 2 minutes ago, diesieben07 said: ItemStack does not override equals, if you want to compare ItemStacks you have to compare their contents manually. But here you just want to check whether the ItemStack contains your Item, so do that. By no means am I trying to disrespect, but that's really not the problem, I've tried on player right click event, without checking what item they were holding, and it still did not work
August 14, 20178 yr Author 1 minute ago, CrowsOfWar said: Stupid question but you're sure the event handler is being called right? Yeah, the other events in the same class are getting called, and it's not a stupid question, as that could have been the problem.
August 14, 20178 yr Author Also would there be a more efficient way of checking if a player is holding an item, without having to check every tick? I feel like having too many "Check every tick" methods would cause lag. Edited August 14, 20178 yr by Plgue
August 15, 20178 yr Override Item#getAttributeModifiers to call the super method, add a movement speed AttributeModifier to the returned Multimap and then return the Multimap. The modifiers in the returned Multimap will automatically be applied to any entity that equips or holds the item. The key of the Multimap is the attribute's name (IAttribute#getName). Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.
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.