Multiplier helper class

This commit is contained in:
Clisprail
2014-04-12 00:48:37 +02:00
parent 15d10fec4f
commit 307b2cbb4a
@@ -0,0 +1,46 @@
package org.parabot.environment.api.utils;
import java.math.BigInteger;
/**
*
* Helper class for calculating setters for clients that uses multipliers
*
* @author Everel
*
*/
public class Multipliers {
/**
*
* @param multiplier
* the multiplier
* @param set
* the value you want to set
* @return the correct setter value
*/
public static int getIntSetter(int multiplier, int set) {
int bits = 32;
BigInteger quotient = new BigInteger(Integer.toString(multiplier));
BigInteger shift = BigInteger.ONE.shiftLeft(bits);
int value = quotient.modInverse(shift).intValue();
return value * set;
}
/**
*
* @param multiplier
* the multiplier
* @param set
* the value you want to set
* @return the correct setter value
*/
public static long getLongSetter(long multiplier, long set) {
int bits = 64;
BigInteger quotient = new BigInteger(Long.toString(multiplier));
BigInteger shift = BigInteger.ONE.shiftLeft(bits);
long value = quotient.modInverse(shift).longValue();
return value * set;
}
}