private void updateSpeed(EntityPlayer player) {
if(player.worldObj.isRemote || !player.onGround) {
return;
}
IAttributeInstance moveInst = player.getAttributeMap().getAttributeInstance(SharedMonsterAttributes.movementSpeed);
if(moveInst.getModifier(walkModifiers[0].getID()) != null) {
moveInst.removeModifier(walkModifiers[0]); //any will so as they all have the same UID
} else if(moveInst.getModifier(sprintModifiers[0].getID()) != null) {
moveInst.removeModifier(sprintModifiers[0]);
}
ItemStack leggings = player.getEquipmentInSlot(2);
SpeedUpgrade speedUpgrade = SpeedUpgrade.loadFromItem(leggings);
if(leggings != null && leggings.getItem() == EnderIO.itemDarkSteelLeggings && speedUpgrade != null && isSpeedActive(player)) {
double horzMovement = Math.abs(player.distanceWalkedModified - player.prevDistanceWalkedModified);
double costModifier = player.isSprinting() ? Config.darkSteelSprintPowerCost : Config.darkSteelWalkPowerCost;
costModifier = costModifier + (costModifier * speedUpgrade.walkMultiplier);
int cost = (int) (horzMovement * costModifier);
int totalEnergy = getPlayerEnergy(player, EnderIO.itemDarkSteelLeggings);
if(totalEnergy > 0) {
usePlayerEnergy(player, EnderIO.itemDarkSteelLeggings, cost);
if(player.isSprinting()) {
moveInst.applyModifier(sprintModifiers[speedUpgrade.level - 1]);
} else {
moveInst.applyModifier(walkModifiers[speedUpgrade.level - 1]);
}
}
}
}