Jump to content

[1.7.2] Increase player speed


RedEnergy

Recommended Posts

You can't JUST do that.

 

Base Attribute is a generic value for entity. When you assign it to entity all entities (in this case players) will have this attribute.

If you want to edit whole base for all player instances you can do that, some method with "register" word or something, i don't remeber (idk if it will work because they are being registered in constructor).

 

What you need to use is AttributeModifier, there are 3 operation there, you can make entity go faster, similar to potion effect (that's what potions use).

And this will work per-player.

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

Link to comment
Share on other sites

Also note, that I think the base value is only used once, during entity construction.

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.

Link to comment
Share on other sites

Hello, i need to increase player speed by 2. I tried using entity attributes but it's didn't anything.

Code, which i tried to use:

player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5D);

 

This is of/from coolAlias

 

http://www.minecraftforge.net/forum/index.php?topic=20806.20

 

And how i used it. Just an example :P

 

 

 

package cobaltmod.handler.event;

import java.util.UUID;

import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.attributes.AttributeModifier;
import net.minecraft.entity.ai.attributes.IAttributeInstance;
import net.minecraft.item.ItemStack;
import cobaltmod.main.mod_cobalt;
import cobaltmod.main.api.CMContent;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.PlayerTickEvent;

public class CobaltPlayerTickEventHandler {



private static final UUID cobaltspeedBootsMoveBonusUUID = UUID.fromString("36A0FC05-50EB-460B-8961-615633A6D813");

private static final AttributeModifier cobaltspeedBootsMoveBonus = (new AttributeModifier(cobaltspeedBootsMoveBonusUUID, "Cobalt Speed Boots Speed Bonus", mod_cobalt.forwardspeedboots, 2)).setSaved(false);

@SuppressWarnings("unused")
private boolean bootson = false;

private int i = 0;

@SubscribeEvent
public void onPlayerTick(PlayerTickEvent event) {

	if (event.side.isClient() && event.phase.equals(TickEvent.Phase.START))
	{
		IAttributeInstance movement = event.player.getEntityAttribute(SharedMonsterAttributes.movementSpeed);
		ItemStack[] is = event.player.inventory.armorInventory;
    	
		if (is[0] != null ) {

			if (is[0].getItem() == CMContent.speedcobaltboots ) {

				this.bootson = true;

				if (movement.getModifier(cobaltspeedBootsMoveBonusUUID) != null) {
					movement.removeModifier(cobaltspeedBootsMoveBonus);
				}
				movement.applyModifier(cobaltspeedBootsMoveBonus);

		        double d0 = event.player.worldObj.rand.nextGaussian() * 0.02D;
		        double d1 = event.player.worldObj.rand.nextGaussian() * 0.02D;
		        double d2 = event.player.worldObj.rand.nextGaussian() * 0.02D;
		        
		        double dx = event.player.posX;
		        double dy = event.player.posY - 1.7;
		        double dz = event.player.posZ + 0.2;
		        
		        this.i++;
		        
		        if ( (!(event.player.motionZ == 0.0) || !(event.player.motionZ == 0.0)) && !event.player.isWet() && !event.player.capabilities.isCreativeMode && !event.player.isSneaking() )
		        {
		        	if (this.i >= 3)
		        	{
		        		event.player.worldObj.spawnParticle("cloud", dx, dy, dz, d0, d1, d2);
		        		this.i = 0;
		        	}	        	
		        }
		        else if (event.player.capabilities.isCreativeMode || this.i >= 10)
		        {
		        	this.i = 0;
		        }
			}	
		}
		else
		{
			if (this.bootson = true)
			{
				this.bootson = false;
				movement.removeModifier(cobaltspeedBootsMoveBonus);
			}
		}
	}	
    }
}

 

 

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.