mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-06 16:50:39 +00:00
Multiplier helper class
This commit is contained in:
@@ -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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user