Posted September 1, 201411 yr Hey so im adding stats that players can have based on items they are wearing and a class that they choose, and one stat is Agility and I want it to increase movement speed. Now looking at the villager mob I see they have a line called: getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(0.5d); which I think makes them slower, as tests with the player show higher numbers mean moving faster, however putting this into my "setAgility" method just makes the screen seizure as the base value is being set every tick, and my attempts to counter act this fail. So how do I passively increase a players movement speed based on their agility stat, and do so properly? here is my current code snippet in my extended player class: public void setAgility(int value) { this.agility = MathHelper.clamp_int(value + currentClass.getAgi(), -20, 20); if (player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getBaseValue() != 2) { player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).setBaseValue(2); System.out.println("set speed"); } //System.out.println(player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue()); } Now this method is called in the LivingUpdateEvent event so I'm hoping that this effects server and client side, as effects of my other events work when I alter this. Am I just changing the player stat in the wrong place? PS the move speed does work even if the screen is warping in and out I did a test MP and the players zoom around (of course once I fix this the insane test numbers will be handled in a mathHelper.clamp) Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
September 1, 201411 yr I think you need to only set it when it's first equipped and unset it when it's unequipped. If you are using a custom slot, look in the Slot class for clues. Kain
September 1, 201411 yr Author that makes a bit more sense, can probably put something to check "is the collected modifiers == current modifiers, else set modifiers" or something with that logic Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
September 1, 201411 yr Author Ok so doing so makes it do it once, however the speed boost doesn't stay. How can I make it set the players movespeed and be done with it untill the next stat change? Nvm was setting the speed in the wrong place, aka client side. EDIT 2: ok so to have the speed effect applied one has to leave and reload the world, and changing the stat resets it back to default walk speed.. if (props.getAgility() != (agiMod - props.getClassModifers()[1])) { props.setAgility(agiMod); player.getEntityAttribute(SharedMonsterAttributes.movementSpeed) .setBaseValue(MathHelper.clamp_double(SharedMonsterAttributes.movementSpeed.getDefaultValue() + props.getAgility() / 125, 0.45d, 0.7d)); System.out.println(player.getEntityAttribute(SharedMonsterAttributes.movementSpeed).getAttributeValue()); } Do I have to use a command to refresh the player? Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
September 2, 201411 yr Walking speed is defined in net.minecraft.entity.player.PlayerCapabilities and it's pretty useful and is normally saved with the player data. public void writeCapabilitiesToNBT(NBTTagCompound p_75091_1_) { NBTTagCompound nbttagcompound1 = new NBTTagCompound(); nbttagcompound1.setBoolean("invulnerable", this.disableDamage); nbttagcompound1.setBoolean("flying", this.isFlying); nbttagcompound1.setBoolean("mayfly", this.allowFlying); nbttagcompound1.setBoolean("instabuild", this.isCreativeMode); nbttagcompound1.setBoolean("mayBuild", this.allowEdit); nbttagcompound1.setFloat("flySpeed", this.flySpeed); nbttagcompound1.setFloat("walkSpeed", this.walkSpeed); p_75091_1_.setTag("abilities", nbttagcompound1); } public void readCapabilitiesFromNBT(NBTTagCompound p_75095_1_) { if (p_75095_1_.hasKey("abilities", 10)) { NBTTagCompound nbttagcompound1 = p_75095_1_.getCompoundTag("abilities"); this.disableDamage = nbttagcompound1.getBoolean("invulnerable"); this.isFlying = nbttagcompound1.getBoolean("flying"); this.allowFlying = nbttagcompound1.getBoolean("mayfly"); this.isCreativeMode = nbttagcompound1.getBoolean("instabuild"); if (nbttagcompound1.hasKey("flySpeed", 99)) { this.flySpeed = nbttagcompound1.getFloat("flySpeed"); this.walkSpeed = nbttagcompound1.getFloat("walkSpeed"); } if (nbttagcompound1.hasKey("mayBuild", 1)) { this.allowEdit = nbttagcompound1.getBoolean("mayBuild"); } } } You can use PlayerCapabilities#setPlayerWalkSpeed(float speed), but you have to make sure to do it on both sides (for agreement). OnLivingUpdate will set attributes accordingly. These are saved automagicly. -S- (if I helped, please click Thank and applaud) http://6upnqa.dm2301.livefilestore.com/y2mtf-vG7Tqq1TiiVpIm53KWj7294NDPoHfSHHb4PzZiMAUfRCfK0UY0MwOu7Q3zTBNVTKqWjr2-xgBfFRpQT5p-QivtvknPpoABMNUw9br9WuZcBFkjePhnAbW500gVm-P/sequiturian.png[/img]
September 2, 201411 yr Author Wish I could double thank that post. Problem solved thank you very much. Had no idea about playerCapabilities Currently updating my Mod to 1.10.2 https://bitbucket.org/hugo_the_dwarf/riseoftristram2016/src?at=master
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.