Jump to content

[1.7.10] Increasing player movement speed


jimmyh

Recommended Posts

I'm looking at ways I can increase the speed at which a player moves.  The trigger for this is based on armour that the player is  wearing.

 

I have 2 questions, where best to apply the increase and the best/preferred way of increasing it.

 

I have found LivingUpdateEvent and onArmorTick to be possible places where I can apply the increase.

 

I've seen a few examples on how to apply the increase, one using attrributes(generic.movementSpeed), which MPS uses and the other being moveFlying, which Botania uses.  Are there any major differences between the 2 methods or are they pretty much both doing the same thing?

 

Any help would be appreciated.

 

Jimmy

Link to comment
Share on other sites

Are you considering using speedPotion effect? That would be like really easy:

player.addPotionEffect(potion effect).

 

If you are looking for hardcoding way, you will need packets.

1.7.10 is no longer supported by forge, you are on your own.

Link to comment
Share on other sites

AttributeModifiers would be the preferred method, in my opinion.

 

Attributes such as player movement speed are automatically synchronized to the client in the background, so you don't need to worry about packets so long as you add/remove the modifier on the server.

 

If you want it based on armor that the player is wearing, you cannot really do it in ItemArmor#onArmorTick because you will be unable to remove the modifier (i.e. onArmorTick is only called if the armor is worn, not when it is taken off).

 

The only way I've found to do this is to store the last armor worn in IExtendedEntityProperties for the player, then each player tick (use PlayerTickEvent), I check if the armor has changed. Whenever it changes, you need to both remove your speed modifier and, if the player is wearing the correct armor, apply it.

Link to comment
Share on other sites

I do it the following way

//when on server I do

                        player.getEntityAttribute(SharedMonsterAttributes.maxHealth).setBaseValue(placeIGetStats.stats.hp);
		player.setHealth(placeIGetStats.stats.currentHp);
		player.getEntityAttribute(SharedMonsterAttributes.attackDamage).setBaseValue(placeIGetStats.stats.currentAtt);
                        PacketOverlord.sendToClient(new PacketUpdatePlayerSharedMonsterAttributes());

//then for movement speed I send a packet and inside my packets process method (which is called client side only I do) the following->

                        player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(whatever);

 

note with movement speed you'll encounter a problem most likely where if the player sprints the movement speed will be reset back to the original even after youve applied the effect. I havent found a way to fix this yet (although havent look that hard at fixing it)

Link to comment
Share on other sites

Hmmm Ok, Im not sure I understand exactly could you provide an example.

I did: vanilla sprinting adds an AttributeModifier to the player's movementSpeed SharedMonsterAttribute, and then removes that same modifier when no longer sprinting.

 

Everything needed to use AttributeModifiers can be seen by looking at the vanilla sprinting code, but in a nutshell:

 

1. You need a UUID for your modifier so you can remove it when necessary; I use http://createguid.com/ to get a UUID string, then UUID.fromString to get the actual UUID and store it in a static final instance.

 

2. You will also want to create a static final instance of your AttributeModifier, even if the internal value will change, simply so you can reference it when removing it.

 

3. When you determine the modifier should be applied:

    a. Get the IAttributeInstance of the appropriate SharedMonsterAttribute for the entity in question

    b. Remove any previous modifier:

if (attribute.getModifier(uuid) != null) {
  attribute.removeModifier(yourAttributeModifierInstance);
}

  c. Then apply the modifier, either the statically referenced one, or a new one with the same UUID

attribute.applyModifier(yourAttributeModifierInstance);

 

You can find information about the final constructor parameter on the Minecraft wiki in the Attributes section; it determines how the 2nd to last parameter (the value) is applied, e.g. simple addition (0), multiplier to the base value (1), etc.

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.



×
×
  • Create New...

Important Information

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