Jump to content

Can't change player speed


Plgue

Recommended Posts

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 by Plgue
Link to comment
Share on other sites

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 by Plgue
Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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 by Plgue
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.